From da31de2a8209cd73527b9b4314789dfac5e6fffa Mon Sep 17 00:00:00 2001 From: Chiedo John <2156688+chiedo@users.noreply.github.com> Date: Mon, 17 May 2021 14:50:57 -0400 Subject: [PATCH] Create update-status-labels-on-tracking-issues.yml (#19373) * Create update-status-labels-on-tracking-issues.yml * Lint Co-authored-by: chiedo --- ...pdate-status-labels-on-tracking-issues.yml | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/update-status-labels-on-tracking-issues.yml diff --git a/.github/workflows/update-status-labels-on-tracking-issues.yml b/.github/workflows/update-status-labels-on-tracking-issues.yml new file mode 100644 index 0000000000..a26b0c2826 --- /dev/null +++ b/.github/workflows/update-status-labels-on-tracking-issues.yml @@ -0,0 +1,46 @@ +name: Automatically Keep Epic Status Labels Updated +on: + issue_comment: + types: [created, edited] +jobs: + post-status-updates-to-slack: + runs-on: ubuntu-latest + if: contains(github.event.comment.body, '_created with') && contains(github.event.comment.body, 'typing_ `/status`') + steps: + - uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + + const issue = context.payload.issue + const owner = context.repo.owner + const repo = context.payload.repository.name + + const allStatusLabels = [ + 'Status: GREEN', + 'Status: GREY', + 'Status: YELLOW', + 'Status: BLACK', + 'Status: RED' + ]; + + const currentLabels = await github.issues.listLabelsOnIssue({ + owner: owner, + repo: repo, + issue_number: issue.number + }); + + const newLabels = currentLabels.data.filter( label => allStatusLabels.includes(label.name) === false) + + allStatusLabels.forEach( label => { + if(context.payload.comment.body.includes(label)) { + newLabels.push(label) + } + }); + + await github.issues.update({ + owner: owner, + repo: repo, + issue_number: issue.number, + labels: newLabels, + });