-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add actions for notifying of pending prs, closing stale prs and switch user for auto-backports #505
base: main
Are you sure you want to change the base?
Conversation
…h user for auto-backports
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 |
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.
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 |
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 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 |
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.
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}' |
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.
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 |
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 -l
will return 0
if there's nothing open or 1
if we have a payload to post.
uses: slackapi/[email protected] | ||
if: steps.generate-prs.outputs.has-prs != '0' | ||
with: | ||
webhook: ${{ secrets.SLACK_WEBHOOK_URL }} |
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.
We'll need to ask for one of these from infra folks to send this notification to our channel.
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!):
Here's what the output looks like in Slack (using my test Slack workspace):