Skip to content

Commit

Permalink
Maybe add status check
Browse files Browse the repository at this point in the history
  • Loading branch information
rehlma committed Apr 9, 2024
1 parent 4f793a1 commit d969582
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
18 changes: 15 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29035,7 +29035,7 @@ function run() {
}
else {
const comment = generateComment(newTodos, removedTodos);
yield commentPr(octokit, comment);
yield commentPr(octokit, comment, headRef);
core.setOutput('comment', comment);
}
}
Expand Down Expand Up @@ -29092,18 +29092,20 @@ function getTodoIfFound(line) {
return matches[0][1];
}
function generateComment(newTodos, removedTodos) {
let comment = 'New TODOs found in this PR:\n';
let comment = '```[tasklist]';
comment += 'New TODOs found in this PR:\n';
for (const todo of newTodos) {
comment += `- [ ] ${todo}\n`;
}
comment += '\nSolved TODOs found in this PR:\n';
for (const todo of removedTodos) {
comment += `- [x] ${todo}\n`;
}
comment += '```';
console.log('Comment:', comment);
return comment;
}
function commentPr(octokit, comment) {
function commentPr(octokit, comment, head) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
const { owner, repo } = github.context.repo;
Expand Down Expand Up @@ -29141,6 +29143,16 @@ function commentPr(octokit, comment) {
body: comment
});
}
yield octokit.rest.repos.addStatusCheckContexts({
owner,
repo,
branch: head,
contexts: ['todo-check']
}).then(() => {
console.log('Added status check context');
}).catch((error) => {
console.log('Error adding status check context:', error);
});
});
}

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function run(): Promise<void> {
} else {
const comment = generateComment(newTodos, removedTodos)

await commentPr(octokit, comment)
await commentPr(octokit, comment, headRef)
core.setOutput('comment', comment)
}
} catch (error) {
Expand Down Expand Up @@ -104,7 +104,8 @@ function generateComment(newTodos: string[], removedTodos: string[]): string {

async function commentPr(
octokit: ReturnType<typeof github.getOctokit>,
comment: string
comment: string,
head: string,

Check failure on line 108 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Delete `,`
): Promise<void> {
const { owner, repo } = github.context.repo
const issueNumber = github.context.payload.pull_request?.number
Expand Down Expand Up @@ -143,4 +144,15 @@ async function commentPr(
body: comment
})
}

await octokit.rest.repos.addStatusCheckContexts({

Check failure on line 148 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Insert `⏎····`
owner,

Check failure on line 149 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Insert `··`
repo,

Check failure on line 150 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Insert `··`
branch: head,

Check failure on line 151 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Insert `··`
contexts: ['todo-check']

Check failure on line 152 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Insert `··`
}).then(() => {

Check failure on line 153 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Replace `})` with `··})⏎····`

Check failure on line 153 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Prefer async/await to Promise.then()
console.log('Added status check context')

Check failure on line 154 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Insert `··`
}).catch((error) => {

Check failure on line 155 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Replace `}).catch((error)` with `··})⏎····.catch(error`
console.log('Error adding status check context:', error)
})
}

0 comments on commit d969582

Please sign in to comment.