Skip to content

feat: add useQueryString | Image Automation #123

feat: add useQueryString | Image Automation

feat: add useQueryString | Image Automation #123

name: Enforce PR Title Format with Comments
on:
pull_request:
types: [opened, edited, synchronize]
jobs:
validate-title:
runs-on: ubuntu-latest
steps:
- name: Check PR Title and Manage Comments
uses: actions/github-script@v6
with:
script: |
const prTitle = context.payload.pull_request.title;
const prNumber = context.payload.pull_request.number;
const repoOwner = context.repo.owner;
const repoName = context.repo.repo;
const validTitleRegex = /^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-zA-Z0-9-_]+\))?:\s.+$/;
const commentIdentifier = "**๐Ÿ” PR ์ œ๋ชฉ ํ™•์ธ ๋ด‡**";
const { data: comments } = await github.rest.issues.listComments({
owner: repoOwner,
repo: repoName,
issue_number: prNumber,
});
const botComment = comments.find(comment => comment.body.includes(commentIdentifier));
if (!validTitleRegex.test(prTitle)) {
console.log("โŒ Invalid PR title detected.");
const invalidMessage = commentIdentifier + "\n\n" +
"โŒ PR ์ œ๋ชฉ์ด ์ž˜๋ชป๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ปจ๋ฒค์…”๋„ ์ปค๋ฐ‹ ํ˜•์‹์— ๋งž์ถฐ์ฃผ์„ธ์š”.\n\n" +
"์˜ˆ:\n" +
"- feat: ์ƒˆ๋กœ์šด ๋กœ๊ทธ์ธ ๊ธฐ๋Šฅ ์ถ”๊ฐ€\n" +
"- fix: ์ž˜๋ชป๋œ API ํ˜ธ์ถœ ์ˆ˜์ •\n" +
"- feat(react-native): React Native ๊ด€๋ จ ๊ธฐ๋Šฅ ์ถ”๊ฐ€\n\n" +
"๐Ÿ‘‰ ์ฐธ๊ณ : [์ปจ๋ฒค์…”๋„ ์ปค๋ฐ‹ ๊ฐ€์ด๋“œ](https://www.conventionalcommits.org)";
if (botComment) {
console.log("๐Ÿ”„ Updating existing bot comment.");
await github.rest.issues.updateComment({
owner: repoOwner,
repo: repoName,
comment_id: botComment.id,
body: invalidMessage,
});
} else {
console.log("๐Ÿ“ Creating new bot comment.");
await github.rest.issues.createComment({
owner: repoOwner,
repo: repoName,
issue_number: prNumber,
body: invalidMessage,
});
}
throw new Error("Invalid PR title.");
}
console.log("โœ… PR title is valid.");
if (botComment) {
console.log("๐Ÿ—‘๏ธ Deleting bot comment.");
await github.rest.issues.deleteComment({
owner: repoOwner,
repo: repoName,
comment_id: botComment.id,
});
}