Skip to content

Commit

Permalink
Doin' it
Browse files Browse the repository at this point in the history
  • Loading branch information
RDIL authored Nov 26, 2024
1 parent 02cc01a commit 357c404
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 47 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -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
64 changes: 17 additions & 47 deletions src/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

0 comments on commit 357c404

Please sign in to comment.