Skip to content

Commit

Permalink
fix: do not notify duplicate comment event
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Mar 6, 2024
1 parent fde4fb1 commit 9284699
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
17 changes: 13 additions & 4 deletions src/github/templates/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Repository, User } from '@octokit/webhooks-types';

import { StringBuilder, limitLine } from '@/utils/string-builder';

import { ExtractPayload, Context } from '../types';
import { ExtractPayload, Context, THasChanges } from '../types';

import {
StopHandleError,
Expand Down Expand Up @@ -53,7 +53,7 @@ export function CommentBody(comment: {
return text;
}

const meaningfulCommentEditUser = new Set([
const meaningfulCommentEditUser = new Set<string>([
'dependabot[bot]',
'renovate[bot]',
'dependabot-preview[bot]',
Expand Down Expand Up @@ -91,6 +91,16 @@ function renderComment(
`do not render ${comment.user.login} comment edit event`,
);
}

const from = (payload as THasChanges).changes?.body?.from;
if (from === undefined) {
throw new StopHandleError('no from in comment edit');
}

const now = comment.body;
if (now === from) {
throw new StopHandleError('no change in comment edit');
}
}

return Template(
Expand All @@ -112,9 +122,8 @@ export async function handleIssueComment(
ctx: Context,
): Promise<TemplateRenderResult> {
const issue = payload.issue;
const isUnderPullRequest = Boolean(issue.pull_request);
let name: Name = 'issues';
if (isUnderPullRequest) {
if (Boolean(issue.pull_request)) {
name = 'pull_request';
}
return renderComment(name, payload, issue, ctx);
Expand Down
10 changes: 6 additions & 4 deletions src/github/templates/prOrIssue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ export async function handlePr(
// 说明是标题改变
// 我们只接收标题带有 WIP 的改变
if (
changes.title.from.toLowerCase().includes('wip') &&
!data.title.toLowerCase().includes('wip')
contains(changes.title.from, 'wip') &&
!contains(data.title, 'wip')
) {
oldTitle = changes.title.from;
}
if (
!changes.title.from.toLowerCase().includes('wip') &&
data.title.toLowerCase().includes('wip')
!contains(changes.title.from, 'wip') &&
contains(data.title, 'wip')
) {
oldTitle = changes.title.from;
}
Expand Down Expand Up @@ -207,3 +207,5 @@ export async function handleDiscussion(
): Promise<TemplateRenderResult> {
return render('discussion', payload, payload.discussion, ctx);
}

const contains = (str: string, sub: string) => str.toLowerCase().includes(sub);

0 comments on commit 9284699

Please sign in to comment.