[Github Action] PR pull request/push 시 여러 개의 이슈티켓 label 변경하기
Jan 02, 2024
![[Github Action] PR pull request/push 시 여러 개의 이슈티켓 label 변경하기](https://image.inblog.dev?url=https%3A%2F%2Finblog.ai%2Fapi%2Fog%3Ftitle%3D%255BGithub%2520Action%255D%2520PR%2520pull%2520request%252Fpush%2520%25EC%258B%259C%2520%25EC%2597%25AC%25EB%259F%25AC%2520%25EA%25B0%259C%25EC%259D%2598%2520%25EC%259D%25B4%25EC%258A%2588%25ED%258B%25B0%25EC%25BC%2593%2520label%2520%25EB%25B3%2580%25EA%25B2%25BD%25ED%2595%2598%25EA%25B8%25B0%26logoUrl%3Dhttps%253A%252F%252Finblog.ai%252Finblog_logo.png%26blogTitle%3Dyoung9xo&w=2048&q=75)
Contents
test merged pr eventname: \'QA' label이 존재하는 Issue Card에 'qc-local-ing' 또는 'qc-local-done' label 추가/삭제하기
run-name: QA PR Issue card labeling (${{ github.actor}}) (github.event_name=${{ github.event_name }}) (github.event.action=${{ github.event.action }})
on:
push:
pull_request:
branches:
- develop
- release/**
- feature/**
types: [opened, closed]
permissions:
issues: write
pull-requests: read
id-token: write
contents: read
jobs:
qa_pr_setting:
runs-on: ubuntu-latest
outputs:
ISSUE_NUMBER_LIST: ${{ env.ISSUE_NUMBER_LIST }}
IS_QA_LABEL_EXIST_LIST: ${{ env.IS_QA_LABEL_EXIST_LIST }}
steps:
- uses: 8BitJonny/gh-get-current-pr@2.2.0
id: PR
- name: set ISSUE_NUMBER_LIST
if: steps.PR.outputs.pr_found == 'true'
env:
PR_BODY: ${{ steps.PR.outputs.pr_body || github.event.pull_request.body }}
uses: actions/github-script@v6
with:
script: |
try {
const { PR_BODY } = process.env
const findHCRIssueNumberRegex = /hub-control-room\/issues\/([0-9]+)/g;
const matchedList = String(PR_BODY).match(findHCRIssueNumberRegex)
if(!matchedList){
return;
}
const issueNumberList = matchedList.map((path)=> path.replace("hub-control-room/issues/",""))
core.exportVariable('ISSUE_NUMBER_LIST', issueNumberList)
} catch (error){
console.log('[get resolve issue number at commit message error]', error)
}
- run: |
echo ISSUE_NUMBER_LIST="$ISSUE_NUMBER_LIST"
- name: check QA label exist
uses: actions/github-script@v6
with:
script: |
try {
const { ISSUE_NUMBER_LIST, IS_QA_LABEL_EXIST_LIST } = process.env
if(!ISSUE_NUMBER_LIST){
return;
}
const qaLabelExistList = []
const issueNumberList = JSON.parse(ISSUE_NUMBER_LIST)
issueNumberList.forEach(async(issueNumber)=> {
const { data: issueData } = await github.rest.issues.get({
issue_number: issueNumber,
owner: context.repo.owner,
repo: context.repo.repo,
})
const isQALabelExist = issueData.labels.filter(({ name }) => name === 'QA').length === 1
if(isQALabelExist){
github.rest.issues.addLabels({
issue_number: issueNumber,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["qc-local-ing"]
})
qaLabelExistList.push(isQALabelExist)
core.exportVariable('IS_QA_LABEL_EXIST_LIST', qaLabelExistList)
}
})
} catch (error){
console.log('[get labels at issues error]', error)
}
- run: |
echo IS_QA_LABEL_EXIST_LIST="$IS_QA_LABEL_EXIST_LIST"
qa_pr_merged:
if: ${{ contains(fromJSON(needs.qa_pr_setting.outputs.IS_QA_LABEL_EXIST_LIST), true) && github.event.pull_request.merged == true}}
runs-on: ubuntu-latest
needs: qa_pr_setting
env:
ISSUE_NUMBER_LIST: ${{ needs.qa_pr_setting.outputs.ISSUE_NUMBER_LIST }}
IS_QA_LABEL_EXIST_LIST: ${{ needs.qa_pr_setting.outputs.IS_QA_LABEL_EXIST_LIST }}
steps:
- name: Change 'qc-local-ing' label to 'qc-local-done' label
uses: actions/github-script@v6
with:
script: |
try {
const { ISSUE_NUMBER_LIST } = process.env
if(!ISSUE_NUMBER_LIST){
return;
}
const issueNumberList = JSON.parse(ISSUE_NUMBER_LIST)
issueNumberList.forEach(async(issueNumber, index)=> {
const { data: issueData } = await github.rest.issues.get({
issue_number: issueNumber,
owner: context.repo.owner,
repo: context.repo.repo,
})
const isLocalQcIngLabelExist = issueData.labels.filter(({ name }) => name === 'qc-local-ing').length === 1
if(!isLocalQcIngLabelExist){
return;
}
github.rest.issues.addLabels({
issue_number: issueNumber,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["qc-local-done"]
})
github.rest.issues.removeLabel({
issue_number: issueNumber,
owner: context.repo.owner,
repo: context.repo.repo,
name: "qc-local-ing"
})
}
)
} catch (error){
console.log('[change label error]', error)
}
- PR body에 다음과 같이 'hub-control-room/issues/{이슈번호}’ 형식으로 PR에 연결할 이슈들을 등록합니다.

* <https://github.com/barogo/hub-control-room/issues/1372>
* <https://github.com/barogo/hub-control-room/issues/1420>
2. push 또는 pull_request event 발생 시 qa_pr_setting job에서 등록한 이슈번호들이 'QA' label을 가졌는지 자동으로 확인합니다.
- 확인 후 'QA' label을 가졌다면 자동으로 qc-local-ing 라벨이 이슈티켓에 추가됩니다.
- 'QA' label이 있고 closed된 PR이라면 자동으로 qc-local-done label이 자동으로 이슈티켓에 추가되고 qc-local-ing 라벨은 삭제됩니다.

test merged pr event


Share article