Skip to content
Open
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
6 changes: 3 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` 인증) |

Expand Down
10 changes: 5 additions & 5 deletions test-migration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 경로 별칭 라우팅"
Expand Down Expand Up @@ -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} 실제 이벤트로 검증"
Expand Down
9 changes: 8 additions & 1 deletion utils/prActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

요청 본문을 신뢰하는 대신 GitHub Actions OIDC 토큰을 검증하고, 토큰의 repository_owner 클레임으로 소유자를 확인하는 건 어떨까요?

Suggested change
const repoOwner = data.repo_owner;
const repoOwner = claims.repository_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,
Expand Down
23 changes: 22 additions & 1 deletion utils/prActions.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect } from "vitest";

import { getCheckSkipReason } from "./prActions.js";
import { getCheckSkipReason, parsePrActionPayload } from "./prActions.js";

describe("getCheckSkipReason", () => {
it("모든 체크가 통과하면 승인을 막지 않는다", () => {
Expand All @@ -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);
}
});
});