Skip to content

Commit 0eb9b4d

Browse files
committed
fix: pr 내용 안채워지는 오류 수정
1 parent 55805c4 commit 0eb9b4d

File tree

1 file changed

+45
-53
lines changed

1 file changed

+45
-53
lines changed

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

Lines changed: 45 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -18,86 +18,78 @@ jobs:
1818
with:
1919
script: |
2020
const pr = context.payload.pull_request;
21-
const title = pr.title; // 예: [Week15] PGS 42627: 디스크컨트롤러
21+
const title = pr.title;
22+
let body = pr.body || "";
2223
23-
// 1. PR 제목에서 정보 추출 (정규표현식)
24+
// 1. 제목에서 주차와 문제번호 추출
2425
const weekMatch = title.match(/Week\s*(\d+)/i);
25-
const probNumMatch = title.match(/\d{4,}/); // 4자리 이상의 숫자(문제번호)
26+
const probNumMatch = title.match(/\d{4,}/);
2627
2728
if (!weekMatch || !probNumMatch) {
28-
console.log("제목 형식에서 주차(Week) 또는 문제번호를 찾을 수 없습니다.");
29+
console.log("주차(Week) 또는 문제번호를 제목에서 찾을 수 없습니다.");
2930
return;
3031
}
3132
32-
const targetWeek = `Week ${weekMatch[1]}`; // "Week 15"
33-
const targetProbNum = probNumMatch[0]; // "42627"
33+
const targetWeek = `Week ${weekMatch[1]}`;
34+
const targetProbNum = probNumMatch[0];
3435
35-
// 2. 해당 주차의 이슈 찾기 (최근 생성된 이슈 중 제목에 'Week 15'가 포함된 것)
36+
// 2. 해당 주차 이슈 찾기
3637
const issues = await github.rest.issues.listForRepo({
3738
owner: context.repo.owner,
3839
repo: context.repo.repo,
3940
state: 'open'
4041
});
4142
4243
const targetIssue = issues.data.find(issue => issue.title.includes(targetWeek));
43-
4444
if (!targetIssue) {
45-
console.log(`${targetWeek}에 해당하는 이슈를 찾지 못했습니다.`);
45+
console.log(`${targetWeek} 이슈를 찾지 못했습니다.`);
4646
return;
4747
}
4848
49-
// 3. 이슈 본문 파싱 및 문제 매칭
50-
const issueBody = targetIssue.body;
51-
// "문제 1", "문제 2" 혹은 빈 줄 기준으로 섹션 나누기
52-
const sections = issueBody.split(/문제 \d/);
49+
// 3. 이슈에서 문제 섹션 추출
50+
const sections = targetIssue.body.split(/문제 \d/);
5351
const targetSection = sections.find(s => s.includes(targetProbNum));
5452
5553
if (!targetSection) {
56-
console.log(`이슈 내에서 문제 번호 ${targetProbNum}를 찾을 수 없습니다.`);
54+
console.log(`이슈 내에서 ${targetProbNum}번 정보를 찾지 못했습니다.`);
5755
return;
5856
}
5957
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;
58+
// 4. 정보 추출
59+
const platform = targetSection.match(/플랫폼:\s*(.+)/)?.[1]?.trim() || "";
60+
const probName = targetSection.match(/문제 이름:\s*(.+)/)?.[1]?.trim() || "";
61+
const probLink = targetSection.match(/링크:\s*(https?:\/\/[^\s]+)/)?.[1]?.trim() || "";
62+
const difficulty = targetSection.match(/난이도:\s*(.+)/)?.[1]?.trim() || "";
63+
64+
// 5. PR 템플릿의 빈 칸 채우기 (정규표현식 치환)
65+
// 템플릿에 있는 기본 문구들을 이슈에서 가져온 실제 데이터로 교체합니다.
66+
let newBody = body
67+
.replace(/- \*\*플랫폼\*\*:\s*.*$/m, `- **플랫폼**: ${platform}`)
68+
.replace(/- \*\*문제 번호\*\*:\s*.*$/m, `- **문제 번호**: ${targetProbNum}`)
69+
.replace(/- \*\*문제 이름\*\*:\s*.*$/m, `- **문제 이름**: ${probName}`)
70+
.replace(/- \*\*문제 링크\*\*:\s*.*$/m, `- **문제 링크**: ${probLink}`)
71+
.replace(/- \*\*난이도\*\*:\s*.*$/m, `- **난이도**: ${difficulty}`);
72+
73+
// 6. 변경사항이 있을 때만 업데이트
74+
if (newBody !== body) {
75+
await github.rest.pulls.update({
76+
owner: context.repo.owner,
77+
repo: context.repo.repo,
78+
pull_number: pr.number,
79+
body: newBody
80+
});
81+
console.log("PR 본문이 성공적으로 업데이트되었습니다.");
7182
}
7283
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. 라벨 자동 추가 (보너스)
84+
// 7. 라벨 추가
9385
const labels = [];
9486
if (platform.includes("프로그래머스") || title.includes("PGS")) labels.push("프로그래머스");
9587
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-
});
88+
if (labels.length > 0) {
89+
await github.rest.issues.addLabels({
90+
owner: context.repo.owner,
91+
repo: context.repo.repo,
92+
issue_number: pr.number,
93+
labels: labels
94+
});
95+
}

0 commit comments

Comments
 (0)