Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ fine-grained PAT는 GitHub `Settings` > `Developer settings` > `Personal access
| --- | --- |
| Repository access | 감시 대상 repository만 선택 |
| Contents | Read-only |
| Checks | Read-only |
| Pull requests | Read-only |
| Metadata | Read-only. GitHub가 자동 포함 |

`Contents: Read-only`는 checkout과 branch fetch에 필요합니다. `Checks: Read-only`는 branch head SHA의 check run 조회에 필요합니다. `Pull requests: Read-only`는 commit에 연결된 PR metadata 조회에 필요합니다.
`Contents: Read-only`는 checkout과 branch fetch에 필요합니다. `Pull requests: Read-only`는 commit에 연결된 PR metadata 조회에 필요합니다.

### Consumer workflow permissions

Expand Down Expand Up @@ -251,7 +250,7 @@ scheduled run은 consumer repository의 실제 remote branch를 fetch하고, `ba
| workflow가 시작되지 않음 | consumer workflow가 `schedule`, `workflow_dispatch` 중 필요한 trigger를 가지고 있는지 확인 |
| checkout 또는 fetch 실패 | `WATCHER_GITHUB_TOKEN`의 Repository access, `Contents: Read-only`, workflow `contents: read` 확인 |
| PR metadata가 비어 있음 | `WATCHER_GITHUB_TOKEN`의 `Pull requests: Read-only`, commit에 연결된 PR 존재 여부 확인 |
| check metadata가 비어 있음 | `WATCHER_GITHUB_TOKEN`의 `Checks: Read-only`, 해당 branch head SHA의 check run 존재 여부 확인 |
| check metadata가 비어 있음 | 해당 branch head SHA의 check run 존재 여부 확인 |
| AI prediction이 `skipped`로 표시됨 | deterministic possibility status가 `critical`인지와 `confirmed_conflict`가 아닌지 확인 |
| AI prediction이 `failed`로 표시됨 | `OPENAI_API_KEY` secret, OpenAI API 응답 형식, rate limit 상태 확인 |
| Discord 전송이 되지 않음 | `DISCORD_WEBHOOK_URL` secret, Discord incoming webhook URL, webhook channel 권한 확인 |
Expand Down
41 changes: 25 additions & 16 deletions src/workflows/mergeRiskWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,23 +279,28 @@ export function githubMetadataClientFor(options: MergeRiskWatchOptions): {

return {
checksFor: async ref => {
const response = await githubJson<GitHubCheckRunsResponse>(options, [
"repos",
owner,
repo,
"commits",
ref,
"check-runs"
], {
per_page: "100"
})
try {
const response = await githubJson<GitHubCheckRunsResponse>(options, [
"repos",
owner,
repo,
"commits",
ref,
"check-runs"
], {
per_page: "100"
})

return (response.check_runs ?? [])
.map(check => ({
name: check.name ?? "unknown",
status: check.status ?? "unknown",
conclusion: check.conclusion ?? undefined
}))
return (response.check_runs ?? [])
.map(check => ({
name: check.name ?? "unknown",
status: check.status ?? "unknown",
conclusion: check.conclusion ?? undefined
}))
} catch (error) {
console.warn(`GitHub check metadata request failed: ${warningMessageFor(error)}`)
return []
}
},
pullRequestFor: async (sha, branchName) => {
const pulls = await githubJson<GitHubPullRequestResponse[]>(options, [
Expand All @@ -322,6 +327,10 @@ export function githubMetadataClientFor(options: MergeRiskWatchOptions): {
}
}

function warningMessageFor(error: unknown): string {
return error instanceof Error ? error.message : String(error)
}

// git diff hunk header를 BranchChangedHunk 목록으로 변환
async function collectChangedHunks(input: {
repositoryPath: string
Expand Down
29 changes: 29 additions & 0 deletions tests/workflows/mergeRiskWatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,23 @@ test("collects check metadata from GitHub check runs API", async () => {
}])
})

// check run metadata 조회 실패가 branch 수집 실패로 전파되지 않는지 확인
test("returns empty check metadata when GitHub check runs request fails", async () => {
const client = githubMetadataClientFor({
...baseOptions(),
fetch: async () => new Response("{}", {
status: 403,
headers: {
"Content-Type": "application/json"
}
})
})

const checks = await suppressConsoleWarn(() => client.checksFor("abc123"))

assert.deepEqual(checks, [])
})

// commit에 연결된 PR 목록에서 branch와 맞는 Pull Request metadata를 선택하는지 확인
test("collects pull request metadata for matching branch", async () => {
const client = githubMetadataClientFor({
Expand Down Expand Up @@ -347,6 +364,18 @@ function restoreEnv(name: string, value: string | undefined): void {
process.env[name] = value
}

async function suppressConsoleWarn<T>(operation: () => Promise<T>): Promise<T> {
const originalWarn = console.warn

console.warn = () => {}

try {
return await operation()
} finally {
console.warn = originalWarn
}
}

async function git(cwd: string, args: string[]): Promise<string> {
const result = await execFileAsync("git", args, {
cwd,
Expand Down
Loading