[Github Action] PR pull request/push 시 여러 개의 이슈티켓 label 변경하기

Jan 02, 2024
[Github Action] PR pull request/push 시 여러 개의 이슈티켓 label 변경하기
name: \'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) }
  1. PR body에 다음과 같이 'hub-control-room/issues/{이슈번호}’ 형식으로 PR에 연결할 이슈들을 등록합니다.
notion image
* <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을 가졌는지 자동으로 확인합니다.
  1. 확인 후 'QA' label을 가졌다면 자동으로 qc-local-ing 라벨이 이슈티켓에 추가됩니다.
  1. 'QA' label이 있고 closed된 PR이라면 자동으로 qc-local-done label이 자동으로 이슈티켓에 추가되고 qc-local-ing 라벨은 삭제됩니다.
 
notion image
 

test merged pr event

issue card 1
issue card 1
issue card 2
issue card 2
 
Share article

veganee

RSS·Powered by Inblog