Skip to content

[AN][feat]: 깃허브 액션이 라벨을 할당하도록 수정#1121

Open
junseo511 wants to merge 4 commits intodevelop-anfrom
feat/1120
Open

[AN][feat]: 깃허브 액션이 라벨을 할당하도록 수정#1121
junseo511 wants to merge 4 commits intodevelop-anfrom
feat/1120

Conversation

@junseo511
Copy link
Contributor

@junseo511 junseo511 commented Jan 11, 2026

🔗 관련 이슈

📝 작업 내용

GitHub Actions 워크플로우를 통한 PR 자동 처리 시스템을 개선했습니다. 기존에는 PR 리뷰어 할당 시 Draft 상태를 고려하지 않아 불필요한 Draft PR에도 리뷰어 요청이 발생했고, PR 제목 기반의 라벨 자동 할당 기능이 없어 수동으로 라벨을 관리해야 했습니다.

주요 변경사항

  1. PR 제목 기반 자동 라벨 할당 기능 추가 (pr-label-init.yml 신규 생성)

    • PR 제목의 대괄호 안의 텍스트를 파싱하여 라벨 추출 (예: [feat], [fix], [AN] 등)
    • 정의된 허용 라벨 목록(AN, BE, chore, docs, feat, fix, refactor, style, test)과 검증하여 일치하는 라벨만 자동 할당
    • PR 편집/재오픈 이벤트와 "PR Title Sync" 워크플로우 완료 후 모두 트리거되도록 설정
    • workflow_run 이벤트에서는 API로 최신 PR 정보를 조회하여 제목이 반영된 상태에서 라벨 할당
  2. Draft PR 리뷰어 할당 개선 (pr-assign-init.yml 수정)

    • Draft 상태 체크 추가: Draft PR인 경우 리뷰어 요청을 건너뛰고 명시적으로 로그
    • 리뷰어 요청에 try/catch 예외 처리 추가: 실패 시 경고 로그를 남기고 계속 진행
    • 성공/실패/스킵 각 케이스에 대해 명확한 로깅으로 실행 추적성 향상
  3. Assignee 할당의 에러 처리 구조 개선

    • 리뷰어 요청과 달리 Assignee는 원작자 자신이므로 실패 확률이 낮지만, 리뷰어 할당 실패 시에도 작성자 Assignee는 진행되도록 설계하여 전체 워크플로우 안정성 강화

📊 변경 효과 요약

  • 파일 변경: 1개 신규 생성 (pr-label-init.yml, +69줄), 1개 수정 (pr-assign-init.yml, +16/-8줄)
  • 라벨 관리 자동화로 수동 개입 제거
  • Draft PR에 대한 불필요한 리뷰어 요청 차단
  • 워크플로우 실행 결과에 대한 가시성 개선 (이전: 결과 미로깅 → 현재: 성공/실패/스킵 모두 명확한 로그 기록)
  • 정량 지표: 정량 지표는 이번 PR에서 측정하지 않음

📸 스크린샷 (Optional)

(해당 없음)

@github-actions github-actions bot changed the title Feat/1120 [AN][feat]: 깃허브 액션이 라벨을 할당하도록 수정 Jan 11, 2026
@github-actions github-actions bot added the AN 안드로이드 관련 이슈 label Jan 11, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 11, 2026

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key(s) in object: 'tools'
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

이번 변경은 GitHub Actions 워크플로우 두 개를 대상으로 합니다. 첫째, pr-assign-init.yml은 draft 상태의 PR에 대한 검증 로직을 추가하고, 리뷰어 요청 시 try-catch 에러 처리 및 로깅을 개선했습니다. 둘째, pr-label-init.yml은 새로운 워크플로우를 추가하여 PR 제목에 포함된 대괄호 토큰(예: [feat], [fix])을 파싱하고, 허용된 라벨 집합과 검증한 후 매칭되는 라벨을 PR에 자동으로 부여합니다.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목이 실제 변경사항과 일치합니다. GitHub Actions 라벨 자동 할당 기능 추가 및 검수자 요청 로직 개선이 정확히 반영되어 있습니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed PR 설명이 제시된 템플릿 구조를 충실히 따르고 있으며, 모든 필수 섹션이 완성되어 있습니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot requested review from devfeijoa and hwannow January 11, 2026 08:59
@github-actions github-actions bot added the feat 새로운 기능을 구현합니다. label Jan 11, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @.github/workflows/pr-label-init.yml:
- Around line 59-69: Wrap the labels add flow in a try-catch, first retrieve the
current PR labels using github.rest.issues.listLabelsOnIssue (or issues.get) and
compute toAdd = labelsToAdd.filter(l => !existingLabels.includes(l)), then only
call github.rest.issues.addLabels with toAdd when toAdd.length > 0 and log the
actual added labels via core.info; in the catch log the error with core.error
including the caught error and context (prNumber, repo), and do not attempt
removal of existing labels here.
🧹 Nitpick comments (2)
.github/workflows/pr-assign-init.yml (1)

56-61: Assignee 할당에도 에러 핸들링을 추가하는 것을 권장합니다.

리뷰어 요청(lines 42-47)에는 try-catch 블록을 추가했지만, assignee 할당 로직에는 에러 핸들링이 없습니다. addAssignees API 호출도 실패할 수 있는 상황이 있습니다:

실패 가능한 경우:

  • PR 작성자가 이미 assignee로 지정된 경우
  • API rate limit 초과
  • 권한 문제 (예: 외부 기여자)
  • 네트워크 일시적 오류

권장하는 개선 방향:
리뷰어 할당과 동일한 패턴으로 에러 핸들링을 추가하여 일관성을 유지하고, 한 API 호출의 실패가 워크플로우 전체를 중단시키지 않도록 하는 것이 좋습니다.

🛡️ Assignee 할당에 에러 핸들링 추가 제안
+            try {
               await github.rest.issues.addAssignees({
                 owner: context.repo.owner,
                 repo: context.repo.repo,
                 issue_number: context.payload.pull_request.number,
                 assignees: [author]
               });
+              core.info(`Assignee added: ${author}`);
+            } catch (error) {
+              core.warning(`Failed to add assignee: ${error.message}`);
+            }

이렇게 하면:

  • 리뷰어 할당과 동일한 에러 핸들링 패턴 유지
  • assignee 할당 실패 시에도 워크플로우 계속 진행
  • 로그를 통해 문제 발생 여부 추적 가능
.github/workflows/pr-label-init.yml (1)

27-27: 라벨 목록이 하드코딩되어 있어 유지보수성이 떨어질 수 있습니다.

validLabels 배열이 스크립트 내부에 직접 정의되어 있습니다.

현재 방식의 문제점:

  • 라벨을 추가/제거할 때마다 워크플로우 파일을 직접 수정해야 함
  • pr-assign-init.yml의 팀 라벨(AN, BE)과 이 파일의 라벨이 분리되어 관리됨
  • 실수로 잘못된 라벨을 추가할 위험이 있음

개선 대안들:

대안 1: GitHub API로 저장소의 실제 라벨 목록 조회 (권장)

  • 장점: 라벨이 저장소에 실제로 존재하는지 자동 검증, 중앙 집중식 관리
  • 단점: API 호출 추가로 약간의 실행 시간 증가

대안 2: 별도의 설정 파일로 분리

  • 장점: 라벨 관리가 한 곳에서 가능, 다른 워크플로우와 공유 가능
  • 단점: 파일 읽기 단계가 추가됨

대안 3: 현재 방식 유지 + 주석으로 문서화

  • 장점: 가장 간단하고 빠름
  • 단점: 여전히 수동 관리 필요

현재 프로젝트 규모와 라벨 변경 빈도를 고려하여 선택하시면 됩니다. 라벨이 자주 변경되지 않는다면 현재 방식도 충분히 실용적입니다.

💡 대안 1: GitHub API로 저장소 라벨 조회 예시
-            const validLabels = ['AN', 'BE', 'chore', 'docs', 'feat', 'fix', 'refactor', 'style', 'test'];
+            // Fetch repository labels to ensure they exist
+            const { data: repoLabels } = await github.rest.issues.listLabelsForRepo({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+            });
+            const validLabels = repoLabels.map(label => label.name);

이렇게 하면 저장소에 실제로 존재하는 라벨만 자동으로 사용하게 됩니다.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between deaf81f and 9780ffd.

📒 Files selected for processing (2)
  • .github/workflows/pr-assign-init.yml
  • .github/workflows/pr-label-init.yml
🔇 Additional comments (4)
.github/workflows/pr-assign-init.yml (1)

38-54: Draft PR 체크와 에러 핸들링 추가가 좋습니다!

Draft PR에 대한 리뷰어 요청을 건너뛰는 로직과 try-catch를 통한 에러 핸들링이 잘 추가되었습니다. 이를 통해:

  • Draft 상태의 PR에서 불필요한 리뷰어 알림을 방지
  • API 호출 실패 시 워크플로우 전체가 중단되지 않고 경고만 남김
  • 로깅을 통해 디버깅 가능성 향상

이러한 개선은 워크플로우의 안정성과 사용자 경험을 모두 향상시킵니다.

.github/workflows/pr-label-init.yml (3)

31-51: 두 가지 이벤트 소스를 잘 처리하고 있습니다.

workflow_runpull_request 이벤트를 모두 지원하는 로직이 명확하게 분기되어 있고, workflow_run에서 PR이 없는 경우도 적절히 처리하고 있습니다.

특히 좋은 점:

  • Line 37-42: workflow_run에서 최신 PR 데이터를 다시 fetch하여 업데이트된 제목을 가져오는 부분이 정확합니다
  • Line 44-45: PR이 연관되지 않은 경우 early return으로 불필요한 처리를 방지

이 구조는 두 가지 트리거 시나리오를 모두 안전하게 처리할 수 있습니다.


53-57: 정규식 패턴과 라벨 추출 로직이 명확합니다.

대괄호 안의 텍스트를 추출하는 정규식 /\[([^\]]+)\]/g와 필터링 로직이 잘 구현되어 있습니다.

동작 확인:

  • [feat] Add feature['feat'] 추출 ✓
  • [AN][fix] Fix bug['AN', 'fix'] 추출 ✓
  • [invalid] No match → 필터링되어 제외됨 ✓

로직이 의도대로 동작하며 엣지 케이스도 잘 처리됩니다.


4-6: "PR Title Sync" 워크플로우 존재 확인됨 - 문제 없음

.github/workflows/pr-title-init.yml 파일이 존재하며, name 필드가 정확히 "PR Title Sync"로 설정되어 있습니다. 따라서 workflow_run 트리거(라인 4-6)가 정상적으로 작동할 것으로 확인됩니다.

이 부분의 검증이 필요했던 이유는 GitHub Actions에서 workflow_run 트리거는 참조하는 워크플로우의 이름이 정확히 일치해야만 동작하기 때문입니다. 이름에 오타가 있거나 워크플로우가 존재하지 않으면 해당 트리거가 작동하지 않아 예상치 못한 버그의 원인이 될 수 있습니다. 다행히 이 경우 워크플로우가 존재하고 이름이 정확하므로 의도대로 PR 제목 동기화 완료 후 라벨 자동 할당이 실행될 것입니다.

Comment on lines +59 to +69
if (labelsToAdd.length > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: labelsToAdd
});
core.info(`Labels added: ${labelsToAdd.join(', ')}`);
} else {
core.info('No matching labels found in PR title');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

라벨 추가 로직에 에러 핸들링과 중복 방지 개선이 필요합니다.

현재 구현에는 두 가지 개선 가능한 부분이 있습니다:

문제점 1: 에러 핸들링 부재
addLabels API 호출(lines 60-65)에 try-catch가 없어서 실패 시 워크플로우 전체가 중단됩니다. 가능한 실패 상황:

  • 권한 부족 (특히 외부 기여자의 PR)
  • API rate limit 초과
  • 네트워크 일시적 오류
  • 존재하지 않는 라벨 추가 시도

pr-assign-init.yml에서는 에러 핸들링을 추가했는데, 이 파일에는 없어서 일관성이 떨어집니다.

문제점 2: 중복 라벨 추가 가능성
PR 제목을 수정할 때마다 이 워크플로우가 실행되는데, addLabels API는 이미 존재하는 라벨을 다시 추가하려고 시도합니다. GitHub API는 중복을 무시하지만, 불필요한 API 호출이 발생하고 로그가 부정확해질 수 있습니다.

문제점 3: 라벨 제거 로직 없음
PR 제목에서 라벨을 제거해도 PR에 이미 붙은 라벨은 그대로 남습니다. 예를 들어:

  • 초기 제목: [feat] Add featurefeat 라벨 추가
  • 수정 제목: [fix] Fix featurefix 라벨 추가, feat 라벨은 그대로 유지됨
🔧 에러 핸들링 추가 및 중복 방지 개선안
             const labelsToAdd = extractedLabels.filter(label => validLabels.includes(label));
             
             if (labelsToAdd.length > 0) {
+              try {
+                // Get current labels to avoid duplicates
+                const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
+                  owner: context.repo.owner,
+                  repo: context.repo.repo,
+                  issue_number: prNumber
+                });
+                const currentLabelNames = currentLabels.map(label => label.name);
+                const newLabels = labelsToAdd.filter(label => !currentLabelNames.includes(label));
+                
+                if (newLabels.length > 0) {
                   await github.rest.issues.addLabels({
                     owner: context.repo.owner,
                     repo: context.repo.repo,
                     issue_number: prNumber,
-                    labels: labelsToAdd
+                    labels: newLabels
                   });
-                  core.info(`Labels added: ${labelsToAdd.join(', ')}`);
+                  core.info(`Labels added: ${newLabels.join(', ')}`);
+                } else {
+                  core.info('All labels already exist on PR');
+                }
+              } catch (error) {
+                core.warning(`Failed to add labels: ${error.message}`);
+              }
             } else {
               core.info('No matching labels found in PR title');
             }

이 개선안의 장점:

  • try-catch로 API 실패 시에도 워크플로우가 계속 진행됨
  • 기존 라벨을 확인하여 중복 추가를 방지
  • 로그가 더 정확해짐 (실제로 추가된 라벨만 표시)
  • pr-assign-init.yml과 에러 핸들링 패턴이 일관됨

참고: 라벨 제거 로직은 더 복잡한 요구사항이므로, 필요하다면 별도의 이슈로 추적하는 것을 권장합니다. 제거 로직을 추가하려면:

  1. 제목에서 제거된 라벨을 감지
  2. 다른 워크플로우나 수동으로 추가한 라벨과 구분
  3. 안전하게 제거할 수 있는 라벨만 제거

이는 현재 범위를 넘어서는 작업이므로 선택적으로 고려하시면 됩니다.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (labelsToAdd.length > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: labelsToAdd
});
core.info(`Labels added: ${labelsToAdd.join(', ')}`);
} else {
core.info('No matching labels found in PR title');
}
const labelsToAdd = extractedLabels.filter(label => validLabels.includes(label));
if (labelsToAdd.length > 0) {
try {
// Get current labels to avoid duplicates
const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber
});
const currentLabelNames = currentLabels.map(label => label.name);
const newLabels = labelsToAdd.filter(label => !currentLabelNames.includes(label));
if (newLabels.length > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: newLabels
});
core.info(`Labels added: ${newLabels.join(', ')}`);
} else {
core.info('All labels already exist on PR');
}
} catch (error) {
core.warning(`Failed to add labels: ${error.message}`);
}
} else {
core.info('No matching labels found in PR title');
}
🤖 Prompt for AI Agents
In @.github/workflows/pr-label-init.yml around lines 59 - 69, Wrap the labels
add flow in a try-catch, first retrieve the current PR labels using
github.rest.issues.listLabelsOnIssue (or issues.get) and compute toAdd =
labelsToAdd.filter(l => !existingLabels.includes(l)), then only call
github.rest.issues.addLabels with toAdd when toAdd.length > 0 and log the actual
added labels via core.info; in the catch log the error with core.error including
the caught error and context (prNumber, repo), and do not attempt removal of
existing labels here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AN 안드로이드 관련 이슈 feat 새로운 기능을 구현합니다.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant