AutoAssign

2025. 6. 11. 22:19·Git/action
반응형

👋 들어가기 전

이번 내용은 프로젝트 협업에 유용한 custom workflow를 가져왔다.

바로 AutoAssign이다.

 

AutoAssign은 PR에서 담당자를 자동으로 지정해주는 workflow다.

 

 

매번 이렇게 수동으로 해주는 것도 좋지만, PR올리는 유저 = Assigne인 경우가 거의 대부분이기 때문에

 

이런 특징을 이용하면, Assign지정을 PR올리는 유저로 자동으로 지정해버리면 편할 것 같다.

🏁 학습할 내용

  • 전체 코드
  • 분석

📋 전체코드

먼저 오늘 분석할 workflow 코드를 살펴보자.

name: Auto assign PR author

on:
  pull_request:
    types:
      - opened
      - reopened

jobs:
  assign-pr-author:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Get PR author
        id: get-pr-author
        run: echo "author=${{ github.event.pull_request.user.login }}" >> $GITHUB_OUTPUT

      - name: Assign PR author
        run: gh pr edit ${{ github.event.number }} --add-assignee ${{ steps.get-pr-author.outputs.author }}
        env:
          GH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

      - name: Comment success result to PR
        uses: mshick/add-pr-comment@v2
        if: ${{ success() }}
        with:
          message: |
            ## ✅ Assign 자동 지정을 성공했어요!
            @${{ steps.get-pr-author.outputs.author }}
          allow-repeats: true
          repo-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

      - name: Comment failure result to PR
        uses: mshick/add-pr-comment@v2
        if: ${{ failure() }}
        with:
          message: "## ❌ PR의 Assign 자동 지정을 실패했어요."
          allow-repeats: true
          repo-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

📊 분석

위 코드는 크게 3가지 부분으로 나눌 수 있다.

  • action trigger 설정
  • Assign 지정
  • 결과 코멘트 추가

🔫 Trigger 지정

name: Auto assign PR author

on:
  pull_request:
    types:
      - opened 
      - reopened

PR이 최초로 열리거나, 다시 열리면 실행한다.

✅ Assgin 지정

jobs:
  assign-pr-author:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Get PR author
        id: get-pr-author
        run: echo "author=${{ github.event.pull_request.user.login }}" >> $GITHUB_OUTPUT

      - name: Assign PR author
        run: gh pr edit ${{ github.event.number }} --add-assignee ${{ steps.get-pr-author.outputs.author }}
        env:
          GH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

 

1) Get PR author step 부터 알아보자.

 

${{ github.event.pull_request.user.login }} 결과는 현재 PR 작성자의 ID를 얻는다.

그값을 steps.get-pr-author(step_id).outputs.author(variable_name)으로 얻을 수 있다.

 

2) Assign PR author

 

gh pr edit ${{ github.event.number }} --add-assignee ${{ steps.get-pr-author.outputs.author }}

 

현재 event번호(현재 이벤트 번호 =  PR번호)에 해당하는 PR을 수정한다.

 

이때 assignee을 위에서 구한, 현재 PR 작성자 ID로 추가한다.

 

💡 토큰을 사용한 이유는, PR 수정은 인증된 멤버만 할 수 있어야한다.

 

🫧 결과 코멘트 지정

      - name: Comment success result to PR
        uses: mshick/add-pr-comment@v2
        if: ${{ success() }}
        with:
          message: |
            ## ✅ Assign 자동 지정을 성공했어요!
            @${{ steps.get-pr-author.outputs.author }}
          allow-repeats: true
          repo-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

      - name: Comment failure result to PR
        uses: mshick/add-pr-comment@v2
        if: ${{ failure() }}
        with:
          message: "## ❌ PR의 Assign 자동 지정을 실패했어요."
          allow-repeats: true
          repo-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

 

https://github.com/mshick/add-pr-comment 를 사용하면 PR에 Comment를 손쉽게 추가할 수 있다.

 

${{success()}} 의 결과는 앞선 steps에서 실패한 내용이 없으면 true로 받는다.

반대로 ${{failure()}} 은 steps에서 실패한 내용이 있으면 true를 받는다.

 

assign 지정이 성공했을 경우 

 @${{ steps.get-pr-author.outputs.author }} 로 Comment가 달린다.

 

결과는 아래와 같다.

반응형

'Git > action' 카테고리의 다른 글

[문제 해결] 파이썬 의존성 문제  (0) 2025.10.08
Runner란  (2) 2025.08.30
[ 부스트 캠프 ] CI를 통한 범인 찾기  (1) 2024.11.28
유용한 Marketplace workflow  (2) 2024.11.17
workflow 만들기  (2) 2024.11.17
'Git/action' 카테고리의 다른 글
  • [문제 해결] 파이썬 의존성 문제
  • Runner란
  • [ 부스트 캠프 ] CI를 통한 범인 찾기
  • 유용한 Marketplace workflow
Hamp
Hamp
남들에게 보여주기 부끄러운 잡다한 글을 적어 나가는 자칭 기술 블로그입니다.
  • Hamp
    Hamp의 분리수거함
    Hamp
  • 전체
    오늘
    어제
    • 분류 전체보기 (309) N
      • CS (30)
        • 객체지향 (2)
        • Network (7)
        • OS (6)
        • 자료구조 (1)
        • LiveStreaming (3)
        • 이미지 (1)
        • 잡다한 질문 정리 (0)
        • Hardware (2)
        • 이론 (6)
        • 컴퓨터 그래픽스 (0)
      • Firebase (3)
      • Programing Langauge (38)
        • swift (32)
        • python (5)
        • Kotlin (1)
      • iOS (132)
        • UIKit (37)
        • Combine (1)
        • SwiftUI (32)
        • Framework (7)
        • Swift Concurrency (22)
        • Tuist (6)
        • Setting (11)
        • Modularization (1)
        • Instruments (6)
      • PS (59)
        • 프로그래머스 (24)
        • 백준 (13)
        • LeetCode (19)
        • 알고리즘 (3)
      • Git (18)
        • 명령어 (4)
        • 이론 (2)
        • hooks (1)
        • config (2)
        • action (7)
      • Shell Script (2)
      • Linux (6)
        • 명령어 (5)
      • Spring (15) N
        • 어노테이션 (3) N
        • 튜토리얼 (11)
      • CI-CD (4)
      • Android (0)
        • Jetpack Compose (0)
      • AI (2) N
        • 이론 (2) N
  • 블로그 메뉴

    • 홈
    • 태그
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    Tuist
    IOS
    UIKit
    concurrency
    CS
    lifecycle
    boostcamp
    GIT
    백준
    dfs
    AVFoundation
    프로그래머스
    Swift
    SwiftUI
    property
    protocol
    dp
    Spring
    투포인터
    dispatch
  • 최근 댓글

  • 최근 글

  • 반응형
  • hELLO· Designed By정상우.v4.10.0
Hamp
AutoAssign
상단으로

티스토리툴바