Skip to content

Commit 3f4e88a

Browse files
Merge pull request #31 from NaverPayDev/feature/fork-guide
feat(detect-add): Fork PR에 대한 changeset 가이드 기능 추가
2 parents b0c366a + b2af4fc commit 3f4e88a

3 files changed

Lines changed: 144 additions & 2 deletions

File tree

detect-add/action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,10 @@ inputs:
3030
description: 'language to use for the changeset'
3131
required: false
3232
default: 'en'
33+
fork_guide_enabled:
34+
description: 'enable guide comment for fork PRs (fork PRs cannot use auto-detect due to token permissions)'
35+
required: false
36+
default: 'false'
37+
fork_guide_message:
38+
description: 'custom guide message for fork PRs (optional, uses default bilingual message if not provided)'
39+
required: false

detect-add/dist/index.js

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57338,7 +57338,7 @@ const file_1 = __nccwpck_require__(398);
5733857338
const get_release_plan_1 = __nccwpck_require__(6240);
5733957339
function main() {
5734057340
return __awaiter(this, void 0, void 0, function* () {
57341-
var _a, _b, _c, _d;
57341+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
5734257342
const context = github.context;
5734357343
const { pull_request } = context.payload;
5734457344
if (!pull_request) {
@@ -57382,11 +57382,74 @@ function main() {
5738257382
: `The base branch is ${pull_request.base.ref}, or the head branch is ${(_c = pull_request === null || pull_request === void 0 ? void 0 : pull_request.head) === null || _c === void 0 ? void 0 : _c.ref}, so detectAdd is skipped.`);
5738357383
return;
5738457384
}
57385+
// Fork PR 감지 및 가이드 코멘트 처리
57386+
const forkGuideEnabled = core.getInput('fork_guide_enabled') === 'true';
57387+
const isForkPR = ((_e = (_d = pull_request.head) === null || _d === void 0 ? void 0 : _d.repo) === null || _e === void 0 ? void 0 : _e.fork) === true || ((_g = (_f = pull_request.head) === null || _f === void 0 ? void 0 : _f.repo) === null || _g === void 0 ? void 0 : _g.full_name) !== `${owner}/${repo}`;
57388+
if (isForkPR) {
57389+
core.info(isKoreanLanguage
57390+
? `Fork PR이 감지되었습니다. (${(_j = (_h = pull_request.head) === null || _h === void 0 ? void 0 : _h.repo) === null || _j === void 0 ? void 0 : _j.full_name})`
57391+
: `Fork PR detected. (${(_l = (_k = pull_request.head) === null || _k === void 0 ? void 0 : _k.repo) === null || _l === void 0 ? void 0 : _l.full_name})`);
57392+
if (forkGuideEnabled) {
57393+
const customMessage = core.getInput('fork_guide_message');
57394+
const defaultMessage = `## Changeset Guide for External Contributors
57395+
57396+
**한국어** | [English](#english)
57397+
57398+
### 한국어
57399+
57400+
외부 기여자분께 감사드립니다! 🎉
57401+
57402+
패키지에 변경사항이 있는 경우, changeset 파일을 수동으로 생성해주세요.
57403+
57404+
\`\`\`bash
57405+
pnpm changeset
57406+
\`\`\`
57407+
57408+
위 명령어를 실행하면 변경된 패키지와 버전 타입(patch/minor/major)을 선택하고, 변경 내용을 입력할 수 있습니다.
57409+
57410+
생성된 \`.changeset/*.md\` 파일을 커밋에 포함해주세요.
57411+
57412+
> **참고**: \`${skipLabel}\` 레이블이 있으면 changeset이 필요하지 않습니다.
57413+
57414+
---
57415+
57416+
<a name="english"></a>
57417+
### English
57418+
57419+
Thank you for your contribution! 🎉
57420+
57421+
If your PR includes package changes, please create a changeset file manually.
57422+
57423+
\`\`\`bash
57424+
pnpm changeset
57425+
\`\`\`
57426+
57427+
This command will guide you to select the changed packages, version type (patch/minor/major), and enter a description.
57428+
57429+
Please include the generated \`.changeset/*.md\` file in your commit.
57430+
57431+
> **Note**: If the \`${skipLabel}\` label is present, changeset is not required.
57432+
57433+
<!-- ${constants_1.CHANGESET_DETECT_ADD_ACTIONS_CHECKSUM} -->`;
57434+
const guideMessage = customMessage || defaultMessage;
57435+
const guideComment = Object.assign(Object.assign({}, commonParams), { body: guideMessage });
57436+
if (prevComment !== undefined) {
57437+
yield octokit.rest.issues.updateComment(Object.assign(Object.assign({}, guideComment), { comment_id: prevComment.id }));
57438+
}
57439+
else {
57440+
yield octokit.rest.issues.createComment(guideComment);
57441+
}
57442+
core.info(isKoreanLanguage
57443+
? `Fork PR에 changeset 가이드 코멘트를 추가했습니다.`
57444+
: `Added changeset guide comment for fork PR.`);
57445+
}
57446+
return;
57447+
}
5738557448
/**
5738657449
* 변경된 파일 이름을 가져오기위한 api
5738757450
*/
5738857451
const packages_dir = core.getInput('packages_dir');
57389-
const excludes = (_d = core.getInput('excludes')) !== null && _d !== void 0 ? _d : '';
57452+
const excludes = (_m = core.getInput('excludes')) !== null && _m !== void 0 ? _m : '';
5739057453
if (typeof packages_dir !== 'string') {
5739157454
throw new Error(isKoreanLanguage
5739257455
? `해당 action에 주입된 packages_dir parameter가 잘못되었습니다. (string, string1)의 형식으로 작성해주세요.`

detect-add/src/index.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,78 @@ async function main() {
7676
return
7777
}
7878

79+
// Fork PR 감지 및 가이드 코멘트 처리
80+
const forkGuideEnabled = core.getInput('fork_guide_enabled') === 'true'
81+
const isForkPR = pull_request.head?.repo?.fork === true || pull_request.head?.repo?.full_name !== `${owner}/${repo}`
82+
83+
if (isForkPR) {
84+
core.info(
85+
isKoreanLanguage
86+
? `Fork PR이 감지되었습니다. (${pull_request.head?.repo?.full_name})`
87+
: `Fork PR detected. (${pull_request.head?.repo?.full_name})`,
88+
)
89+
90+
if (forkGuideEnabled) {
91+
const customMessage = core.getInput('fork_guide_message')
92+
const defaultMessage = `## Changeset Guide for External Contributors
93+
94+
**한국어** | [English](#english)
95+
96+
### 한국어
97+
98+
외부 기여자분께 감사드립니다! 🎉
99+
100+
패키지에 변경사항이 있는 경우, changeset 파일을 수동으로 생성해주세요.
101+
102+
\`\`\`bash
103+
pnpm changeset
104+
\`\`\`
105+
106+
위 명령어를 실행하면 변경된 패키지와 버전 타입(patch/minor/major)을 선택하고, 변경 내용을 입력할 수 있습니다.
107+
108+
생성된 \`.changeset/*.md\` 파일을 커밋에 포함해주세요.
109+
110+
> **참고**: \`${skipLabel}\` 레이블이 있으면 changeset이 필요하지 않습니다.
111+
112+
---
113+
114+
<a name="english"></a>
115+
### English
116+
117+
Thank you for your contribution! 🎉
118+
119+
If your PR includes package changes, please create a changeset file manually.
120+
121+
\`\`\`bash
122+
pnpm changeset
123+
\`\`\`
124+
125+
This command will guide you to select the changed packages, version type (patch/minor/major), and enter a description.
126+
127+
Please include the generated \`.changeset/*.md\` file in your commit.
128+
129+
> **Note**: If the \`${skipLabel}\` label is present, changeset is not required.
130+
131+
<!-- ${CHANGESET_DETECT_ADD_ACTIONS_CHECKSUM} -->`
132+
133+
const guideMessage = customMessage || defaultMessage
134+
const guideComment = {...commonParams, body: guideMessage}
135+
136+
if (prevComment !== undefined) {
137+
await octokit.rest.issues.updateComment({...guideComment, comment_id: prevComment.id})
138+
} else {
139+
await octokit.rest.issues.createComment(guideComment)
140+
}
141+
142+
core.info(
143+
isKoreanLanguage
144+
? `Fork PR에 changeset 가이드 코멘트를 추가했습니다.`
145+
: `Added changeset guide comment for fork PR.`,
146+
)
147+
}
148+
return
149+
}
150+
79151
/**
80152
* 변경된 파일 이름을 가져오기위한 api
81153
*/

0 commit comments

Comments
 (0)