Skip to content

Commit

Permalink
feat: support comments from issue_comment.created event
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed May 21, 2020
1 parent dd8eb54 commit a57f251
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 12 deletions.
19 changes: 16 additions & 3 deletions dist/index-node10-dev.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index-node10-dev.cjs.js.map

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions dist/index-node10.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index-node10.cjs.js.map

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/pr-handlers/comment.ts
Expand Up @@ -56,7 +56,12 @@ export default function prComment(
mongoStores: MongoStores,
): void {
app.on(
'pull_request_review_comment.created',
[
'pull_request_review_comment.created',
// comments without review and without path are sent with issue_comment.created.
// createHandlerPullRequestChange checks if pull_request event is present, removing real issues comments.
'issue_comment.created',
],
createHandlerPullRequestChange<WebhookPayloadPullRequestReviewComment>(
mongoStores,
async (pr, context, repoContext): Promise<void> => {
Expand Down
17 changes: 14 additions & 3 deletions src/pr-handlers/utils/index.ts
Expand Up @@ -21,16 +21,27 @@ export const handlerPullRequestChange = async <
context: Context<T>,
callback: CallbackWithPRAndRepoContext,
): Promise<void> => {
let pullRequest = context.payload.pull_request;
if (!pullRequest) {
const issue = (context.payload as any).issue;
if (!issue) return;
pullRequest = {
...issue,
...issue.pull_request,
};
}
if (!pullRequest) return;

const repoContext = await obtainRepoContext(mongoStores, context);
if (!repoContext) return;

return repoContext.lockPROrPRS(
String(context.payload.pull_request.id),
context.payload.pull_request.number,
String(pullRequest.id),
pullRequest.number,
async () => {
const prResult = await context.github.pulls.get(
context.repo({
pull_number: context.payload.pull_request.number,
pull_number: pullRequest.number,
}),
);

Expand Down

0 comments on commit a57f251

Please sign in to comment.