diff --git a/.github/workflows/gh_pr_checks_approval.yml b/.github/workflows/gh_pr_checks_approval.yml index d8aed34e2ba..bc1bbd494b4 100644 --- a/.github/workflows/gh_pr_checks_approval.yml +++ b/.github/workflows/gh_pr_checks_approval.yml @@ -7,10 +7,6 @@ on: - main env: - greetings_message: | - 👋 Thanks for your contributing! - - Our collaborators will review your pull request after all status checks have been passed. safety_changes_message: | After a quick scan, I have approved%sworkflow%s to run. risky_changes_message: | @@ -21,26 +17,8 @@ env: jobs: pull_request_checks_approval: if: github.repository == 'Tencent/Hippy' - permissions: - actions: write - pull-requests: write runs-on: ubuntu-latest steps: - - name: Greetings - if: github.event.action == 'opened' - uses: actions/github-script@v6.3.3 - with: - script: | - const { owner, repo } = context.repo; - const { pull_request } = context.payload; - const { issues } = github.rest; - - await issues.createComment({ - owner, - repo, - issue_number: pull_request.number, - body: process.env['greetings_message'], - }); - name: Token uses: navikt/github-app-token-generator@v1 id: get-token diff --git a/.github/workflows/gh_pr_guide.yml b/.github/workflows/gh_pr_guide.yml new file mode 100644 index 00000000000..d31aa3014f2 --- /dev/null +++ b/.github/workflows/gh_pr_guide.yml @@ -0,0 +1,105 @@ +name: '[gh] pull request guide' + +on: + pull_request_target: + branches: + - master + - main + - v3.0-dev + - v3.0 + types: + - opened + issue_comment: + types: + - created + +jobs: + pull_request_greetings: + if: github.event.action == 'opened' && github.repository == 'Tencent/Hippy' + runs-on: ubuntu-latest + env: + MESSAGE: | + Hi, @${{ github.event.sender.login }}, Thanks for your PR! :clap: + + :label: You can leave a comment in this PR with **`#help`** tag when you need help (e.g. a status checks run failed due to internal issue), admin team members will help asap. + steps: + - name: Token + uses: navikt/github-app-token-generator@v1 + id: get-token + with: + private-key: ${{ secrets.PRIVATE_KEY }} + app-id: ${{ secrets.APP_ID }} + - name: Greetings + uses: actions/github-script@v6.1.0 + with: + github-token: ${{ steps.get-token.outputs.token }} + script: | + const { owner, repo } = context.repo; + const { pull_request } = context.payload; + const { issues } = github.rest; + + await issues.createComment({ + owner, + repo, + issue_number: pull_request.number, + body: process.env.MESSAGE, + }); + + pull_request_help_needed: + if: github.event.sender.type == 'User' && github.event.issue.pull_request && contains(github.event.comment.body, '#help') && github.repository == 'Tencent/Hippy' + runs-on: ubuntu-latest + env: + MESSAGE: | + [${{ github.event.sender.login }}](https://github.com/${{ github.event.sender.login }}) needs help on [#${{ github.event.issue.number }}](${{ github.event.comment.html_url }}) pull request. + > [${{ github.event.comment.html_url }}](${{ github.event.comment.html_url }}) + > ${{ github.event.comment.body }} + steps: + - name: Token + uses: navikt/github-app-token-generator@v1 + id: get-token + with: + private-key: ${{ secrets.PRIVATE_KEY }} + app-id: ${{ secrets.APP_ID }} + - name: Action + uses: actions/github-script@v6.3.3 + with: + github-token: ${{ steps.get-token.outputs.token }} + script: | + const { owner, repo } = context.repo; + const { issue } = context.payload; + const { issues } = github.rest; + + const p = []; + + p.push(issues.addLabels({ + issue_number: issue.number, + labels: [ 'needs: help' ], + ...context.repo, + })); + + p.push(github.request("POST ${{ secrets.WECHAT_WORK_BOT_WEBHOOK }}", { + headers: { + "content-type": "application/json" + }, + data: { + chatid: "${{ secrets.WECHAT_WORK_ADMIN_CHAT_ID }}", + msgtype: "markdown", + markdown: { + content: process.env.MESSAGE, + attachments: [{ + callback_id: "help_needed", + actions: [{ + name: "help_needed_btn", + text: "Mark as Resolved", + type: "button", + value: "Mark as Resolved", + replace_text: "Already resolved", + border_color: "2c974b", + text_color: "2c974b" + }] + }] + } + } + })); + + await Promise.all(p);