chore: Add Github Action and husky #8
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: Missing Types Checker | |
on: | |
pull_request: | |
types: | |
- synchronize | |
jobs: | |
detect-modified-files: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Get modified files | |
id: modified-files | |
run: | | |
echo "::set-output name=modified::$(git diff --name-only HEAD^ types/)" | |
- name: Comment on PR | |
if: steps.modified-files.outputs.modified == '' | |
id: comment-on-pr | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const comment = ` | |
## Status | |
* ❌ No modified files found in the `types` directory. | |
Please make sure to include types for any changes you have made. Thank you!. | |
If you believe this is an error, kindly double-check your changes. | |
`; | |
const pullRequest = await github.rest.pulls.get({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.issue.number | |
}); | |
const comments = await github.rest.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number | |
}); | |
const existingComment = comments.data.find(comment => comment.user.login === 'github-actions[bot]' && comment.body.includes('❌ No modified files found in the `types` directory.')); | |
if (existingComment) { | |
console.log('Comment already exists'); | |
} else { | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
body: comment | |
}); | |
- name: Edit comment on PR | |
if: steps.modified-files.outputs.modified != '' | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const comment = ` | |
## Status | |
* ✅ Modified files found in the 'types' directory. | |
${steps.modified-files.outputs.modified} | |
`; | |
const comments = await github.rest.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number | |
}); | |
const existingComment = comments.data.find(comment => comment.user.login === 'github-actions[bot]' && comment.body.includes(':warning: No modified files found in the \'types\' directory.')); | |
if (existingComment) { | |
await github.rest.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: existingComment.id, | |
body: comment | |
}); | |
} |