Skip to content

Commit 53c8213

Browse files
committed
tweaks
1 parent 691b31d commit 53c8213

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

src/main.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ async function runSqldef(binaryPath: string, config: CommandConfig): Promise<str
223223
return output + stderr;
224224
}
225225

226-
async function createComment(body: string, command: string, versionOutput: string, schemaFile: string): Promise<void> {
226+
async function createComment(sqldefOutput: string, command: string, versionOutput: string, schemaFile: string): Promise<void> {
227227
const context = github.context;
228228

229229
if (context.eventName !== "pull_request") {
@@ -270,20 +270,22 @@ ${htmlCommentId}
270270
${infoLine}
271271
272272
~~~sql
273-
${body}
273+
${sqldefOutput}
274274
~~~
275275
276276
This comment was created by ${runLink}, powered by [sqldef/sqldef-preview-action](https://github.com/sqldef/sqldef-preview-action).
277277
`.trimStart();
278278

279279
if (previousComment) {
280+
core.info(`Updating previous comment with ID: ${previousComment.id}`);
280281
await octokit.rest.issues.updateComment({
281282
owner: context.repo.owner,
282283
repo: context.repo.repo,
283284
comment_id: previousComment.id,
284285
body: commentBody,
285286
});
286287
} else {
288+
core.info("Creating new comment");
287289
await octokit.rest.issues.createComment({
288290
owner: context.repo.owner,
289291
repo: context.repo.repo,
@@ -352,19 +354,8 @@ async function run(): Promise<void> {
352354
core.info("Applying desired schema to database");
353355
const output = await runSqldef(binaryPath, config);
354356

355-
if (output.trim()) {
356-
core.info("Schema changes detected:");
357-
core.info(output);
358-
// Create comment for PR events
359-
if (context.eventName === "pull_request") {
360-
await createComment(output, command, versionOutput, schemaFile);
361-
}
362-
} else {
363-
core.info("No schema changes detected");
364-
// Create comment for PR events
365-
if (context.eventName === "pull_request") {
366-
await createComment("No schema changes detected.", command, versionOutput, schemaFile);
367-
}
357+
if (context.eventName === "pull_request") {
358+
await createComment(output.trim() || "No schema changes detected.", command, versionOutput, schemaFile);
368359
}
369360

370361
if (!baselineSchemaFile && actualBaselineFile && actualBaselineFile !== "" && fs.existsSync(actualBaselineFile)) {

0 commit comments

Comments
 (0)