Cloth Classifier #7
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: PR Label Management | |
on: | |
pull_request: | |
types: [opened, edited, reopened, synchronize] | |
workflow_dispatch: | |
jobs: | |
manage-labels: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Check PR description and manage labels | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const { owner, repo } = context.repo; | |
const pr = context.payload.pull_request; | |
// Function to extract issue number from PR description | |
function extractIssueNumber(description) { | |
const match = description.match(/#(\d+)/); | |
return match ? match[1] : null; | |
} | |
// Function to add labels from an issue to the PR | |
async function addLabelsFromIssue(issueNumber) { | |
const issue = await github.rest.issues.get({ | |
owner, | |
repo, | |
issue_number: issueNumber | |
}); | |
if (issue.data.labels.length > 0) { | |
const labels = issue.data.labels.map(label => label.name); | |
await github.rest.issues.addLabels({ | |
owner, | |
repo, | |
issue_number: pr.number, | |
labels: labels | |
}); | |
console.log(`Added labels: ${labels.join(', ')}`); | |
} else { | |
console.log('No labels found on the linked issue'); | |
} | |
} | |
// Main logic | |
const issueNumber = extractIssueNumber(pr.body); | |
if (issueNumber) { | |
console.log(`Issue number found: #${issueNumber}`); | |
await addLabelsFromIssue(issueNumber); | |
} else { | |
console.log('No issue number found in PR description'); | |
await github.rest.issues.createComment({ | |
owner, | |
repo, | |
issue_number: pr.number, | |
body: 'Please update the PR description to include the related issue number (e.g., #123).' | |
}); | |
} |