Skip to content

Commit 615fbac

Browse files
authored
fix(vote): improve UX when posting comment fails (#814)
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.
1 parent c4e7c03 commit 615fbac

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/voting_session.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export default class VotingSession extends Session {
114114
const body = 'I would like to close this vote, and for this effect, I\'m revealing my ' +
115115
`key part:\n\n${'```'}\n${keyPart}\n${'```'}\n`;
116116
if (this.postComment) {
117-
const { html_url } = await this.req.json(`https://api.github.com/repos/${this.owner}/${this.repo}/issues/${this.prid}/comments`, {
117+
const { message, html_url } = await this.req.json(`https://api.github.com/repos/${this.owner}/${this.repo}/issues/${this.prid}/comments`, {
118118
agent: this.req.proxyAgent,
119119
method: 'POST',
120120
headers: {
@@ -124,13 +124,23 @@ export default class VotingSession extends Session {
124124
},
125125
body: JSON.stringify({ body })
126126
});
127-
this.cli.log('Comment posted at:', html_url);
128-
} else if (isGhAvailable()) {
127+
if (html_url) {
128+
this.cli.log(`Comment posted at: ${html_url}`);
129+
return;
130+
} else {
131+
this.cli.warn(message);
132+
this.cli.error('Failed to post comment');
133+
}
134+
}
135+
if (isGhAvailable()) {
129136
this.cli.log('\nRun the following command to post the comment:\n');
130137
this.cli.log(
131138
`gh pr comment ${this.prid} --repo ${this.owner}/${this.repo} ` +
132139
`--body-file - <<'EOF'\n${body}\nEOF`
133140
);
141+
} else {
142+
this.cli.log('\nPost the following comment on the PR thread:\n');
143+
this.cli.log(body);
134144
}
135145
}
136146
}

0 commit comments

Comments
 (0)