Skip to content

Check Pull Requests #34

Check Pull Requests

Check Pull Requests #34

Workflow file for this run

name: Check Pull Requests
on:
schedule:
- cron: "* */1 * * *" # Run every hour
workflow_dispatch: # Allow manual triggering
permissions:
contents: read
pull-requests: write
statuses: write
jobs:
check_prs:
runs-on: ubuntu-latest
steps:
- name: List Open Pull Requests
id: list_prs
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: pullRequests } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open'
});
core.exportVariable('PRS', JSON.stringify(pullRequests));
- name: Filter PRs without Validated or InProgress Status
id: filter_prs
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prsRaw = process.env.PRS;
if (!prsRaw || prsRaw === '[]') {
console.log("No PRs to validate.");
core.setOutput("prs_to_validate", JSON.stringify([]));
return;
}
const prs = JSON.parse(prsRaw);
const prNumbers = [];
for (const pr of prs) {
const { data: statuses } = await github.rest.repos.listCommitStatusesForRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: pr.head.sha
});
const hasValidatedStatus = statuses.some(status => status.context === 'Validated');
const hasInProgressStatus = statuses.some(status => status.context === 'InProgress');
if (!hasValidatedStatus && !hasInProgressStatus) {
prNumbers.push(pr.number);
}
}
core.setOutput("prs_to_validate", JSON.stringify(prNumbers));
console.log(`PRs to validate: ${JSON.stringify(prNumbers)}`);
trigger_validation:
needs: check_prs
if: ${{ needs.check_prs.outputs.prs_to_validate && needs.check_prs.outputs.prs_to_validate != '[]' }}
runs-on: ubuntu-latest
strategy:
matrix:
pr_number: ${{ fromJSON(needs.check_prs.outputs.prs_to_validate) }}
steps:
- name: Debug
run: |
echo "PR Number: ${{ matrix.pr_number }}"