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
4 changes: 3 additions & 1 deletion actions/setup/js/add_comment.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ async function main(config = {}) {
const requiredLabels = Array.isArray(config.required_labels) ? config.required_labels : [];
const requiredTitlePrefix = config.required_title_prefix || "";
const mentionsDisabled = config.mentions === false || config.mentions?.enabled === false;
const preResolvedMentionAliases =
!mentionsDisabled && Array.isArray(config.allowedMentionAliases) ? config.allowedMentionAliases.map(alias => (typeof alias === "string" ? alias.trim().replace(/^@+/, "") : "")).filter(alias => alias.length > 0) : [];
const configuredMentionAliases =
!mentionsDisabled && Array.isArray(config.mentions?.allowed) ? config.mentions.allowed.map(alias => (typeof alias === "string" ? alias.trim().replace(/^@+/, "") : "")).filter(alias => alias.length > 0) : [];
Comment on lines 437 to 441

Expand Down Expand Up @@ -656,7 +658,7 @@ async function main(config = {}) {
}
}
}
const allowedMentionAliases = deduplicateCaseInsensitive([...parentAuthors, ...configuredMentionAliases]);
const allowedMentionAliases = deduplicateCaseInsensitive([...parentAuthors, ...preResolvedMentionAliases, ...configuredMentionAliases]);

if (allowedMentionAliases.length > 0) {
core.info(`[MENTIONS] Allowing aliases in comment: ${allowedMentionAliases.join(", ")}`);
Expand Down
36 changes: 36 additions & 0 deletions actions/setup/js/add_comment.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2849,6 +2849,42 @@ describe("add_comment", () => {
expect(capturedBody).not.toContain("`@copilot`");
});

it("should preserve pre-resolved allowed mentions from handler manager", async () => {
const addCommentScript = fs.readFileSync(path.join(__dirname, "add_comment.cjs"), "utf8");

mockContext.payload = {
pull_request: {
number: 8535,
user: { login: "PRAuthor", type: "User" },
},
};

let capturedBody = null;
mockGithub.rest.issues.createComment = async params => {
capturedBody = params.body;
return {
data: {
id: 12345,
html_url: "https://github.com/owner/repo/issues/8535#issuecomment-12345",
},
};
};

const handler = await eval(`(async () => { ${addCommentScript}; return await main({ mentions: { allowedTeams: ["myorg/eng"] }, allowedMentionAliases: ["TeamMate"] }); })()`);

const message = {
type: "add_comment",
body: "@TeamMate thanks for taking a look",
};

const result = await handler(message, {});

expect(result.success).toBe(true);
expect(capturedBody).toBeDefined();
expect(capturedBody).toContain("@TeamMate");
expect(capturedBody).not.toContain("`@TeamMate`");
});

it("should escape all mentions when mentions.enabled is false", async () => {
const addCommentScript = fs.readFileSync(path.join(__dirname, "add_comment.cjs"), "utf8");

Expand Down
Loading