Skip to content

Instantly share code, notes, and snippets.

@kevingduck
Created April 21, 2023 13:40
Show Gist options
  • Save kevingduck/09d65cbe140001a6da7cd18df764058f to your computer and use it in GitHub Desktop.
Save kevingduck/09d65cbe140001a6da7cd18df764058f to your computer and use it in GitHub Desktop.
name: Label Templated Issue
on:
issues:
types: [created]
jobs:
label-templated-issue:
runs-on: ubuntu-latest
steps:
- name: Get selected feature area
id: get_selected_feature_area
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const issueBody = context.payload.issue.body;
const featureAreaRegex = /Feature Area:\s*(.+)/i;
const match = issueBody.match(featureAreaRegex);
if (match && match[1]) {
return match[1].trim().toLowerCase();
} else {
return "";
}
- name: Fetch label id for selected feature area
id: fetch_label_id
if: ${{ steps.get_selected_feature_area.outputs.result != '' }}
uses: actions/github-script@v6
with:
script: |
const featureArea = "${{ steps.get_selected_feature_area.outputs.result }}";
const labels = await github.pulls.listLabels({
owner: context.repo.owner,
repo: context.repo.repo,
});
const label = labels.data.find(label => label.name.toLowerCase() === featureArea);
return label ? label.id : "";
- name: Label the issue
if: ${{ steps.fetch_label_id.outputs.result != '' }}
uses: actions/github-script@v6
with:
script: |
const labelId = "${{ steps.fetch_label_id.outputs.result }}";
const issueNumber = context.payload.issue.number;
await github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: [labelId],
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment