Check Pull Requests #27
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check Pull Requests | |
on: | |
schedule: | |
- cron: "* */1 * * *" # Run every hour | |
workflow_dispatch: # Allow manual triggering | |
permissions: | |
contents: read | |
pull-requests: 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 }} # Explicitly set the 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.map(pr => pr.number))); | |
console.log("owner: ", context.repo.owner); | |
console.log("repo: ", context.repo.repo); | |
console.log("PRs: ", JSON.stringify(pullRequests.map(pr => pr.number))); | |
- 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; | |
console.log("PRs raw: ", prsRaw); | |
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)); | |
trigger_validation: | |
needs: check_prs | |
if: 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 }}" |