feat: 코드 안정성 향상, 다국어 지원 외 유용한 작업들 #64
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Spam Check | |
on: | |
pull_request: | |
types: [opened, edited, synchronize, reopened] | |
jobs: | |
check: | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
steps: | |
- uses: actions/github-script@v7 | |
with: | |
script: | | |
const pull_request = context.payload.pull_request; | |
if (pull_request === undefined) { | |
console.log("This is not a pull request"); | |
return; | |
} | |
const prOpener = pull_request.user.login; | |
const { data: contributions } = await github.rest.repos.listContributors({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}); | |
const prOpenerContributions = contributions.find( | |
(contributor) => contributor.login === prOpener | |
); | |
if ( | |
prOpenerContributions !== undefined && | |
prOpenerContributions.contributions > 0 | |
) { | |
console.log("the PR opener has previous contributions"); | |
return; | |
} | |
// If the PR opener is not a contributor, check if the body is empty or it contains the default message | |
const body = pull_request.body; | |
const defaultMessage = "Explain the rationale behind the changes and remove this line" | |
if (!body || body.includes(defaultMessage)) { | |
// Add a comment to the PR | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: pull_request.number, | |
body: "Closing this PR because it does not follow the contribution guidelines.", | |
}); | |
// Close the PR | |
await github.rest.pulls.update({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: pull_request.number, | |
state: "closed", | |
}); | |
} |