Skip to content
name: 'Notify about seated PRs'
on:
schedule:
- cron: '0 10 * * *'
workflow_dispatch:
push:
branches:
- 28718-notify-seated-prs
jobs:
resolve-seated-prs:
runs-on: ubuntu-22.04
outputs:
seated_prs: ${{ steps.fetch-seated-prs.outputs.seated_prs }}
env:
REPO: core
PR_DAY_THRESHOLD: 5
DRAFT_PR_DAY_THRESHOLD: 10
steps:
- run: echo 'GitHub context'
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
- name: Filter execution
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const day = new Date().getDay();
console.log(new Date());
if (day === 0 || day === 6) {
console.log('It\'s (happy Ⓡ Freddy Rodriguez) weekend, not sending any notifications');
//process.exit(1);
}
- id: fetch-seated-prs
name: Fetch Seated PRs
if: success()
uses: actions/github-script@v7
with:
result-encoding: string
retries: 3
retry-exempt-status-codes: 400,401
script: |
const millisPerDay = 24 * 60 * 60 * 1000;
const prDayThreshold = ${{ env.PR_DAY_THRESHOLD }} * millisPerDay;
const draftPrDayThreshold = ${{ env.DRAFT_PR_DAY_THRESHOLD }} * millisPerDay;
const now = new Date();
const seatedPrs = {};
const fetchOpenPrs = async () => {
const opts = github.rest.pulls.list.endpoint.merge({
...{
owner: '${{ github.repository_owner }}',
repo: '${{ env.REPO }}',
per_page: 100
}
});
return await github.paginate(opts);
};
const isPrSeated = (pr) => {
const createdAt = new Date(Date.parse(pr.created_at));
const delta = now.getTime() - createdAt.getTime();
const threshold = pr.draft ? draftPrDayThreshold : prDayThreshold;
return delta >= threshold;
};
const addPr = (userPrs, pr) => {
if (isPrSeated(pr)) {
userPrs.push({
pr_number: pr.number,
url: pr.html_url,
draft: pr.draft,
created_at: pr.created_at,
updated_at: pr.updated_at
});
}
};
const handlePr = (pr) => {
const login = pr.user.login;
if (!seatedPrs[login]) {
seatedPrs[login] = [];
}
addPr(seatedPrs[login], pr);
};
const prs = await fetchOpenPrs();
console.log(`PRs size: [${prs.length}]`);
prs.forEach(handlePr);
const users = Object.keys(seatedPrs);
console.log(`Users: [${users}]`);
console.log(`Seated PRs size: [${Object.keys(seatedPrs).length}]`);
console.log(JSON.stringify(seatedPrs, null, 2));
core.setOutput('seated_prs', JSON.stringify(seatedPrs));
# notify-seated-prs:
# runs-on: ubuntu-22.04
# needs: resolve-seated-prs
# env:
# REPO: core
# PR_DAY_THRESHOLD: 5
# DRAFT_PR_DAY_THRESHOLD: 10
# steps:
# - id: