Skip to content

Commit fd5aa70

Browse files
committed
feat: use unique comment IDs for each command/schema combination
Each job now creates a separate PR comment identified by command and schema file. Comments use HTML comment IDs to prevent collision between different sqldef commands.
1 parent 7ecd63e commit fd5aa70

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

dist/index.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ async function runSqldef(binaryPath, config) {
249249
// Return combined output for successful runs
250250
return output + stderr;
251251
}
252-
async function createComment(body) {
252+
async function createComment(body, command, schemaFile) {
253253
const context = github.context;
254254
if (context.eventName !== "pull_request") {
255255
core.warning("Not a pull request event, skipping comment");
@@ -266,11 +266,19 @@ async function createComment(body) {
266266
repo: context.repo.repo,
267267
issue_number: context.payload.pull_request.number,
268268
});
269-
const title = "SQLDef Migration Preview";
270-
const previousComment = comments.find((comment) => comment.user?.type === "Bot" && comment.body?.includes(title));
269+
// Create a unique ID for this command/schema combination
270+
const commentId = `${command}-${schemaFile}`;
271+
const htmlCommentId = `<!-- sqldef-preview-action-id: ${commentId} -->`;
272+
// Find previous comment by searching for the HTML comment ID
273+
const previousComment = comments.find((comment) => comment.user?.type === "Bot" && comment.body?.includes(htmlCommentId));
274+
const title = `SQLDef Migration Preview (${command})`;
275+
const subtitle = `Schema file: \`${schemaFile}\``;
271276
const commentBody = `
277+
${htmlCommentId}
272278
## ${title}
273279

280+
${subtitle}
281+
274282
~~~sql
275283
${body}
276284
~~~
@@ -367,14 +375,14 @@ async function run() {
367375
core.info(output);
368376
// Only create comment for actual PR events
369377
if (context.eventName === "pull_request" && !baselineSchemaFile) {
370-
await createComment(output);
378+
await createComment(output, command, schemaFile);
371379
}
372380
}
373381
else {
374382
core.info("No schema changes detected");
375383
// Only create comment for actual PR events
376384
if (context.eventName === "pull_request" && !baselineSchemaFile) {
377-
await createComment("No schema changes detected.");
385+
await createComment("No schema changes detected.", command, schemaFile);
378386
}
379387
}
380388
if (!baselineSchemaFile && actualBaselineFile && actualBaselineFile !== "" && fs.existsSync(actualBaselineFile)) {

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ async function runSqldef(binaryPath: string, config: CommandConfig): Promise<str
234234
return output + stderr;
235235
}
236236

237-
async function createComment(body: string): Promise<void> {
237+
async function createComment(body: string, command: string, schemaFile: string): Promise<void> {
238238
const context = github.context;
239239

240240
if (context.eventName !== "pull_request") {
@@ -256,13 +256,22 @@ async function createComment(body: string): Promise<void> {
256256
issue_number: context.payload.pull_request!.number,
257257
});
258258

259-
const title = "SQLDef Migration Preview";
259+
// Create a unique ID for this command/schema combination
260+
const commentId = `${command}-${schemaFile}`;
261+
const htmlCommentId = `<!-- sqldef-preview-action-id: ${commentId} -->`;
260262

261-
const previousComment = comments.find((comment) => comment.user?.type === "Bot" && comment.body?.includes(title));
263+
// Find previous comment by searching for the HTML comment ID
264+
const previousComment = comments.find((comment) => comment.user?.type === "Bot" && comment.body?.includes(htmlCommentId));
265+
266+
const title = `SQLDef Migration Preview (${command})`;
267+
const subtitle = `Schema file: \`${schemaFile}\``;
262268

263269
const commentBody = `
270+
${htmlCommentId}
264271
## ${title}
265272
273+
${subtitle}
274+
266275
~~~sql
267276
${body}
268277
~~~
@@ -369,13 +378,13 @@ async function run(): Promise<void> {
369378
core.info(output);
370379
// Only create comment for actual PR events
371380
if (context.eventName === "pull_request" && !baselineSchemaFile) {
372-
await createComment(output);
381+
await createComment(output, command, schemaFile);
373382
}
374383
} else {
375384
core.info("No schema changes detected");
376385
// Only create comment for actual PR events
377386
if (context.eventName === "pull_request" && !baselineSchemaFile) {
378-
await createComment("No schema changes detected.");
387+
await createComment("No schema changes detected.", command, schemaFile);
379388
}
380389
}
381390

0 commit comments

Comments
 (0)