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: Sync Labels from Linear Issue to PR | |
on: | |
pull_request: | |
types: [opened, reopened, synchronize] | |
jobs: | |
sync-labels: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Get associated issue number | |
id: get-issue-number | |
run: | | |
ISSUE_NUMBERS=$(echo "${{ github.event.pull_request.body }}" | grep -oE "#[0-9]+" | tr -d "#" | tr '\n' ',') | |
ISSUE_NUMBERS=$(echo $ISSUE_NUMBERS | sed 's/,$//') | |
echo "issue_numbers=$ISSUE_NUMBERS" >> $GITHUB_ENV | |
echo "Issue numbers are $ISSUE_NUMBERS" | |
- name: Get labels from issue | |
id: get_issue_labels | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const issueNumbers = process.env.ISSUE_NUMBERS.split(","); | |
for (const issueNumber of issueNumbers) { | |
const { data: issue } = await github.rest.issues.get({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issueNumber, | |
}); | |
console.log(data); | |
const labels = issue.labels.map(label => label.name); | |
labels.forEach(label => allLabels.add(label)); | |
} | |
env: | |
ISSUE_NUMBERS: ${{ env.issue_numbers }} | |
- name: Apply labels to PR | |
if: steps.get_issue_labels.outputs.result != '' | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const labels = ${{env.labels}}.split(","); | |
echo `Applying labels: ${label.split(",")}`; | |
await github.rest.issues.addLabels({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
labels: labels, | |
}); |