[Github Action] PR 생성 시 title 앞에 'QA' 가 있는지 여부를 통해 label 변경하기
Jan 02, 2024
![[Github Action] PR 생성 시 title 앞에 'QA' 가 있는지 여부를 통해 label 변경하기](https://image.inblog.dev?url=https%3A%2F%2Finblog.ai%2Fapi%2Fog%3Ftitle%3D%255BGithub%2520Action%255D%2520PR%2520%25EC%2583%259D%25EC%2584%25B1%2520%25EC%258B%259C%2520title%2520%25EC%2595%259E%25EC%2597%2590%2520%27QA%27%2520%25EA%25B0%2580%2520%25EC%259E%2588%25EB%258A%2594%25EC%25A7%2580%2520%25EC%2597%25AC%25EB%25B6%2580%25EB%25A5%25BC%2520%25ED%2586%25B5%25ED%2595%25B4%2520label%2520%25EB%25B3%2580%25EA%25B2%25BD%25ED%2595%2598%25EA%25B8%25B0%26logoUrl%3Dhttps%253A%252F%252Finblog.ai%252Finblog_logo.png%26blogTitle%3Dveganee&w=2048&q=75)
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
- PR 생성 시 title 앞에
[QA]
를 붙이기 [QA]
를 붙이지 않으면 skip됨

- PR opened 시 PR opened한 branch name에 있는 issue number를 사용해 해당 issue에
qc-local-ing
추가됨 - 예를 들어, branch name = feature/client-hub-1372-github-action-test 라면 issue number = 1372

- PR closed 시
qc-local-done
추가 후qc-local-ing
삭제됨

Share article