Skip to content

chore: Add Github Action and husky #17

chore: Add Github Action and husky

chore: Add Github Action and husky #17

Workflow file for this run

name: Missing Types Checker
on:
push:
branches: [ main, chore/add-husky]
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(':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
});
} 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 = `
:white_check_mark: 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
});
}