Skip to content

Commit 55805c4

Browse files
committed
feat: 컨텐츠 자동 채움 action 추가
1 parent a6b78cd commit 55805c4

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

.github/workflows/auto-pr-fill.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Auto Fill PR from Weekly Issue
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited]
6+
7+
jobs:
8+
fill-pr-info:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
issues: read
12+
pull-requests: write
13+
contents: read
14+
15+
steps:
16+
- name: Extract info and Update PR
17+
uses: actions/github-script@v7
18+
with:
19+
script: |
20+
const pr = context.payload.pull_request;
21+
const title = pr.title; // 예: [Week15] PGS 42627: 디스크컨트롤러
22+
23+
// 1. PR 제목에서 정보 추출 (정규표현식)
24+
const weekMatch = title.match(/Week\s*(\d+)/i);
25+
const probNumMatch = title.match(/\d{4,}/); // 4자리 이상의 숫자(문제번호)
26+
27+
if (!weekMatch || !probNumMatch) {
28+
console.log("제목 형식에서 주차(Week) 또는 문제번호를 찾을 수 없습니다.");
29+
return;
30+
}
31+
32+
const targetWeek = `Week ${weekMatch[1]}`; // "Week 15"
33+
const targetProbNum = probNumMatch[0]; // "42627"
34+
35+
// 2. 해당 주차의 이슈 찾기 (최근 생성된 이슈 중 제목에 'Week 15'가 포함된 것)
36+
const issues = await github.rest.issues.listForRepo({
37+
owner: context.repo.owner,
38+
repo: context.repo.repo,
39+
state: 'open'
40+
});
41+
42+
const targetIssue = issues.data.find(issue => issue.title.includes(targetWeek));
43+
44+
if (!targetIssue) {
45+
console.log(`${targetWeek}에 해당하는 이슈를 찾지 못했습니다.`);
46+
return;
47+
}
48+
49+
// 3. 이슈 본문 파싱 및 문제 매칭
50+
const issueBody = targetIssue.body;
51+
// "문제 1", "문제 2" 혹은 빈 줄 기준으로 섹션 나누기
52+
const sections = issueBody.split(/문제 \d/);
53+
const targetSection = sections.find(s => s.includes(targetProbNum));
54+
55+
if (!targetSection) {
56+
console.log(`이슈 내에서 문제 번호 ${targetProbNum}를 찾을 수 없습니다.`);
57+
return;
58+
}
59+
60+
// 4. 정보 추출 (정규표현식)
61+
const platform = targetSection.match(/플랫폼:\s*(.+)/)?.[1]?.trim() || "정보 없음";
62+
const probName = targetSection.match(/문제 이름:\s*(.+)/)?.[1]?.trim() || "정보 없음";
63+
const probLink = targetSection.match(/링크:\s*(https?:\/\/[^\s]+)/)?.[1]?.trim() || "정보 없음";
64+
const difficulty = targetSection.match(/난이도:\s*(.+)/)?.[1]?.trim() || "정보 없음";
65+
66+
// 5. PR 본문 업데이트 (기존 내용이 이미 업데이트 되었는지 확인)
67+
const infoHeader = "## 📝 문제 정보";
68+
if (pr.body && pr.body.includes(infoHeader)) {
69+
console.log("이미 정보가 포함되어 있어 업데이트를 건너뜁니다.");
70+
return;
71+
}
72+
73+
const newBody = `
74+
${infoHeader}
75+
- **플랫폼**: ${platform}
76+
- **문제 번호**: ${targetProbNum}
77+
- **문제 이름**: ${probName}
78+
- **문제 링크**: [바로가기](${probLink})
79+
- **난이도**: ${difficulty}
80+
81+
---
82+
${pr.body || "작성된 내용이 없습니다."}
83+
`.replace(/^ +/gm, '');
84+
85+
await github.rest.pulls.update({
86+
owner: context.repo.owner,
87+
repo: context.repo.repo,
88+
pull_number: pr.number,
89+
body: newBody
90+
});
91+
92+
// 6. 라벨 자동 추가 (보너스)
93+
const labels = [];
94+
if (platform.includes("프로그래머스") || title.includes("PGS")) labels.push("프로그래머스");
95+
if (platform.includes("백준") || title.includes("BOJ")) labels.push("백준");
96+
labels.push("weekly-challenge");
97+
98+
await github.rest.issues.addLabels({
99+
owner: context.repo.owner,
100+
repo: context.repo.repo,
101+
issue_number: pr.number,
102+
labels: labels
103+
});

0 commit comments

Comments
 (0)