diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..a8cc12e --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,28 @@ +on: + pull_request: + branches: [main] + # https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull_request + types: + - assigned + - unassigned + - labeled + - unlabeled + - opened + - edited + - closed + - reopened + - synchronize + - converted_to_draft + - ready_for_review +name: "Test" + +jobs: + does_it_work: + runs-on: ubuntu-latest + name: Does it work? + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: The checklist action + uses: ./ + id: task-list-checker diff --git a/src/report.js b/src/report.js index ecfb130..6fcb6ac 100644 --- a/src/report.js +++ b/src/report.js @@ -5,60 +5,30 @@ const { getOctokit, maybeForbidden } = require('./utils'); - -const message_sign = '​ ​​​​​​​​ ​​​​​​​'; - - const send = async (context, message) => { const octokit = getOctokit(context); + const {owner, repo} = context.repo; + + const output = Boolean(message.length) ? { + title: 'Checklist not complete!', + summary: message, + } : { + title: 'Checklist looks good!', + summary: 'https://genius.com/images/extreme.jpg', + }; - const comments = (await maybeForbidden( - octokit.rest.issues.listComments, + await maybeForbidden( + octokit.rest.checks.create, { - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, + owner, + repo, + name: 'PR Validation', + head_sha: context.pull_request.commits.at(-1).sha, + output, }, - )).data; - const previous_comment = comments.filter(comment => comment.body.endsWith(message_sign))[0]; - - if (!message.length) { - if (previous_comment) { - await maybeForbidden( - octokit.rest.issues.deleteComment, - { - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: previous_comment.id, - }, - ); - }; - } else { - if (comments.length && previous_comment) { - await maybeForbidden( - octokit.rest.issues.updateComment, - { - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: previous_comment.id, - body: message.trim() + message_sign, - }, - ); - } else { - await maybeForbidden( - octokit.rest.issues.createComment, - { - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - body: message.trim() + message_sign, - }, - ); - }; - }; + ); }; - module.exports = Object.freeze({ send, });