fix: Stale pr workflow v1 (#9298)

This commit is contained in:
Bhargav
2025-11-26 15:03:08 +05:30
committed by GitHub
parent 80b1c0f1d8
commit 6dd1e7bab1
2 changed files with 35 additions and 20 deletions
+34 -19
View File
@@ -3,7 +3,7 @@ permissions:
contents: read
on:
schedule:
- cron: "20 17 * * *" # everyday at 4PM
- cron: "0 11 * * *" # everyday at 11AM
workflow_dispatch:
jobs:
@@ -11,39 +11,54 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Get stale PRs
- uses: actions/github-script@v6
- name: Get PRs older than 7 days
uses: actions/github-script@v6
id: stale-prs
with:
script: |
const sevenDaysAgo = new Date();
sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7);
const dateString = sevenDaysAgo.toISOString().split('T')[0];
const resp = await github.rest.search.issuesAndPullRequests({
q: `repo:${{ github.repository }} is:pr is:open label:stale`
q: `repo:${{ github.repository }} is:pr is:open created:<${dateString}`,
sort: 'created',
order: 'asc',
per_page: 100
});
const prs = resp.data.items.map(pr => ({
number: pr.number,
title: pr.title,
user: pr.user.login
}));
const prs = resp.data.items.map(pr => {
const createdDate = new Date(pr.created_at);
const daysOld = Math.floor((new Date() - createdDate) / (1000 * 60 * 60 * 24));
return {
number: pr.number,
title: pr.title,
user: pr.user.login,
daysOld: daysOld
};
});
core.setOutput("prs", JSON.stringify(prs));
- name: Build Slack message
id: slack-msg
run: |
PRS=$(echo '${{ steps.stale-prs.outputs.prs }}' | jq -r '.[] | "- <https://github.com/${{ github.repository }}/pull/\(.number)|#\(.number) \(.title)> — @\(.user)"')
MESSAGE="🔔 *Stale Pull Requests in ${{ github.repository }}*\n\n$PRS"
echo "message<<EOF" >> $GITHUB_OUTPUT
echo "$MESSAGE" >> $GITHUB_OUTPUT
PRS=$(echo '${{ steps.stale-prs.outputs.prs }}' | jq -r '.[] | "- <https://github.com/${{ github.repository }}/pull/\(.number)|#\(.number) \(.title)> — @\(.user) (_\(.daysOld) days old_)"')
PR_COUNT=$(echo '${{ steps.stale-prs.outputs.prs }}' | jq '. | length')
if [ "$PR_COUNT" -eq 0 ]; then
MESSAGE="✅ *No stale PRs in ${{ github.repository }}*\n\nAll PRs are less than 7 days old!"
else
MESSAGE="🔔 *Pull Requests older than 7 days in ${{ github.repository }}*\n\n$PRS"
fi
# Escape for JSON and create the payload
PAYLOAD=$(jq -n --arg msg "$MESSAGE" '{text: $msg}')
echo "payload<<EOF" >> $GITHUB_OUTPUT
echo "$PAYLOAD" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Send Slack notification
if: ${{ steps.stale-prs.outputs.prs != '' }}
uses: slackapi/slack-github-action@v1.25.0
with:
payload: |
{
"text": "${{ steps.slack-msg.outputs.message }}"
}
payload: ${{ steps.slack-msg.outputs.payload }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.STALE_PR_SLACK_NOTIFICATION }}
SLACK_WEBHOOK_URL: ${{ secrets.STALE_PR_SLACK_NOTIFICATION }}
+1 -1
View File
@@ -4,7 +4,7 @@ permissions:
pull-requests: write
on:
schedule:
- cron: "20 17 * * *" # runs daily
- cron: "0 0 * * *" # runs daily
workflow_dispatch:
jobs: