diff --git a/AGENTS.md b/AGENTS.md index 9bb0897..9b4b6d1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -29,14 +29,14 @@ wrangler.jsonc Worker 설정과 공개 값(vars) ## 엔드포인트 -`repo_owner` 를 받는 엔드포인트는 `DaleStudy` 가 아니면 403 이다 (생략하면 `DaleStudy`). `/check-weeks` 는 저장소도 leetcode-study 만 받는다. +`repo_owner` 를 받는 엔드포인트는 `DaleStudy` 가 아니면 403 이다. 일괄 승인·병합 요청에는 `repo_owner`가 필수다. `/check-weeks` 는 생략하면 `DaleStudy`를 사용하며 저장소도 leetcode-study 만 받는다. | 경로 | 하는 일 | | ------------------------- | --------------------------------------------------------------------------------------------------------------- | | `POST /webhooks` | GitHub App 웹훅 수신 (아래 "웹훅") | | `POST /check-weeks` | 열린 PR 전체의 Week 설정을 검사해 경고 댓글을 달거나 지운다. `{ "repo_name" }` | -| `POST /approve-prs` | 해당 주차 풀이 PR 을 일괄 승인한다. `{ "repo_name", "week": "Week 8", "excludes"? }` | -| `POST /merge-prs` | 해당 주차의 승인된 PR 을 일괄 병합한다. `{ "repo_name", "week", "excludes"?, "merge_method"? }` (기본 `squash`) | +| `POST /approve-prs` | 해당 주차 풀이 PR 을 일괄 승인한다. `{ "repo_owner", "repo_name", "week": "Week 8", "excludes"? }` | +| `POST /merge-prs` | 해당 주차의 승인된 PR 을 일괄 병합한다. `{ "repo_owner", "repo_name", "week", "excludes"?, "merge_method"? }` (기본 `squash`) | | `POST /resolve-iteration` | 날짜가 몇 기 몇 주차인지 프로젝트 보드에서 읽는다. `{ "date": "2026-08-08" }` | | `POST /internal/*` | 웹훅 핸들러가 AI 작업을 별도 invocation 으로 넘길 때 쓴다 (`X-Internal-Secret` 인증) | diff --git a/test-migration.sh b/test-migration.sh index 4cae1c7..89b3a82 100755 --- a/test-migration.sh +++ b/test-migration.sh @@ -110,7 +110,7 @@ fi # 1.6 approve-prs week 누락 (400) BODY=$(curl -s -w '\n%{http_code}' -X POST "$BASE_URL/approve-prs" \ -H "Content-Type: application/json" \ - -d '{"repo_name":"leetcode-study"}' --max-time 30 2>/dev/null) + -d '{"repo_owner":"DaleStudy","repo_name":"leetcode-study"}' --max-time 30 2>/dev/null) STATUS=$(echo "$BODY" | tail -1) BODY_CONTENT=$(echo "$BODY" | sed '$d') if [ "$STATUS" = "400" ] && echo "$BODY_CONTENT" | grep -q "week"; then @@ -122,7 +122,7 @@ fi # 1.7 merge-prs week 누락 (400) BODY=$(curl -s -w '\n%{http_code}' -X POST "$BASE_URL/merge-prs" \ -H "Content-Type: application/json" \ - -d '{"repo_name":"leetcode-study"}' --max-time 30 2>/dev/null) + -d '{"repo_owner":"DaleStudy","repo_name":"leetcode-study"}' --max-time 30 2>/dev/null) STATUS=$(echo "$BODY" | tail -1) BODY_CONTENT=$(echo "$BODY" | sed '$d') if [ "$STATUS" = "400" ] && echo "$BODY_CONTENT" | grep -q "week"; then @@ -134,7 +134,7 @@ fi # 1.8 경로 별칭 (underscore) BODY=$(curl -s -w '\n%{http_code}' -X POST "$BASE_URL/approve_prs" \ -H "Content-Type: application/json" \ - -d '{"repo_name":"leetcode-study"}' --max-time 30 2>/dev/null) + -d '{"repo_owner":"DaleStudy","repo_name":"leetcode-study"}' --max-time 30 2>/dev/null) STATUS=$(echo "$BODY" | tail -1) if [ "$STATUS" = "400" ]; then pass "1.8 /approve_prs 경로 별칭 라우팅" @@ -289,13 +289,13 @@ echo "" echo -e " ${YELLOW}[approve-prs]${NC} PR 일괄 승인 (Week 번호를 실제 값으로 변경)" echo " curl -X POST $BASE_URL/approve-prs \\" echo " -H 'Content-Type: application/json' \\" -echo " -d '{\"repo_name\":\"leetcode-study\",\"week\":\"Week 14\"}'" +echo " -d '{\"repo_owner\":\"<저장소 소유자>\",\"repo_name\":\"leetcode-study\",\"week\":\"Week 14\"}'" echo "" echo -e " ${YELLOW}[merge-prs]${NC} PR 일괄 병합" echo " curl -X POST $BASE_URL/merge-prs \\" echo " -H 'Content-Type: application/json' \\" -echo " -d '{\"repo_name\":\"leetcode-study\",\"week\":\"Week 14\",\"merge_method\":\"squash\"}'" +echo " -d '{\"repo_owner\":\"<저장소 소유자>\",\"repo_name\":\"leetcode-study\",\"week\":\"Week 14\",\"merge_method\":\"squash\"}'" echo "" echo -e " ${YELLOW}[Webhook]${NC} 실제 이벤트로 검증" diff --git a/utils/prActions.js b/utils/prActions.js index 50f1df5..076d049 100644 --- a/utils/prActions.js +++ b/utils/prActions.js @@ -16,10 +16,17 @@ const PASSING_CHECK_STATE = "SUCCESS"; export async function parsePrActionPayload(request) { try { const data = await request.json(); - const repoOwner = data.repo_owner || "DaleStudy"; + const repoOwner = data.repo_owner; const repoName = data.repo_name; const week = data.week; + if (!repoOwner) { + return { + valid: false, + response: errorResponse("Missing required field: repo_owner", 400), + }; + } + if (!repoName) { return { valid: false, diff --git a/utils/prActions.test.js b/utils/prActions.test.js index df84379..0634c21 100644 --- a/utils/prActions.test.js +++ b/utils/prActions.test.js @@ -1,6 +1,6 @@ import { describe, it, expect } from "vitest"; -import { getCheckSkipReason } from "./prActions.js"; +import { getCheckSkipReason, parsePrActionPayload } from "./prActions.js"; describe("getCheckSkipReason", () => { it("모든 체크가 통과하면 승인을 막지 않는다", () => { @@ -18,3 +18,24 @@ describe("getCheckSkipReason", () => { expect(getCheckSkipReason({})).toBe("checks missing"); }); }); + +describe("parsePrActionPayload", () => { + it.each([ + [undefined, 400], + ["fork-owner", 403], + ["DaleStudy", null], + ])("repo_owner=%s", async (owner, expectedError) => { + const request = new Request("https://example.com", { + method: "POST", + body: JSON.stringify({ repo_owner: owner, repo_name: "leetcode-study", week: "Week 2" }), + }); + const result = await parsePrActionPayload(request); + if (expectedError) { + expect(result.valid).toBe(false); + expect(result.response.status).toBe(expectedError); + } else { + expect(result.valid).toBe(true); + expect(result.data.repoOwner).toBe(owner); + } + }); +});