Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/actions/javascript/proposalPoliceComment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11639,6 +11639,7 @@ async function run() {
console.log('commentsResponse', commentsResponse);
core.endGroup();
let didFindDuplicate = false;
let originalProposal;
for (const previousProposal of commentsResponse) {
const isProposal = !!previousProposal.body?.includes(CONST_1.default.PROPOSAL_KEYWORD);
const previousProposalCreatedAt = new Date(previousProposal.created_at).getTime();
Expand All @@ -11664,13 +11665,14 @@ async function run() {
if (similarityPercentage >= 90) {
console.log(`Found duplicate with ${similarityPercentage}% similarity.`);
didFindDuplicate = true;
originalProposal = previousProposal;
break;
}
}
}
if (didFindDuplicate) {
const duplicateCheckWithdrawMessage = proposalPolice_1.default.getDuplicateCheckWithdrawMessage();
const duplicateCheckNoticeMessage = proposalPolice_1.default.getDuplicateCheckNoticeMessage(newProposalAuthor);
const duplicateCheckNoticeMessage = proposalPolice_1.default.getDuplicateCheckNoticeMessage(newProposalAuthor, originalProposal?.html_url);
// If a duplicate proposal is detected, update the comment to withdraw it
console.log('ProposalPolice™ withdrawing duplicated proposal...');
await GithubUtils_1.default.octokit.issues.updateComment({
Expand Down Expand Up @@ -12557,8 +12559,9 @@ const PROPOSAL_POLICE_TEMPLATES = {
getDuplicateCheckWithdrawMessage: () => {
return '#### 🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.';
},
getDuplicateCheckNoticeMessage: (proposalAuthor) => {
return `⚠️ @${proposalAuthor} Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.`;
getDuplicateCheckNoticeMessage: (proposalAuthor, originalProposalURL) => {
const existingProposalWithURL = originalProposalURL ? `[existing proposal](${originalProposalURL})` : 'existing proposal';
return `⚠️ @${proposalAuthor} Your proposal is a duplicate of an already ${existingProposalWithURL} and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.`;
},
};
exports["default"] = PROPOSAL_POLICE_TEMPLATES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {context} from '@actions/github';
import type {IssueCommentCreatedEvent, IssueCommentEditedEvent, IssueCommentEvent} from '@octokit/webhooks-types';
import {format} from 'date-fns';
import {toZonedTime} from 'date-fns-tz';
import type {TupleToUnion} from 'type-fest';
import {convertToNumber} from '@github/libs/ActionUtils';
import CONST from '@github/libs/CONST';
import GithubUtils from '@github/libs/GithubUtils';
Expand Down Expand Up @@ -91,6 +92,7 @@ async function run() {
core.endGroup();

let didFindDuplicate = false;
let originalProposal: TupleToUnion<typeof commentsResponse> | undefined;
for (const previousProposal of commentsResponse) {
const isProposal = !!previousProposal.body?.includes(CONST.PROPOSAL_KEYWORD);
const previousProposalCreatedAt = new Date(previousProposal.created_at).getTime();
Expand All @@ -117,14 +119,15 @@ async function run() {
if (similarityPercentage >= 90) {
console.log(`Found duplicate with ${similarityPercentage}% similarity.`);
didFindDuplicate = true;
originalProposal = previousProposal;
break;
}
}
}

if (didFindDuplicate) {
const duplicateCheckWithdrawMessage = PROPOSAL_POLICE_TEMPLATES.getDuplicateCheckWithdrawMessage();
const duplicateCheckNoticeMessage = PROPOSAL_POLICE_TEMPLATES.getDuplicateCheckNoticeMessage(newProposalAuthor);
const duplicateCheckNoticeMessage = PROPOSAL_POLICE_TEMPLATES.getDuplicateCheckNoticeMessage(newProposalAuthor, originalProposal?.html_url);
// If a duplicate proposal is detected, update the comment to withdraw it
console.log('ProposalPolice™ withdrawing duplicated proposal...');
await GithubUtils.octokit.issues.updateComment({
Expand Down
5 changes: 3 additions & 2 deletions prompts/proposalPolice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ const PROPOSAL_POLICE_TEMPLATES = {
getDuplicateCheckWithdrawMessage: (): string => {
return '#### 🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.';
},
getDuplicateCheckNoticeMessage: (proposalAuthor: string | undefined): string => {
return `⚠️ @${proposalAuthor} Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.`;
getDuplicateCheckNoticeMessage: (proposalAuthor: string | undefined, originalProposalURL?: string): string => {
const existingProposalWithURL = originalProposalURL ? `[existing proposal](${originalProposalURL})` : 'existing proposal';
return `⚠️ @${proposalAuthor} Your proposal is a duplicate of an already ${existingProposalWithURL} and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.`;

@rushatgabhane rushatgabhane Aug 6, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: use a friendly tone. i don't think people's intention is to spam

remove to prevent spam

Suggested change
return `⚠️ @${proposalAuthor} Your proposal is a duplicate of an already ${existingProposalWithURL} and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.`;
return `⚠️ @${proposalAuthor} Your proposal is a duplicate of an already ${existingProposalWithURL} and has been automatically withdrawn. Please review the existing proposals before submitting a new one.`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha, this is fair feedback

},
};

Expand Down
Loading