Fake PR to test auto labeling #3
Workflow file for this run
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: Auto-Label PRs | |
on: | |
pull_request_target: | |
types: [opened, synchronize] | |
jobs: | |
label-and-milestone: | |
runs-on: ubuntu-latest | |
steps: | |
# - name: Checkout repository | |
# uses: actions/checkout@v2 | |
- name: Set label and milestone | |
id: set-label-milestone | |
uses: actions/github-script@v6 | |
with: | |
# github-token: ${{ secrets.GITHUB_TOKEN }} | |
github-token: ${{ github.token }} | |
script: | | |
const completionsLabel = 'completions'; | |
const completionsMilestone = 'fish next-3.x'; | |
// Get changed files in the pull request | |
const prNumber = context.payload.pull_request.number; | |
const { data: files } = await github.pulls.listFiles({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: prNumber, | |
}); | |
// Check if any file matches /share/completions/*.fish and no change is outside of /share/ | |
const completionsRegex = new RegExp('^share/completions/.*\.fish'); | |
const isCompletions = files.some(file => completionsRegex.test(file.filename)) | |
&& files.all(file => file.filename.startsWith('share/'); | |
if (isCompletions) { | |
// Add label to PR | |
await github.issues.addLabels({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: prNumber, | |
labels: [completionsLabel], | |
}); | |
console.log(`PR ${prNumber} assigned label "${completionsLabel}"`); | |
// Get the list of milestones | |
const { data: milestones } = await github.issues.listMilestones({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}); | |
// Find the milestone id | |
const milestone = milestones.find(milestone => milestone.title === completionsMilestone); | |
if (milestone) { | |
// Set the milestone for the PR | |
await github.issues.update({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: prNumber, | |
milestone: milestone.number | |
}); | |
console.log(`PR ${prNumber} assigned milestone "${completionsMilestone}"`); | |
} else { | |
console.error(`Milestone "${completionsMilestone}" not found`); | |
} | |
} |