-
Notifications
You must be signed in to change notification settings - Fork 18
Add actions for notifying of pending prs, closing stale prs and switch user for auto-backports #505
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| active: ["main", "release/v2.3.x"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| name: 'Notify of Pending PRs' | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '30 1 * * *' | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| stale: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Generate Pending PRs list | ||
| id: generate-prs | ||
| run: | | ||
| ./.github/workflows/scripts/pending-prs slack redpanda-data/redpanda-operator > payload.json | ||
| echo "has-prs=$(cat payload.json | wc -l)" >> $GITHUB_OUTPUT | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| - name: Post message to Slack channel | ||
| uses: slackapi/slack-github-action@v2.0.0 | ||
| if: steps.generate-prs.outputs.has-prs != '0' | ||
| with: | ||
| webhook: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll need to ask for one of these from infra folks to send this notification to our channel. |
||
| webhook-type: webhook-trigger | ||
| payload-file-path: "./payload.json" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| export BROWSER=echo | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a nasty hack to capture the url for filtering out the PRs that we're actually querying so that they can be printed out in our payloads. |
||
| current_directory=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) | ||
|
|
||
| format="$1" | ||
| repo="$2" | ||
| branches_file="$current_directory/../../branches.yml" | ||
|
|
||
| readarray activeBranches < <(yq e -o=j -I=0 '.active[]' "$branches_file") | ||
|
|
||
| get_url() { | ||
| local repo=$1 | ||
| local branch=$2 | ||
| gh search prs --repo=$repo --state=open --base $branch -w | awk '{print substr($0, 1, length($0)-12)}' 2> /dev/null | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw, the nasty hack with See the difference in the broken output v. fixed |
||
| } | ||
|
|
||
| terminal_bold() { | ||
| local text=$1 | ||
| echo "\033[1m$text\033[22m" | ||
| } | ||
|
|
||
| markdown_bold() { | ||
| local text=$1 | ||
| echo "*$text*" | ||
| } | ||
|
|
||
| terminal_url() { | ||
| local url=$1 | ||
| local text=$2 | ||
| echo "\033]8;;$url\033\\\\$text\033]8;;\033\\\\" | ||
| } | ||
|
|
||
| markdown_url() { | ||
| local url=$1 | ||
| local text=$2 | ||
| echo "<$url|$text>" | ||
| } | ||
|
|
||
| format_header() { | ||
| local branch=$1 | ||
| local url=$2 | ||
| local format=$3 | ||
| case $format in | ||
| terminal) | ||
| text=$(echo "PRs open for $(terminal_url $url $branch):") | ||
| echo "$(terminal_bold "$text")" | ||
| ;; | ||
| *) | ||
| text=$(echo "PRs open for $(markdown_url $url $branch):") | ||
| echo "$(markdown_bold "$text")" | ||
| ;; | ||
| esac | ||
| } | ||
|
|
||
| get_and_format_prs() { | ||
| local repo=$1 | ||
| local branch=$2 | ||
| local format=$3 | ||
| case $format in | ||
| terminal) | ||
| gh search prs --repo=$repo --state=open --json url,number,title,updatedAt --template '{{range .}}{{(printf "- %s | Last Updated: %s\\n" (hyperlink .url (printf "#%v: %q" .number .title)) (timeago .updatedAt))}}{{end}}' --base $branch | cat | ||
| ;; | ||
| *) | ||
| gh search prs --repo=$repo --state=open --json url,number,title,updatedAt --template '{{range .}}{{(printf "• <%s|#%v>: %q | *Last Updated: %s*\\n" .url .number .title (timeago .updatedAt))}}{{end}}' --base $branch | cat | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
| ;; | ||
| esac | ||
| } | ||
|
|
||
| echo_terminal() { | ||
| local text=$1 | ||
| echo -e "$text" | ||
| } | ||
|
|
||
| echo_json() { | ||
| local text=$1 | ||
| echo "$text" | jq -Rc '{type: "mrkdwn", text: .}' | awk '{gsub(/\\\\n/, "\\n"); print}' | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some |
||
| } | ||
|
|
||
| message="" | ||
| for activeBranch in "${activeBranches[@]}"; do | ||
| branch=$(echo "$activeBranch" | yq -r) | ||
| url=$(get_url "$repo" "$branch") | ||
| header="$(format_header "$branch" "$url" "$format")" | ||
| prs="$(get_and_format_prs "$repo" "$branch" "$format")" | ||
| if [ -n "$prs" ]; then | ||
| message+="$header\n$prs\n" | ||
| fi | ||
| done | ||
|
|
||
| if [ -n "$message" ]; then | ||
| # chomp off the last two newlines | ||
| message="${message::-4}" | ||
|
|
||
| case $format in | ||
| terminal|testing) | ||
| echo_terminal "$message" | ||
| ;; | ||
| *) | ||
| echo_json "$message" | ||
| ;; | ||
| esac | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| name: 'Close stale PRs' | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '30 1 * * *' | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| stale: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/stale@v9 | ||
| with: | ||
| stale-pr-message: 'This PR is stale because it has been open 5 days with no activity. Remove stale label or comment or this will be closed in 5 days.' | ||
| close-pr-message: 'This PR was closed because it has been stalled for 5 days with no activity.' | ||
| days-before-issue-stale: -1 | ||
| days-before-issue-close: -1 | ||
| stale-pr-label: stale | ||
| days-before-pr-stale: 5 | ||
| days-before-pr-close: 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is basically a "did we actually have anything to post?" check. The
wc -lwill return0if there's nothing open or1if we have a payload to post.