Skip to content

Commit 98f4ce6

Browse files
authored
Add actions for notifying of pending prs, closing stale prs and switch user for auto-backports (#505)
1 parent ce11270 commit 98f4ce6

File tree

8 files changed

+161
-3
lines changed

8 files changed

+161
-3
lines changed

.github/branches.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
active: ["main", "release/v2.3.x"]

.github/labels.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ labels:
33
color: "ededed"
44
"no-changelog":
55
color: "8f1402"
6+
"stale":
7+
color: "8f1402"
68
"v2.3.9":
7-
color: "ededed"
9+
color: "ededed"

.github/workflows/backport.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ jobs:
1313
- name: Backport Action
1414
uses: sorenlouv/[email protected]
1515
with:
16-
# TODO: exchange this token with a PAT of a user like our build bot
17-
github_token: ${{ secrets.GITHUB_TOKEN }}
16+
github_token: ${{ secrets.ACTIONS_BOT_TOKEN }}
1817

1918
- name: Info log
2019
if: ${{ success() }}

.github/workflows/pending-prs.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: 'Notify of Pending PRs'
2+
3+
on:
4+
schedule:
5+
- cron: '30 1 * * *'
6+
workflow_dispatch:
7+
8+
jobs:
9+
stale:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Generate Pending PRs list
14+
id: generate-prs
15+
run: |
16+
./.github/workflows/scripts/pending-prs slack redpanda-data/redpanda-operator > payload.json
17+
echo "has-prs=$(cat payload.json | wc -l)" >> $GITHUB_OUTPUT
18+
env:
19+
GH_TOKEN: ${{ github.token }}
20+
- name: Post message to Slack channel
21+
uses: slackapi/[email protected]
22+
if: steps.generate-prs.outputs.has-prs != '0'
23+
with:
24+
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
25+
webhook-type: webhook-trigger
26+
payload-file-path: "./payload.json"
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/usr/bin/env bash
2+
3+
export BROWSER=echo
4+
current_directory=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
5+
6+
format="$1"
7+
repo="$2"
8+
branches_file="$current_directory/../../branches.yml"
9+
10+
readarray activeBranches < <(yq e -o=j -I=0 '.active[]' "$branches_file")
11+
12+
get_url() {
13+
local repo=$1
14+
local branch=$2
15+
gh search prs --repo=$repo --state=open --base $branch -w | awk '{print substr($0, 1, length($0)-12)}' 2> /dev/null
16+
}
17+
18+
terminal_bold() {
19+
local text=$1
20+
echo "\033[1m$text\033[22m"
21+
}
22+
23+
markdown_bold() {
24+
local text=$1
25+
echo "*$text*"
26+
}
27+
28+
terminal_url() {
29+
local url=$1
30+
local text=$2
31+
echo "\033]8;;$url\033\\\\$text\033]8;;\033\\\\"
32+
}
33+
34+
markdown_url() {
35+
local url=$1
36+
local text=$2
37+
echo "<$url|$text>"
38+
}
39+
40+
format_header() {
41+
local branch=$1
42+
local url=$2
43+
local format=$3
44+
case $format in
45+
terminal)
46+
text=$(echo "PRs open for $(terminal_url $url $branch):")
47+
echo "$(terminal_bold "$text")"
48+
;;
49+
*)
50+
text=$(echo "PRs open for $(markdown_url $url $branch):")
51+
echo "$(markdown_bold "$text")"
52+
;;
53+
esac
54+
}
55+
56+
get_and_format_prs() {
57+
local repo=$1
58+
local branch=$2
59+
local format=$3
60+
case $format in
61+
terminal)
62+
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
63+
;;
64+
*)
65+
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
66+
;;
67+
esac
68+
}
69+
70+
echo_terminal() {
71+
local text=$1
72+
echo -e "$text"
73+
}
74+
75+
echo_json() {
76+
local text=$1
77+
echo "$text" | jq -Rc '{type: "mrkdwn", text: .}' | awk '{gsub(/\\\\n/, "\\n"); print}'
78+
}
79+
80+
message=""
81+
for activeBranch in "${activeBranches[@]}"; do
82+
branch=$(echo "$activeBranch" | yq -r)
83+
url=$(get_url "$repo" "$branch")
84+
header="$(format_header "$branch" "$url" "$format")"
85+
prs="$(get_and_format_prs "$repo" "$branch" "$format")"
86+
if [ -n "$prs" ]; then
87+
message+="$header\n$prs\n"
88+
fi
89+
done
90+
91+
if [ -n "$message" ]; then
92+
# chomp off the last two newlines
93+
message="${message::-4}"
94+
95+
case $format in
96+
terminal|testing)
97+
echo_terminal "$message"
98+
;;
99+
*)
100+
echo_json "$message"
101+
;;
102+
esac
103+
fi

.github/workflows/stale-prs.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: 'Close stale PRs'
2+
3+
on:
4+
schedule:
5+
- cron: '30 1 * * *'
6+
workflow_dispatch:
7+
8+
jobs:
9+
stale:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/stale@v9
13+
with:
14+
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.'
15+
close-pr-message: 'This PR was closed because it has been stalled for 5 days with no activity.'
16+
days-before-issue-stale: -1
17+
days-before-issue-close: -1
18+
stale-pr-label: stale
19+
days-before-pr-stale: 5
20+
days-before-pr-close: 5

Taskfile.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,9 @@ tasks:
182182
GO_TEST_RUNNER:
183183
ref: .GO_TEST_RUNNER
184184
CLI_ARGS: '{{.CLI_ARGS}} -run "^TestAcceptance" -timeout 35m -tags acceptance'
185+
186+
pending-prs:
187+
desc: "Get all pending PRs for watched branches"
188+
silent: true
189+
cmds:
190+
- ./.github/workflows/scripts/pending-prs terminal redpanda-data/redpanda-operator

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
pkgs.docker-client
5656
pkgs.docker-tag-list
5757
pkgs.gawk # GNU awk, used by some build scripts.
58+
pkgs.gh
5859
pkgs.gnused # Stream Editor, used by some build scripts.
5960
pkgs.go-licenses
6061
pkgs.go-task

0 commit comments

Comments
 (0)