From 0d73070041c1f8c8b348f6814f134a18cf4293e6 Mon Sep 17 00:00:00 2001 From: Nikita Belonogov Date: Mon, 18 Dec 2023 22:51:45 +0400 Subject: [PATCH] ci: PLATE-775: ChatOps: Instant Workflow Run link + reaction token (#284) --- .github/workflows/git-command.yml | 33 +++++++++++--------- .github/workflows/jira-command.yml | 12 +++++-- .github/workflows/slash-command-dispatch.yml | 2 ++ 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/.github/workflows/git-command.yml b/.github/workflows/git-command.yml index b9185c83..b9cc7d98 100644 --- a/.github/workflows/git-command.yml +++ b/.github/workflows/git-command.yml @@ -13,10 +13,16 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 3 steps: - - name: Dump the client payload context - env: - PAYLOAD_CONTEXT: ${{ toJson(github.event.client_payload) }} - run: echo "$PAYLOAD_CONTEXT" + - uses: hmarr/debug-action@v2.1.0 + + - name: Add Workflow link to command comment + uses: peter-evans/create-or-update-comment@v3 + with: + token: ${{ secrets.GIT_PAT }} + repository: ${{ github.event.client_payload.github.payload.repository.full_name }} + comment-id: ${{ github.event.client_payload.github.payload.comment.id }} + body: | + > [Workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) - name: Checkout on chat command uses: actions/checkout@v4 @@ -27,6 +33,13 @@ jobs: submodules: 'recursive' fetch-depth: 0 + - name: Configure git + shell: bash + run: | + set -xeuo pipefail + git config --global user.name '${{ github.event.client_payload.github.actor }}' + git config --global user.email '${{ github.event.client_payload.github.actor }}@users.noreply.github.com' + - name: Check for merge conflict id: check-conflict env: @@ -34,8 +47,6 @@ jobs: shell: bash run: | set -xeuo pipefail - git config --global user.name '${{ github.event.client_payload.github.actor }}' - git config --global user.email '${{ github.event.client_payload.github.actor }}@users.noreply.github.com' echo "merge_conflict=$(git merge-tree $(git merge-base HEAD origin/$SLASH_COMMAND_ARG_BRANCH) origin/$SLASH_COMMAND_ARG_BRANCH HEAD | grep '<<')" >> $GITHUB_OUTPUT - name: Add reaction to command comment on merge conflict @@ -46,9 +57,7 @@ jobs: repository: ${{ github.event.client_payload.github.payload.repository.full_name }} comment-id: ${{ github.event.client_payload.github.payload.comment.id }} body: | - > **Error**: Merge conflict detected, please resolve it using the git command line. - > - > [Workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) + > **Error**: Merge conflict detected, please resolve it using the command line. reactions: "-1" - name: Merge branch into current branch @@ -79,8 +88,6 @@ jobs: comment-id: ${{ github.event.client_payload.github.payload.comment.id }} body: | > Already up-to-date. Nothing to commit. - > - > [Workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) reactions: "confused" - name: Add reaction to command comment on success @@ -93,8 +100,6 @@ jobs: body: | > Successfully pushed new changes: > ${{ steps.commit_and_push.outputs.last_commit_msg }} (${{ steps.commit_and_push.outputs.last_commit_sha }}) - > - > [Workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) reactions: "+1" - name: Add reaction to command comment on failure @@ -106,8 +111,6 @@ jobs: comment-id: ${{ github.event.client_payload.github.payload.comment.id }} body: | > **Error**: failed to execute "${{ github.event.client_payload.slash_command.args.unnamed.arg1 }}" command - > - > [Workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) reactions: "-1" help: diff --git a/.github/workflows/jira-command.yml b/.github/workflows/jira-command.yml index 76ad92ca..4ef05b3d 100644 --- a/.github/workflows/jira-command.yml +++ b/.github/workflows/jira-command.yml @@ -15,6 +15,15 @@ jobs: steps: - uses: hmarr/debug-action@v2.1.0 + - name: Add Workflow link to command comment + uses: peter-evans/create-or-update-comment@v3 + with: + token: ${{ secrets.GIT_PAT }} + repository: ${{ github.event.client_payload.github.payload.repository.full_name }} + comment-id: ${{ github.event.client_payload.github.payload.comment.id }} + body: | + > [Workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) + - name: Check user's membership uses: actions/github-script@v7 id: check-membership @@ -62,8 +71,6 @@ jobs: comment-id: ${{ github.event.client_payload.github.payload.comment.id }} body: | > Jira issue [${{ steps.jira-create-issue.outputs.key }}](${{ steps.jira-create-issue.outputs.link }}) is created - > - > [Workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) reactions: "+1" - name: Add reaction to command comment on failure @@ -76,7 +83,6 @@ jobs: body: | > **Error**: failed to execute "${{ github.event.client_payload.slash_command.args.unnamed.arg1 }}" command > ${{ steps.check-membership.outputs.error }} - > [Workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) reactions: "-1" help: diff --git a/.github/workflows/slash-command-dispatch.yml b/.github/workflows/slash-command-dispatch.yml index b723a6fe..eba62df2 100644 --- a/.github/workflows/slash-command-dispatch.yml +++ b/.github/workflows/slash-command-dispatch.yml @@ -54,6 +54,7 @@ jobs: uses: peter-evans/slash-command-dispatch@v3 with: token: ${{ secrets.GIT_PAT }} + reaction-token: ${{ secrets.GIT_PAT }} issue-type: "issue" reactions: true commands: ${{ env.issue_commands_list }} @@ -64,6 +65,7 @@ jobs: uses: peter-evans/slash-command-dispatch@v3 with: token: ${{ secrets.GIT_PAT }} + reaction-token: ${{ secrets.GIT_PAT }} issue-type: "pull-request" reactions: true commands: ${{ env.commands_list }}