[Github Action] PR 생성 시 title 앞에 'QA' 가 있는지 여부를 통해 label 변경하기

Jan 02, 2024
[Github Action] PR 생성 시 title 앞에 'QA' 가 있는지 여부를 통해 label 변경하기
name: QA PR branch name에 있는 Issue Number card에 label 추가/삭제하기 run-name: QA PR Issue card labeling (${{ github.actor}}) on: pull_request: types: [opened, closed] permissions: issues: write env: BRANCH_NAME: ${{ github.head_ref || github.ref_name }} jobs: job_opened: if: startsWith(github.event.pull_request.title,'[QA]') && github.event.action == 'opened' runs-on: ubuntu-latest steps: - name: check BRANCH_NAME run: | echo "BRANCH_NAME : $BRANCH_NAME" - name: Add 'qc-local-ing' label uses: actions/github-script@v6 with: script: | try{ const { BRANCH_NAME } = process.env const issue_num = String(BRANCH_NAME).split('-')[2] github.rest.issues.addLabels({ issue_number: issue_num, owner: context.repo.owner, repo: context.repo.repo, labels: ["qc-local-ing"] }) }catch (error){ console.log('[add label error]',error) } job_closed: if: startsWith(github.event.pull_request.title,'[QA]') && github.event.action == 'closed' runs-on: ubuntu-latest steps: - name: check BRANCH_NAME run: | echo "BRANCH_NAME: $BRANCH_NAME" - name: Change label 'qc-local-ing' to 'qc-local-done' uses: actions/github-script@v6 with: script: | try{ const { BRANCH_NAME } = process.env const issue_num = BRANCH_NAME.split('-')[2] github.rest.issues.addLabels({ issue_number: issue_num, owner: context.repo.owner, repo: context.repo.repo, labels: ["qc-local-done"] }) github.rest.issues.removeLabel({ issue_number: issue_num, owner: context.repo.owner, repo: context.repo.repo, labels: ["qc-local-ing"] }) }catch (error){ console.log('[change label error]',error) }
 
Use case
  1. PR 생성 시 title 앞에 [QA]를 붙이기
      • [QA]를 붙이지 않으면 skip됨
        • notion image
  1. PR opened 시 PR opened한 branch name에 있는 issue number를 사용해 해당 issue에 qc-local-ing 추가됨
    1. 예를 들어, branch name = feature/client-hub-1372-github-action-test 라면 issue number = 1372
      1. notion image
  1. PR closed 시 qc-local-done 추가 후 qc-local-ing 삭제됨
notion image
 
 
Share article

veganee

RSS·Powered by Inblog