Label PR Authors (Scheduled) #2000
This file contains hidden or 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: Label PR Authors (Scheduled) | |
| on: | |
| schedule: | |
| - cron: '0 * * * *' # every hour | |
| workflow_dispatch: # allow manual run too | |
| permissions: | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| label-prs: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const org = "FLOrbit"; | |
| const prs = await github.rest.pulls.list({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: "open", | |
| per_page: 100, | |
| }); | |
| for (const pr of prs.data) { | |
| const labels = pr.labels.map(l => l.name); | |
| const hasLabel = labels.includes("Maintainer") || labels.includes("Contributor"); | |
| if (hasLabel) continue; | |
| const author = pr.user.login; | |
| let isMaintainer = false; | |
| try { | |
| const result = await github.rest.orgs.checkMembershipForUser({ | |
| org, | |
| username: author | |
| }); | |
| isMaintainer = result.status === 204; | |
| } catch (e) { | |
| if (e.status === 404) { | |
| isMaintainer = false; | |
| } else { | |
| throw e; | |
| } | |
| } | |
| const label = isMaintainer ? "Maintainer" : "Contributor"; | |
| console.log(`Labeling PR #${pr.number} by ${author} as ${label}`); | |
| await github.rest.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: pr.number, | |
| labels: [label], | |
| }); | |
| } |