digdir / dialogporten

Dialogporten - common API and and metadata state store for digital dialogs
https://docs.altinn.studio/dialogporten
MIT License
1 stars 3 forks source link

Enhancement: Update Slack message on release modification #1208

Open coderabbitai[bot] opened 1 week ago

coderabbitai[bot] commented 1 week ago

As discussed in PR #1185 comment, @arealmaas suggested implementing a mechanism to update the Slack message when the release is modified or when there are new commits to the same PR. This involves storing the Slack message data and utilizing it to update the message accordingly.

Please refer to the conversation and code snippets in the PR for more details.

arealmaas commented 1 week ago

Possible suggestion:

// ... existing code ...

  send-slack-message:
    name: Send Slack message
    needs: [dry-run-deploy-infra-staging, dry-run-deploy-apps-staging, get-current-version, generate-git-short-sha]
    runs-on: ubuntu-latest
    steps:
      - name: Generate release identifier
        id: release-id
        run: echo "release_id=release-${{ github.event.pull_request.number }}-${{ needs.get-current-version.outputs.version }}" >> $GITHUB_OUTPUT

      - name: Slackify markdown in pull request body
        id: slackify
        uses: LoveToKnow/slackify-markdown-action@v1.1.1
        with:
          text: ${{ github.event.pull_request.body }}

      - name: Send or update Slack message
        id: slack
        env:
          SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
        uses: slackapi/slack-github-action@v1.27.0
        with:
          channel-id: ${{ secrets.SLACK_CHANNEL_ID_FOR_RELEASES }}
          update-ts: ${{ secrets.SLACK_MESSAGE_TS }}
          payload: |
            {
                "blocks": [
                  {
                    "type": "section",
                    "text": {
                      "type": "mrkdwn",
                      "text": "*Release ${{ needs.get-current-version.outputs.version }}*\n${{ toJson(steps.slackify.outputs.text) }}"
                    }
                  },
                  { "type": "divider" },
                  {
                    "type": "actions",
                    "elements": [
                      {
                        "type": "button",
                        "text": {
                          "type": "plain_text",
                          "text": "Approve Release"
                        },
                        "url": "https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}"
                      }
                    ]
                  }
                ],
                "metadata": {
                  "event_type": "release_update",
                  "event_payload": {
                    "release_id": "${{ steps.release-id.outputs.release_id }}"
                  }
                }
            }

      - name: Store message timestamp
        if: steps.slack.outputs.message_ts != ''
        run: |
          echo "${{ steps.release-id.outputs.release_id }}=${{ steps.slack.outputs.message_ts }}" >> $GITHUB_ENV

      - name: Update GitHub Actions secret
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          gh secret set SLACK_MESSAGE_TS --body "${{ env.SLACK_MESSAGE_TS }}"

// ... existing code ...