-
Notifications
You must be signed in to change notification settings - Fork 0
[CI] PR 리뷰어 리마인드 Discord 알림 자동화 #286
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
Open
kimminna
wants to merge
4
commits into
develop
Choose a base branch
from
ci/root/285-discord-reviewer-reminder
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+161
−1
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
355b7d1
feat(root): PR 리뷰어 리마인드 Discord 알림 자동화 (#285)
kimminna 5f199ee
fix(root): 리마인더 대상 PR 전체 조회 및 리뷰 요청 시각 기준으로 임계값 계산 (#285)
kimminna 2698d8d
fix(root): 라벨 제거 실패 시 예상된 에러만 무시하도록 수정 (#285)
kimminna a8254cd
fix(root): 리마인더 워크플로 동시 실행 방지 및 팀 리뷰어·오류 처리 보강 (#285)
kimminna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| name: ⏰ Discord Reviewer Reminder | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '0 1,6 * * 1-5' # 평일 KST 10:00, 15:00 | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| remind: | ||
| permissions: | ||
| pull-requests: write | ||
| issues: write | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Remind pending reviewers | ||
| uses: actions/github-script@v7 | ||
| env: | ||
| DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_REMINDER_WEBHOOK_URL }} | ||
| with: | ||
| script: | | ||
| const REMINDER_THRESHOLD_HOURS = 24; | ||
| const REMINDED_LABEL = '🫵🏻 Reminded'; | ||
|
|
||
| const NAME_MAP = { | ||
| kimminna: '민아', | ||
| ehye1: '혜원', | ||
| jjangminii: '정민', | ||
| 'yumin-kim2': '유민', | ||
| }; | ||
| const resolveName = (login) => NAME_MAP[login] || login; | ||
|
|
||
| const webhookUrl = process.env.DISCORD_WEBHOOK_URL; | ||
| if (!webhookUrl) { | ||
| console.log('DISCORD_REMINDER_WEBHOOK_URL not set, skipping'); | ||
| return; | ||
| } | ||
|
|
||
| const pulls = await github.paginate(github.rest.pulls.list, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| state: 'open', | ||
| per_page: 100, | ||
| }); | ||
|
|
||
| const now = Date.now(); | ||
| const failedPrs = []; | ||
|
|
||
| for (const pr of pulls) { | ||
| if (pr.draft) continue; | ||
|
|
||
| const labels = pr.labels.map((label) => label.name); | ||
| if (labels.includes(REMINDED_LABEL)) continue; | ||
|
|
||
| const reviewers = pr.requested_reviewers ?? []; | ||
| const teams = pr.requested_teams ?? []; | ||
| if (reviewers.length === 0 && teams.length === 0) continue; | ||
|
|
||
| const timelineEvents = await github.paginate(github.rest.issues.listEventsForTimeline, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: pr.number, | ||
| per_page: 100, | ||
| }); | ||
|
|
||
| const reviewRequestTimes = new Map(); | ||
| for (const event of timelineEvents) { | ||
| if (event.event !== 'review_requested') continue; | ||
| const login = event.requested_reviewer?.login; | ||
| if (login) { | ||
| reviewRequestTimes.set(`user:${login}`, event.created_at); | ||
| continue; | ||
| } | ||
| const teamSlug = event.requested_team?.slug; | ||
| if (teamSlug) { | ||
| reviewRequestTimes.set(`team:${teamSlug}`, event.created_at); | ||
| } | ||
| } | ||
|
|
||
| const requestTimestamps = [ | ||
| ...reviewers.map((reviewer) => reviewRequestTimes.get(`user:${reviewer.login}`)), | ||
| ...teams.map((team) => reviewRequestTimes.get(`team:${team.slug}`)), | ||
| ] | ||
| .filter(Boolean) | ||
| .map((timestamp) => new Date(timestamp).getTime()); | ||
|
|
||
| const oldestRequestTime = | ||
| requestTimestamps.length > 0 ? Math.min(...requestTimestamps) : new Date(pr.created_at).getTime(); | ||
|
|
||
| const hoursOpen = (now - oldestRequestTime) / (1000 * 60 * 60); | ||
| if (hoursOpen < REMINDER_THRESHOLD_HOURS) continue; | ||
|
|
||
| const reviewerNames = [ | ||
| ...reviewers.map((reviewer) => resolveName(reviewer.login)), | ||
| ...teams.map((team) => team.name || team.slug), | ||
| ].join(', '); | ||
|
|
||
| const payload = { | ||
| embeds: [ | ||
| { | ||
| title: '⏰ 리뷰 리마인드', | ||
| url: pr.html_url, | ||
| description: `**${pr.title}**\n리뷰 요청 후 ${Math.floor(hoursOpen)}시간째 대기 중이에요.`, | ||
| color: 16776960, | ||
| fields: [{ name: '리뷰어', value: reviewerNames, inline: true }], | ||
| footer: { text: 'GitHub Actions' }, | ||
| timestamp: new Date().toISOString(), | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| try { | ||
| const response = await fetch(webhookUrl, { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify(payload), | ||
| signal: AbortSignal.timeout(10000), | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| console.error(`Discord webhook failed for PR #${pr.number}: ${response.status}`); | ||
| failedPrs.push(pr.number); | ||
| continue; | ||
| } | ||
|
|
||
| await github.rest.issues.addLabels({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: pr.number, | ||
| labels: [REMINDED_LABEL], | ||
| }); | ||
| } catch (error) { | ||
| console.error(`Failed to process PR #${pr.number}: ${error.message}`); | ||
| failedPrs.push(pr.number); | ||
| } | ||
| } | ||
|
|
||
| if (failedPrs.length > 0) { | ||
| console.error(`Failed to fully process PRs: ${failedPrs.join(', ')}`); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.