Skip to content

Commit

Permalink
fix(vote): improve UX when posting comment fails (#814)
Browse files Browse the repository at this point in the history
When the token doesn't have the permission to post the comment directly,
we can fallback to showing the user the error message and what command
they should type.
  • Loading branch information
aduh95 authored Jun 8, 2024
1 parent c4e7c03 commit 615fbac
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/voting_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default class VotingSession extends Session {
const body = 'I would like to close this vote, and for this effect, I\'m revealing my ' +
`key part:\n\n${'```'}\n${keyPart}\n${'```'}\n`;
if (this.postComment) {
const { html_url } = await this.req.json(`https://api.github.com/repos/${this.owner}/${this.repo}/issues/${this.prid}/comments`, {
const { message, html_url } = await this.req.json(`https://api.github.com/repos/${this.owner}/${this.repo}/issues/${this.prid}/comments`, {
agent: this.req.proxyAgent,
method: 'POST',
headers: {
Expand All @@ -124,13 +124,23 @@ export default class VotingSession extends Session {
},
body: JSON.stringify({ body })
});
this.cli.log('Comment posted at:', html_url);
} else if (isGhAvailable()) {
if (html_url) {
this.cli.log(`Comment posted at: ${html_url}`);
return;
} else {
this.cli.warn(message);
this.cli.error('Failed to post comment');
}
}
if (isGhAvailable()) {
this.cli.log('\nRun the following command to post the comment:\n');
this.cli.log(
`gh pr comment ${this.prid} --repo ${this.owner}/${this.repo} ` +
`--body-file - <<'EOF'\n${body}\nEOF`
);
} else {
this.cli.log('\nPost the following comment on the PR thread:\n');
this.cli.log(body);
}
}
}

0 comments on commit 615fbac

Please sign in to comment.