Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add label on pr automatically #341

Closed
wants to merge 28 commits into from
Closed
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/add_label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: "Add labels"

on:
pull_request:

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
with:
script: |
github.rest.issues.removeLabel({
issue_number: issue_num,
owner: context.repo.owner,
repo: context.repo.repo,
name: ["mix", "mix_lint", "mix_annotations", "mix_generator", "documentation", "examples", "repo"]
})

const { execSync } = require('child_process')
const { commits } = context.payload.pull_request
const rawFiles = execSync(`git diff --name-only HEAD HEAD~${commits}`).toString()
const files = rawFiles.split('\n').filter(Boolean)

// verify packages
const packagesFiles = files.filter(file => file.startsWith('packages/') && !file.includes('mix_lint_test'))
const packages = packagesFiles.map(file => file.split('/')[1])
const labels = Array.from(new Set(packages))

// verify documentation
const wasDocModified = files.filter(file => file.startsWith('website/')).length > 0
if (wasDocModified) {
labels.push('documentation')
}

// verify examples
const wasExampleModified = files.filter(file => file.startsWith('examples/')).length > 0
if (wasExampleModified) {
labels.push('examples')
}

// verify repo
const wasRepoModified = files.filter(file => !file.startsWith('website/') && !file.startsWith('packages/') && !file.startsWith('examples/')).length > 0
if (wasRepoModified) {
labels.push('repo')
}

github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: labels
})


Loading