Skip to content

docs: Add section for TokenResolver #645

docs: Add section for TokenResolver

docs: Add section for TokenResolver #645

Workflow file for this run

name: "Add labels"
on:
pull_request_target:
types:
- opened
- edited
- synchronize
- reopened
permissions:
pull-requests: write
jobs:
apply-label:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- uses: actions/github-script@v7
env:
GH_TOKEN: ${{ secrets.ADD_LABEL_BOT_TOKEN }}
with:
script: |
const { execSync } = require('child_process')
const { commits } = context.payload.pull_request
const rawFiles = execSync(`git diff --name-only origin/${{ github.base_ref }}`).toString()
const files = rawFiles.split('\n').filter(Boolean)
console.log('##### Modified Files #####')
console.log(files)
console.log('##########################')
// verify packages
const packagesFiles = files.filter(file => file.startsWith('packages/') && !file.includes('mix_lint_test'))
const packages = packagesFiles.map(file => file.split('/')[1])
const newLabels = Array.from(new Set(packages))
console.log('##### PackagesLabels #####')
console.log(newLabels)
console.log('##########################')
// verify documentation
const wasDocModified = files.filter(file => file.startsWith('website/')).length > 0
if (wasDocModified) {
newLabels.push('documentation')
console.log('documentation label was added')
}
// verify examples
const wasExampleModified = files.filter(file => file.startsWith('examples/')).length > 0
if (wasExampleModified) {
newLabels.push('examples')
console.log('examples label was added')
}
// verify repo
const wasRepoModified = files.filter(file => !file.startsWith('website/') && !file.startsWith('packages/') && !file.startsWith('examples/')).length > 0
if (wasRepoModified) {
newLabels.push('repo')
console.log('rep label was added')
}
console.log('##### New Labels #####')
console.log(newLabels)
console.log('##########################')
// Get existing labels
const existingLabels = await github.rest.issues.listLabelsOnIssue({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
})
const labelsToAdd = newLabels.filter(label => !existingLabels.data.some(existingLabel => existingLabel.name === label))
const labelsToRemove = existingLabels.data.filter(existingLabel => !newLabels.includes(existingLabel.name))
console.log('##### Labels to Add #####')
console.log(labelsToAdd)
console.log('##########################')
console.log('##### Labels to Remove #####')
console.log(labelsToRemove)
console.log('##########################')
// Add new labels
if (labelsToAdd.length > 0) {
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: labelsToAdd
})
}
// Remove unnecessary labels
for (const label of labelsToRemove) {
await github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: label.name
})
}