Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Pull Request #28

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/actions/post-to-slack/action.yml
Original file line number Diff line number Diff line change
@@ -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 }}
84 changes: 84 additions & 0 deletions .github/workflows/notify-pr-opened.yml
Original file line number Diff line number Diff line change
@@ -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@notifications
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@notifications
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@notifications
with:
channel-id: ${{ vars.SLACK_CHANNEL_ID }}
message: ${{ steps.generate-message.outputs.payload }}
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
Binary file removed docs/images/SecRel.png
Binary file not shown.
Binary file modified docs/images/secrel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions pull_request_template.md
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions templates/slack-notify-pr-approved.tpl
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions templates/slack-notify-pr-closed.tpl
Original file line number Diff line number Diff line change
@@ -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:

The merged branch "$PR_BRANCH_NAME" has been automatically removed
EOF
7 changes: 7 additions & 0 deletions templates/slack-notify-pr-opened.tpl
Original file line number Diff line number Diff line change
@@ -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*.

Approvers may review it here: <$PR_URL|$PR_NAME>
EOF