-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(auto_assign): Add GitHub Actions workflow for auto-assigning PR creators #102
base: main
Are you sure you want to change the base?
Conversation
|
""" 워크스루새로운 GitHub Actions 워크플로우 파일 변경 사항
시퀀스 다이어그램sequenceDiagram
participant PR Creator
participant GitHub Actions
participant GitHub API
PR Creator->>GitHub Actions: Pull Request 생성
GitHub Actions->>GitHub API: PR 정보 조회
GitHub API-->>GitHub Actions: PR 정보 반환
GitHub Actions->>GitHub API: PR 생성자를 담당자로 지정
토끼의 시
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
🔇 Additional comments (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (1)
.github/workflows/auto_assign.yaml (1)
1-6
: PR이 다시 열릴 때도 자동 할당이 필요합니다워크플로우가 PR이 처음 열릴 때만 트리거되도록 설정되어 있습니다. PR이 다시 열리는 경우도 처리하도록 개선하는 것이 좋겠습니다.
다음과 같이 수정하는 것을 제안합니다:
on: pull_request: - types: [opened] + types: [opened, reopened]
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
.github/workflows/auto_assign.yaml
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: chromatic
🔇 Additional comments (1)
.github/workflows/auto_assign.yaml (1)
11-14
: 작업 구성이 적절합니다작업 이름이 명확하고 실행 환경이 적절하게 설정되어 있습니다.
.github/workflows/auto_assign.yaml
Outdated
permissions: | ||
pull-requests: write | ||
issues: write | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
불필요한 권한을 제거하세요
PR 담당자 지정을 위해서는 pull-requests
권한만 필요합니다. 최소 권한의 원칙에 따라 불필요한 issues
권한은 제거하는 것이 좋습니다.
다음과 같이 수정하는 것을 제안합니다:
permissions:
pull-requests: write
- issues: write
📝 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.
permissions: | |
pull-requests: write | |
issues: write | |
permissions: | |
pull-requests: write | |
.github/workflows/auto_assign.yaml
Outdated
- uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const pr = context.payload.pull_request; | ||
const repository = context.payload.repository; | ||
await github.rest.issues.addAssignees({ | ||
owner: repository.owner.login, | ||
repo: repository.name, | ||
issue_number: pr.number, | ||
assignees: [pr.user.login] | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
에러 처리 로직을 추가하세요
GitHub API 호출 시 발생할 수 있는 오류(예: API 제한, 네트워크 문제 등)에 대한 처리가 없습니다. 워크플로우의 안정성을 위해 에러 처리를 추가하는 것이 좋겠습니다.
다음과 같이 수정하는 것을 제안합니다:
- uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const repository = context.payload.repository;
- await github.rest.issues.addAssignees({
- owner: repository.owner.login,
- repo: repository.name,
- issue_number: pr.number,
- assignees: [pr.user.login]
- });
+ try {
+ await github.rest.issues.addAssignees({
+ owner: repository.owner.login,
+ repo: repository.name,
+ issue_number: pr.number,
+ assignees: [pr.user.login]
+ });
+ console.log(`Successfully assigned ${pr.user.login} to PR #${pr.number}`);
+ } catch (error) {
+ console.error('Failed to assign PR creator:', error);
+ core.setFailed(error.message);
+ }
📝 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.
- uses: actions/github-script@v7 | |
with: | |
script: | | |
const pr = context.payload.pull_request; | |
const repository = context.payload.repository; | |
await github.rest.issues.addAssignees({ | |
owner: repository.owner.login, | |
repo: repository.name, | |
issue_number: pr.number, | |
assignees: [pr.user.login] | |
}); | |
- uses: actions/github-script@v7 | |
with: | |
script: | | |
const pr = context.payload.pull_request; | |
const repository = context.payload.repository; | |
try { | |
await github.rest.issues.addAssignees({ | |
owner: repository.owner.login, | |
repo: repository.name, | |
issue_number: pr.number, | |
assignees: [pr.user.login] | |
}); | |
console.log(`Successfully assigned ${pr.user.login} to PR #${pr.number}`); | |
} catch (error) { | |
console.error('Failed to assign PR creator:', error); | |
core.setFailed(error.message); | |
} |
…PR creators - Removed unnecessary permissions for issues. - Added try-catch block to handle errors when assigning PR creators, with logging for success and failure cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
액션의 유지보수성을 높이기 위해 JavaScript action으로 만들어서 관리하면 어떨까? ㅎㅎ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 좋은생각인 것 같아!!
한번 시도해볼게!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
♻️ Duplicate comments (1)
.github/workflows/auto-assign/auto_assign.js (1)
5-34
: 🛠️ Refactor suggestion에러 처리를 개선해야 합니다
현재 에러 처리가 너무 단순합니다. GitHub API 호출 시 발생할 수 있는 구체적인 에러 케이스(예: API 제한, 권한 부족 등)에 대한 처리가 필요합니다.
다음과 같이 개선하는 것을 제안합니다:
const octokit = github.getOctokit(token); +const { retry } = require('@octokit/plugin-retry'); +const RetryOctokit = github.getOctokit(token).plugin(retry); - await octokit.rest.issues.addAssignees({ + try { + await RetryOctokit.rest.issues.addAssignees({ owner: repository.owner.login, repo: repository.name, issue_number: pr.number, assignees: [pr.user.login], - }); + }); + } catch (error) { + if (error.status === 403) { + throw new Error('권한이 부족합니다. GitHub 토큰의 권한을 확인해주세요.'); + } else if (error.status === 429) { + throw new Error('GitHub API 호출 제한에 도달했습니다. 잠시 후 다시 시도해주세요.'); + } + throw error; + }
🧹 Nitpick comments (2)
.github/workflows/auto-assign/auto_assign.js (1)
1-4
: ESLint 설정 개선이 필요합니다TypeScript 프로젝트에서 JavaScript 파일을 사용하고 있습니다. 코드베이스의 일관성을 위해 TypeScript로 마이그레이션하는 것이 좋습니다.
다음과 같이 변경하는 것을 제안합니다:
- 파일 확장자를
.ts
로 변경- 타입 정의 추가:
import * as github from '@actions/github' import * as core from '@actions/core' interface Repository { owner: { login: string } name: string } interface PullRequest { number: number user: { login: string } }.github/workflows/auto_assign.yaml (1)
28-32
: 의존성 설치 단계 최적화가 필요합니다
npm ci
명령어를 실행하기 전에package-lock.json
파일의 존재 여부를 확인하지 않고 있습니다.다음과 같이 수정하는 것을 제안합니다:
- name: Install dependencies for auto-assign run: | cd .github/workflows/auto-assign + if [ ! -f package-lock.json ]; then + echo "Error: package-lock.json not found" + exit 1 + fi npm ci
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
.github/workflows/auto-assign/package-lock.json
is excluded by!**/package-lock.json
📒 Files selected for processing (3)
.github/workflows/auto-assign/auto_assign.js
(1 hunks).github/workflows/auto-assign/package.json
(1 hunks).github/workflows/auto_assign.yaml
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- .github/workflows/auto-assign/package.json
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/auto_assign.yaml
16-16: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
🔇 Additional comments (2)
.github/workflows/auto_assign.yaml (2)
7-10
: 권한 설정이 최적화되어 있습니다이전 리뷰 의견을 반영하여 필요한 최소한의 권한만 설정된 것을 확인했습니다.
1-37
: JavaScript 액션으로의 마이그레이션을 고려해보세요이전 리뷰 의견에서 제안된 것처럼, 이 워크플로우를 JavaScript 액션으로 변환하면 재사용성과 유지보수성이 향상될 것 같습니다.
JavaScript 액션으로 변환하는 작업을 도와드릴까요?
🧰 Tools
🪛 actionlint (1.7.4)
16-16: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
} | ||
} | ||
|
||
run(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
비동기 함수 실행 방식 개선이 필요합니다
비동기 함수의 실행 결과와 에러를 제대로 처리하지 않고 있습니다.
다음과 같이 수정하는 것을 제안합니다:
-run();
+run().catch(error => {
+ console.error('치명적인 오류 발생:', error);
+ process.exit(1);
+});
📝 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.
run(); | |
run().catch(error => { | |
console.error('치명적인 오류 발생:', error); | |
process.exit(1); | |
}); |
.github/workflows/auto_assign.yaml
Outdated
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
액션 버전 업데이트가 필요합니다
actions/checkout
액션의 버전이 너무 오래되었습니다.
다음과 같이 수정하는 것을 제안합니다:
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
📝 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.
uses: actions/checkout@v3 | |
uses: actions/checkout@v4 |
🧰 Tools
🪛 actionlint (1.7.4)
16-16: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
.github/workflows/auto_assign.yaml
Outdated
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "22" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Node.js 버전 선택을 재고해야 합니다
Node.js 22 버전은 아직 안정화되지 않은 버전입니다. 프로덕션 환경에서는 LTS 버전을 사용하는 것이 좋습니다.
다음과 같이 수정하는 것을 제안합니다:
- node-version: "22"
+ node-version: "20"
📝 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.
node-version: "22" | |
node-version: "20" |
There was a problem hiding this 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
🧹 Nitpick comments (1)
.github/workflows/auto-assign/auto_assign.js (1)
5-9
: 토큰 검증 로직 개선이 필요합니다.토큰 유효성 검사를 더 강화하고 오류 메시지를 더 상세하게 제공하면 좋을 것 같습니다.
다음과 같이 수정하는 것을 제안합니다:
async function getOctokitAndContext() { const token = process.env.GITHUB_TOKEN; - if (!token) throw new Error('GITHUB_TOKEN is not provided'); + if (!token) throw new Error('GitHub 토큰이 환경 변수에 설정되지 않았습니다. workflow 파일에서 permissions 설정을 확인해주세요.'); + if (typeof token !== 'string' || token.trim() === '') { + throw new Error('GitHub 토큰이 유효하지 않습니다.'); + } return { octokit: github.getOctokit(token), context: github.context }; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
.github/workflows/auto-assign/auto_assign.js
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: chromatic
🔇 Additional comments (2)
.github/workflows/auto-assign/auto_assign.js (2)
1-3
: ESLint 설정과 임포트가 적절합니다!GitHub Actions 스크립트에 필요한 ESLint 규칙 비활성화와 라이브러리 임포트가 올바르게 구성되어 있습니다.
32-32
: 비동기 함수 실행 방식 개선이 필요합니다이전 리뷰에서 지적된 것처럼, 비동기 함수의 실행 결과와 에러를 제대로 처리하지 않고 있습니다.
다음과 같이 수정하는 것을 제안합니다:
-run(); +run().catch(error => { + console.error('치명적인 오류 발생:', error); + process.exit(1); +});
async function run() { | ||
try { | ||
const { octokit, context } = await getOctokitAndContext(); | ||
const { pull_request: pr, repository } = context.payload; | ||
|
||
if (!pr) throw new Error('This action only runs on pull request events.'); | ||
|
||
await octokit.rest.issues.addAssignees({ | ||
owner: repository.owner.login, | ||
repo: repository.name, | ||
issue_number: pr.number, | ||
assignees: [pr.user.login], | ||
}); | ||
|
||
console.log(`Successfully assigned ${pr.user.login} to PR #${pr.number}`); | ||
} catch (error) { | ||
console.error('Failed to assign PR creator:', error.message); | ||
process.exit(1); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
에러 처리와 API 제한 처리가 필요합니다.
- API 호출 실패에 대한 구체적인 에러 처리
- GitHub API 레이트 리밋 처리
- 네트워크 타임아웃 처리가 필요합니다.
다음과 같이 수정하는 것을 제안합니다:
async function run() {
try {
const { octokit, context } = await getOctokitAndContext();
const { pull_request: pr, repository } = context.payload;
if (!pr) throw new Error('This action only runs on pull request events.');
+ // API 레이트 리밋 확인
+ const { data: rateLimit } = await octokit.rest.rateLimit.get();
+ if (rateLimit.remaining === 0) {
+ throw new Error(`API 레이트 리밋에 도달했습니다. ${new Date(rateLimit.reset * 1000)} 이후에 다시 시도해주세요.`);
+ }
+ // 타임아웃 설정과 함께 API 호출
+ const timeoutPromise = new Promise((_, reject) =>
+ setTimeout(() => reject(new Error('API 요청 타임아웃')), 10000)
+ );
+ await Promise.race([
octokit.rest.issues.addAssignees({
owner: repository.owner.login,
repo: repository.name,
issue_number: pr.number,
assignees: [pr.user.login],
- });
+ }),
+ timeoutPromise
+ ]);
console.log(`Successfully assigned ${pr.user.login} to PR #${pr.number}`);
} catch (error) {
- console.error('Failed to assign PR creator:', error.message);
+ if (error.status === 403) {
+ console.error('권한이 없습니다. workflow 파일의 permissions 설정을 확인해주세요.');
+ } else if (error.status === 404) {
+ console.error('PR 또는 저장소를 찾을 수 없습니다.');
+ } else {
+ console.error('PR 생성자 할당 실패:', error.message);
+ }
process.exit(1);
}
}
📝 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.
async function run() { | |
try { | |
const { octokit, context } = await getOctokitAndContext(); | |
const { pull_request: pr, repository } = context.payload; | |
if (!pr) throw new Error('This action only runs on pull request events.'); | |
await octokit.rest.issues.addAssignees({ | |
owner: repository.owner.login, | |
repo: repository.name, | |
issue_number: pr.number, | |
assignees: [pr.user.login], | |
}); | |
console.log(`Successfully assigned ${pr.user.login} to PR #${pr.number}`); | |
} catch (error) { | |
console.error('Failed to assign PR creator:', error.message); | |
process.exit(1); | |
} | |
} | |
async function run() { | |
try { | |
const { octokit, context } = await getOctokitAndContext(); | |
const { pull_request: pr, repository } = context.payload; | |
if (!pr) throw new Error('This action only runs on pull request events.'); | |
// API 레이트 리밋 확인 | |
const { data: rateLimit } = await octokit.rest.rateLimit.get(); | |
if (rateLimit.remaining === 0) { | |
throw new Error(`API 레이트 리밋에 도달했습니다. ${new Date(rateLimit.reset * 1000)} 이후에 다시 시도해주세요.`); | |
} | |
// 타임아웃 설정과 함께 API 호출 | |
const timeoutPromise = new Promise((_, reject) => | |
setTimeout(() => reject(new Error('API 요청 타임아웃')), 10000) | |
); | |
await Promise.race([ | |
octokit.rest.issues.addAssignees({ | |
owner: repository.owner.login, | |
repo: repository.name, | |
issue_number: pr.number, | |
assignees: [pr.user.login], | |
}), | |
timeoutPromise | |
]); | |
console.log(`Successfully assigned ${pr.user.login} to PR #${pr.number}`); | |
} catch (error) { | |
if (error.status === 403) { | |
console.error('권한이 없습니다. workflow 파일의 permissions 설정을 확인해주세요.'); | |
} else if (error.status === 404) { | |
console.error('PR 또는 저장소를 찾을 수 없습니다.'); | |
} else { | |
console.error('PR 생성자 할당 실패:', error.message); | |
} | |
process.exit(1); | |
} | |
} |
.github/workflows/auto_assign.yaml
Outdated
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거 indent가 잘못들어간거 같은데?
가끔 이런 syntax에러는 나같은 경우는
- https://github.com/redhat-developer/vscode-yaml/issues
- https://marketplace.cursorapi.com/items?itemName=GitHub.vscode-github-actions
익스텐션 설치해서 사용하는데, 알아보긴하는데 .vscode extensions.json에 추가하는게 좋을까 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extension recommendations에 github-action 추가했어!! 고마워~!!
/* eslint-disable @typescript-eslint/no-require-imports */ | ||
const github = require('@actions/github'); | ||
|
||
async function getOctokitAndContext() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런식으로 만들어서 쓰는거 처음알아따..
.github/workflows/auto_assign.yaml
Outdated
- name: Install dependencies for auto-assign | ||
run: | | ||
cd .github/workflows/auto-assign | ||
npm ci |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pnpm ci 로 해야하는거 아닌가 ~ ?
pnpm install --frozen-lockfile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요것도 추가했어!! 고마웡~!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Changes
This PR introduces a GitHub Actions workflow (
auto_assign.yaml
) to automatically assign the PR creator as the assignee when a pull request is opened. It uses theactions/github-script
to interact with GitHub's REST API.Visuals
No visuals are included, as this is a backend configuration update.
Checklist
Additional Discussion Points
Summary by CodeRabbit
auto_assign.js
파일에서 PR 작성자를 자동으로 할당하는 기능을 구현했습니다.auto-assign
프로젝트를 위한package.json
파일을 추가했습니다."github.vscode-github-actions"
를 추가했습니다.