Test label workflow #9
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: PR Labeler | |
on: [pull_request] | |
jobs: | |
label: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const pr = context.payload.pull_request; | |
// Get list of changed files | |
const filesChanged = await github.rest.pulls.listFiles({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: pr.number | |
}); | |
// Initialize labels array | |
const labels = new Set(); | |
// Check each changed file | |
filesChanged.data.forEach(file => { | |
if (file.filename.startsWith('src/pages/')) { | |
labels.add('literary-contribution'); | |
} else { | |
labels.add('code-contribution'); | |
} | |
}); | |
// Convert Set to Array and add labels | |
if (labels.size > 0) { | |
await github.rest.issues.addLabels({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: pr.number, | |
labels: Array.from(labels) | |
}); | |
} |