diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..928e267 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @rise8-us/cato-repo-pr-approvers diff --git a/.github/actions/post-to-slack/action.yml b/.github/actions/post-to-slack/action.yml new file mode 100644 index 0000000..79eaf86 --- /dev/null +++ b/.github/actions/post-to-slack/action.yml @@ -0,0 +1,75 @@ +name: Send Slack message +description: Sends a Slack message + +inputs: + channel-id: + description: 'Slack channel ID' + required: true + type: string + message: + description: 'The message to send' + required: true + type: string + slack-bot-token: + description: 'The token of the Slack bot' + required: true + thread_ts: + description: 'The threaded timestamp on the message that was posted' + required: false + type: string +outputs: + thread_ts: + description: 'The threaded timestamp on the message that was posted' + value: ${{ steps.send-message.outputs.thread_ts }} + +runs: + using: composite + steps: + - name: Send message + id: send-message + if: inputs.thread_ts == '' + uses: slackapi/slack-github-action@v1 + with: + channel-id: ${{ inputs.channel-id }} + payload: | + { + "text": "Slack Message", + "unfurl_links": false, + "unfurl_media": false, + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "${{ inputs.message }}" + } + } + ] + } + env: + SLACK_BOT_TOKEN: ${{ inputs.slack-bot-token }} + + - name: Send message in existing thread + id: update-thread + if: inputs.thread_ts != '' + uses: slackapi/slack-github-action@v1 + with: + channel-id: ${{ inputs.channel-id }} + payload: | + { + "text": "Slack Message", + "unfurl_links": false, + "unfurl_media": false, + "thread_ts": "${{ inputs.thread_ts }}", + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "${{ inputs.message }}" + } + } + ] + } + env: + SLACK_BOT_TOKEN: ${{ inputs.slack-bot-token }} diff --git a/.github/workflows/notify-pr-status.yml b/.github/workflows/notify-pr-status.yml new file mode 100644 index 0000000..aa01185 --- /dev/null +++ b/.github/workflows/notify-pr-status.yml @@ -0,0 +1,84 @@ +name: Notify PR Status + +on: + pull_request: + types: [opened, closed] + branches: + - main + pull_request_review: + types: [submitted] + +env: + ACTOR: ${{ github.actor }} + PR_NAME: ${{ github.event.pull_request.title }} + PR_BRANCH_NAME: ${{ github.event.pull_request.head.ref }} + PR_URL: ${{ github.event.pull_request.html_url }} + PR_AUTHOR: ${{ github.event.pull_request.user.login }} + PR_AUTHOR_URL: ${{ github.event.pull_request.user.html_url }} + PR_APPROVER: ${{ github.event.review.user.login }} + REPO: ${{ github.repository }} + REPO_URL: ${{ github.event.repository.html_url }} + +jobs: + notify-opened: + runs-on: ubuntu-latest + if: github.event_name == 'pull_request' && github.event.action == 'opened' + steps: + - uses: actions/checkout@v4 + + - name: Generate message + id: generate-message + run: | + bash templates/slack-notify-pr-opened.tpl + cat slack_message | awk '{printf "%s\\n", $0}' > slack_message.stripped + BODY=$(cat slack_message.stripped) + echo "payload=$BODY" >> $GITHUB_OUTPUT + + - name: Post to Slack + uses: rise8-us/cato-playbook/.github/actions/post-to-slack@main + with: + channel-id: ${{ vars.SLACK_CHANNEL_ID }} + message: ${{ steps.generate-message.outputs.payload }} + slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }} + + notify-approved: + runs-on: ubuntu-latest + if: github.event_name == 'pull_request_review' && github.event.review.state == 'approved' + steps: + - uses: actions/checkout@v4 + + - name: Generate message + id: generate-message + run: | + bash templates/slack-notify-pr-approved.tpl + cat slack_message | awk '{printf "%s\\n", $0}' > slack_message.stripped + BODY=$(cat slack_message.stripped) + echo "payload=$BODY" >> $GITHUB_OUTPUT + + - name: Post to Slack + uses: rise8-us/cato-playbook/.github/actions/post-to-slack@main + with: + channel-id: ${{ vars.SLACK_CHANNEL_ID }} + message: ${{ steps.generate-message.outputs.payload }} + slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }} + + notify-closed: + runs-on: ubuntu-latest + if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged + steps: + - uses: actions/checkout@v4 + + - name: Generate message + id: generate-message + run: | + bash templates/slack-notify-pr-closed.tpl + cat slack_message | awk '{printf "%s\\n", $0}' > slack_message.stripped + BODY=$(cat slack_message.stripped) + echo "payload=$BODY" >> $GITHUB_OUTPUT + + - name: Post to Slack + uses: rise8-us/cato-playbook/.github/actions/post-to-slack@main + with: + channel-id: ${{ vars.SLACK_CHANNEL_ID }} + message: ${{ steps.generate-message.outputs.payload }} + slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }} diff --git a/docs/images/SecRel.png b/docs/images/SecRel.png deleted file mode 100644 index e64703c..0000000 Binary files a/docs/images/SecRel.png and /dev/null differ diff --git a/docs/images/secrel.png b/docs/images/secrel.png index 42aeb6b..e64703c 100644 Binary files a/docs/images/secrel.png and b/docs/images/secrel.png differ diff --git a/pull_request_template.md b/pull_request_template.md new file mode 100644 index 0000000..718a1fa --- /dev/null +++ b/pull_request_template.md @@ -0,0 +1,13 @@ +# Description + +Please include a summary of the changes being made, and include relevant motivation and context. +List any dependencies that are required for this change. + +## Type of change + +Please remove any options that are not relevant. + +- [ ] Documentation update 📚 (additions/changes to the playbook docs, spelling mistakes, grammar corrections) +- [ ] Bug fix 🐛 (non-breaking change which fixes an issue) +- [ ] New feature 🎉 (non-breaking change which adds functionality) +- [ ] Breaking change 💔 (fix or feature that would cause existing functionality to not work as expected) diff --git a/templates/slack-notify-pr-approved.tpl b/templates/slack-notify-pr-approved.tpl new file mode 100644 index 0000000..3aeab6a --- /dev/null +++ b/templates/slack-notify-pr-approved.tpl @@ -0,0 +1,7 @@ +#!/bin/bash + +cat << EOF > slack_message +:github-check: A pull request has been *approved* by $ACTOR in the <$REPO_URL|$REPO> repository, and is *pending merge*. + +Merge it here: <$PR_URL|$PR_NAME> +EOF diff --git a/templates/slack-notify-pr-closed.tpl b/templates/slack-notify-pr-closed.tpl new file mode 100644 index 0000000..83eea8e --- /dev/null +++ b/templates/slack-notify-pr-closed.tpl @@ -0,0 +1,7 @@ +#!/bin/bash + +cat << EOF > slack_message +:github-merged: A pull request has been *merged* into main by $ACTOR in the <$REPO_URL|$REPO> repository :rocket: + +This closes the pull request <$PR_URL|$PR_NAME>, and the merged branch '$PR_BRANCH_NAME' has been automatically removed +EOF diff --git a/templates/slack-notify-pr-opened.tpl b/templates/slack-notify-pr-opened.tpl new file mode 100644 index 0000000..ff808f8 --- /dev/null +++ b/templates/slack-notify-pr-opened.tpl @@ -0,0 +1,7 @@ +#!/bin/bash + +cat << EOF > slack_message +:exclamation: A new pull request has been *opened* by $PR_AUTHOR in the <$REPO_URL|$REPO> repository, and is *pending approval*. + +Anyone in @cato-repo-pr-approvers can review it here: <$PR_URL|$PR_NAME> +EOF