Skip to content

Comments

Add actions for notifying of pending prs, closing stale prs and switch user for auto-backports#505

Merged
andrewstucki merged 1 commit intomainfrom
as/more-actions
Mar 21, 2025
Merged

Add actions for notifying of pending prs, closing stale prs and switch user for auto-backports#505
andrewstucki merged 1 commit intomainfrom
as/more-actions

Conversation

@andrewstucki
Copy link
Contributor

Title says pretty much what all of this is. The added task has some hackery to print out what essentially gets sent to Slack (when we set up a webhook for it asking infra folks). The bash script to generate it is all pretty gnarly, but figure 🤷 it's probably good enough for now.

Here's the terminal output (with clickable links!):

Screenshot 2025-03-07 at 4 19 05 PM

Here's what the output looks like in Slack (using my test Slack workspace):

Screenshot 2025-03-07 at 4 21 28 PM

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

@@ -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 😅

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.


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

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.

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.

@andrewstucki andrewstucki merged commit 98f4ce6 into main Mar 21, 2025
16 checks passed
@andrewstucki andrewstucki deleted the as/more-actions branch March 21, 2025 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants