Skip to content

Commit 0ac2eaa

Browse files
authored
Add notify-stale-pr.yml
Thank you Salim!
1 parent 3076fbb commit 0ac2eaa

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

.github/workflows/notify-stale-pr.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Notify Stale PR
2+
3+
on:
4+
# schedule:
5+
# - cron: "* * * * *"
6+
workflow_dispatch:
7+
8+
9+
jobs:
10+
notify:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Install tools
14+
run: |
15+
sudo apt update
16+
sudo apt install -y curl jq
17+
18+
- name: Check for stale PRs
19+
id: stale_pr
20+
run: |
21+
22+
function is_stale() {
23+
24+
local created_at="$1";
25+
local created_ts=$(date -d "$created_at" +%s);
26+
local diff_sec=$(($(date +%s) - created_ts));
27+
local diff_days=$((diff_sec / 86400));
28+
29+
if [[ "$diff_days" -le "${{ vars.DAYS_SINCE_CREATED }}" ]]; then
30+
return 1;
31+
else
32+
return 0;
33+
fi;
34+
35+
}
36+
37+
message="";
38+
count=1;
39+
40+
while read -r pr; do
41+
title=$(echo "$pr" | jq -r '.title');
42+
user=$(echo "$pr" | jq -r '.user.login');
43+
user_link=$(echo "$pr" | jq -r '.user.html_url');
44+
created_at=$(echo "$pr" | jq -r '.created_at');
45+
updated_at=$(echo "$pr" | jq -r '.updated_at');
46+
pr_link=$(echo "$pr" | jq -r '.html_url');
47+
48+
if is_stale "$updated_at"; then
49+
message+="${count}. <${pr_link}|${title}>\n"; # title
50+
message+="\t• :slightly_smiling_face: Created By: <${user_link}|${user}>\n"; # user
51+
message+="\t• :date: *Opened At:* ${created_at}\n"; # opened date
52+
message+="\t• :link: Link: ${pr_link}\n"; # pr link
53+
((count++))
54+
fi;
55+
56+
done < <(curl -s "https://api.github.com/repos/${{ vars.REPO }}/pulls?state=open" | jq -c '.[]');
57+
58+
if [[ -n "$message" ]]; then
59+
echo "message=$message" >> "$GITHUB_OUTPUT";
60+
fi;
61+
62+
- name: "Notify Via Slack"
63+
if: steps.stale_pr.outputs.message != ''
64+
uses: slackapi/slack-github-action@v2.1.0
65+
with:
66+
method: chat.postMessage
67+
token: ${{ secrets.SLACK_BOT_TOKEN }}
68+
payload: |
69+
channel: ${{ secrets.SLACK_CHANNEL_ID }}
70+
text: "Stale Pull Requests"
71+
unfurl_links: false
72+
unfurl_media: false
73+
blocks:
74+
- type: "section"
75+
text:
76+
type: "mrkdwn"
77+
text: "*Stale Pull Requests* \n ${{ steps.stale_pr.outputs.message }}"
78+

0 commit comments

Comments
 (0)