Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .github/branches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
active: ["main", "release/v2.3.x"]
4 changes: 3 additions & 1 deletion .github/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ labels:
color: "ededed"
"no-changelog":
color: "8f1402"
"stale":
color: "8f1402"
"v2.3.9":
color: "ededed"
color: "ededed"
3 changes: 1 addition & 2 deletions .github/workflows/backport.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ jobs:
- name: Backport Action
uses: sorenlouv/backport-github-action@v9.5.1
with:
# TODO: exchange this token with a PAT of a user like our build bot
github_token: ${{ secrets.GITHUB_TOKEN }}
github_token: ${{ secrets.ACTIONS_BOT_TOKEN }}

- name: Info log
if: ${{ success() }}
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/pending-prs.yml
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
Copy link
Contributor Author

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 -l will return 0 if there's nothing open or 1 if we have a payload to post.

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 }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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"
103 changes: 103 additions & 0 deletions .github/workflows/scripts/pending-prs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env bash

export BROWSER=echo
Copy link
Contributor Author

@andrewstucki andrewstucki Mar 7, 2025

Choose a reason for hiding this comment

The 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. gh -w actually opens the link directly, so rather than doing that I just want to echo it out and capture its value 😅

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, the nasty hack with awk here is b/c by default the gh client likes to mis-append an &type=issues onto the end of the URL which breaks it when trying to jump to the in-browser url:

➜  redpanda-operator git:(as/more-actions) BROWSER=echo gh search prs --repo=redpanda-data/redpanda-operator --state=open --base main -w 2> /dev/null
https://github.com/search?q=base%3Amain+repo%3Aredpanda-data%2Fredpanda-operator+state%3Aopen+type%3Apr&type=issues

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the <%s|#%v> syntax is because Slack's markdown isn't real markdown and this is surprisingly the link syntax.

;;
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}'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some gsub hackery here so that we don't double escape the newlines, which are double escaped elsewhere so they get properly handled with echo -e and so they aren't split here when handed off to jq -R

}

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
20 changes: 20 additions & 0 deletions .github/workflows/stale-prs.yml
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
6 changes: 6 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,9 @@ tasks:
GO_TEST_RUNNER:
ref: .GO_TEST_RUNNER
CLI_ARGS: '{{.CLI_ARGS}} -run "^TestAcceptance" -timeout 35m -tags acceptance'

pending-prs:
desc: "Get all pending PRs for watched branches"
silent: true
cmds:
- ./.github/workflows/scripts/pending-prs terminal redpanda-data/redpanda-operator
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
pkgs.docker-client
pkgs.docker-tag-list
pkgs.gawk # GNU awk, used by some build scripts.
pkgs.gh
pkgs.gnused # Stream Editor, used by some build scripts.
pkgs.go-licenses
pkgs.go-task
Expand Down