From aaf656ebbbc2a1e029fca48627e02ae592f17410 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 20 Aug 2025 21:41:03 +0000 Subject: [PATCH 1/4] feat: enhance issue and pull request comments with AI disclaimer and context references --- .github/workflows/test-claude.lock.yml | 58 +++++++++++++------------ pkg/workflow/js/create_comment.mjs | 9 +++- pkg/workflow/js/create_issue.mjs | 37 +++++++--------- pkg/workflow/js/create_pull_request.mjs | 11 +++-- 4 files changed, 61 insertions(+), 54 deletions(-) diff --git a/.github/workflows/test-claude.lock.yml b/.github/workflows/test-claude.lock.yml index cd6a49aa3a6..80eb0e24aaa 100644 --- a/.github/workflows/test-claude.lock.yml +++ b/.github/workflows/test-claude.lock.yml @@ -564,13 +564,16 @@ jobs: console.log('No GITHUB_AW_AGENT_OUTPUT environment variable found'); return; } - if (outputContent.trim() === '') { console.log('Agent output content is empty'); return; } - console.log('Agent output content length:', outputContent.length); + // Check if we're in an issue context (triggered by an issue event) + const parentIssueNumber = context.payload?.issue?.number; + // Parse labels from environment variable (comma-separated string) + const labelsEnv = process.env.GITHUB_AW_ISSUE_LABELS; + const labels = labelsEnv ? labelsEnv.split(',').map(label => label.trim()).filter(label => label) : []; // Parse the output to extract title and body const lines = outputContent.split('\n'); @@ -611,38 +614,30 @@ jobs: title = titlePrefix + title; } + if (parentIssueNumber) { + console.log('Detected issue context, parent issue #' + parentIssueNumber); + + // Add reference to parent issue in the child issue body + bodyLines.push(`Related to #${parentIssueNumber}`; + } + + // Add AI disclaimer with run id, run htmlurl + bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${context.run.id}](${context.run.html_url})`); + // Prepare the body content const body = bodyLines.join('\n').trim(); - // Parse labels from environment variable (comma-separated string) - const labelsEnv = process.env.GITHUB_AW_ISSUE_LABELS; - const labels = labelsEnv ? labelsEnv.split(',').map(label => label.trim()).filter(label => label) : []; - console.log('Creating issue with title:', title); console.log('Labels:', labels); console.log('Body length:', body.length); - // Check if we're in an issue context (triggered by an issue event) - const parentIssueNumber = context.payload?.issue?.number; - let finalBody = body; - - if (parentIssueNumber) { - console.log('Detected issue context, parent issue #' + parentIssueNumber); - - // Add reference to parent issue in the child issue body - if (finalBody.trim()) { - finalBody = `Related to #${parentIssueNumber}\n\n${finalBody}`; - } else { - finalBody = `Related to #${parentIssueNumber}`; - } - } // Create the issue using GitHub API const { data: issue } = await github.rest.issues.create({ owner: context.repo.owner, repo: context.repo.repo, title: title, - body: finalBody, + body: body, labels: labels }); @@ -747,15 +742,20 @@ jobs: return; } + + let body = outputContent.trim(); + // Add AI disclaimer with run id, run htmlurl + body += `\n\n> Generated by Agentic Workflow Run [${context.run.id}](${context.run.html_url})`; + console.log(`Creating comment on ${commentEndpoint} #${issueNumber}`); - console.log('Comment content length:', outputContent.length); + console.log('Comment content length:', body.length); // Create the comment using GitHub API const { data: comment } = await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: issueNumber, - body: outputContent + body: body }); console.log('Created comment #' + comment.id + ': ' + comment.html_url); @@ -808,11 +808,12 @@ jobs: GITHUB_AW_PR_LABELS: "claude,automation,bot" with: script: | + // Required Node.js modules + import * as fs from "fs"; + import * as crypto from "crypto"; + import { execSync } from "child_process": + async function main() { - // Required Node.js modules - const fs = require('fs'); - const crypto = require('crypto'); - const { execSync } = require('child_process'); // Environment validation - fail early if required variables are missing const workflowId = process.env.GITHUB_AW_WORKFLOW_ID; @@ -882,6 +883,9 @@ jobs: title = titlePrefix + title; } + // Add AI disclaimer with run id, run htmlurl + bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${context.run.id}](${context.run.html_url})`); + // Prepare the body content const body = bodyLines.join('\n').trim(); diff --git a/pkg/workflow/js/create_comment.mjs b/pkg/workflow/js/create_comment.mjs index bc3997fa53b..5484e03178e 100644 --- a/pkg/workflow/js/create_comment.mjs +++ b/pkg/workflow/js/create_comment.mjs @@ -49,15 +49,20 @@ async function main() { return; } + + let body = outputContent.trim(); + // Add AI disclaimer with run id, run htmlurl + body += `\n\n> Generated by Agentic Workflow Run [${context.run.id}](${context.run.html_url})\n`; + console.log(`Creating comment on ${commentEndpoint} #${issueNumber}`); - console.log('Comment content length:', outputContent.length); + console.log('Comment content length:', body.length); // Create the comment using GitHub API const { data: comment } = await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: issueNumber, - body: outputContent + body: body }); console.log('Created comment #' + comment.id + ': ' + comment.html_url); diff --git a/pkg/workflow/js/create_issue.mjs b/pkg/workflow/js/create_issue.mjs index 59a9a0b6d5f..39c0514c0fb 100644 --- a/pkg/workflow/js/create_issue.mjs +++ b/pkg/workflow/js/create_issue.mjs @@ -5,13 +5,16 @@ async function main() { console.log('No GITHUB_AW_AGENT_OUTPUT environment variable found'); return; } - if (outputContent.trim() === '') { console.log('Agent output content is empty'); return; } - console.log('Agent output content length:', outputContent.length); + // Check if we're in an issue context (triggered by an issue event) + const parentIssueNumber = context.payload?.issue?.number; + // Parse labels from environment variable (comma-separated string) + const labelsEnv = process.env.GITHUB_AW_ISSUE_LABELS; + const labels = labelsEnv ? labelsEnv.split(',').map(label => label.trim()).filter(label => label) : []; // Parse the output to extract title and body const lines = outputContent.split('\n'); @@ -52,38 +55,30 @@ async function main() { title = titlePrefix + title; } + if (parentIssueNumber) { + console.log('Detected issue context, parent issue #' + parentIssueNumber); + + // Add reference to parent issue in the child issue body + bodyLines.push(`Related to #${parentIssueNumber}`; + } + + // Add AI disclaimer with run id, run htmlurl + bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${context.run.id}](${context.run.html_url})`, ''); + // Prepare the body content const body = bodyLines.join('\n').trim(); - // Parse labels from environment variable (comma-separated string) - const labelsEnv = process.env.GITHUB_AW_ISSUE_LABELS; - const labels = labelsEnv ? labelsEnv.split(',').map(label => label.trim()).filter(label => label) : []; - console.log('Creating issue with title:', title); console.log('Labels:', labels); console.log('Body length:', body.length); - // Check if we're in an issue context (triggered by an issue event) - const parentIssueNumber = context.payload?.issue?.number; - let finalBody = body; - - if (parentIssueNumber) { - console.log('Detected issue context, parent issue #' + parentIssueNumber); - - // Add reference to parent issue in the child issue body - if (finalBody.trim()) { - finalBody = `Related to #${parentIssueNumber}\n\n${finalBody}`; - } else { - finalBody = `Related to #${parentIssueNumber}`; - } - } // Create the issue using GitHub API const { data: issue } = await github.rest.issues.create({ owner: context.repo.owner, repo: context.repo.repo, title: title, - body: finalBody, + body: body, labels: labels }); diff --git a/pkg/workflow/js/create_pull_request.mjs b/pkg/workflow/js/create_pull_request.mjs index bd57d9a13af..910e4d0af13 100644 --- a/pkg/workflow/js/create_pull_request.mjs +++ b/pkg/workflow/js/create_pull_request.mjs @@ -1,8 +1,8 @@ +import * as fs from "fs"; +import * as crypto from "crypto"; +import { execSync } from "child_process": + async function main() { - // Required Node.js modules - const fs = require('fs'); - const crypto = require('crypto'); - const { execSync } = require('child_process'); // Environment validation - fail early if required variables are missing const workflowId = process.env.GITHUB_AW_WORKFLOW_ID; @@ -72,6 +72,9 @@ async function main() { title = titlePrefix + title; } + // Add AI disclaimer with run id, run htmlurl + bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${context.run.id}](${context.run.html_url})`); + // Prepare the body content const body = bodyLines.join('\n').trim(); From a724992e9f506555b73fec2af88e485d8e023e96 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 20 Aug 2025 21:43:17 +0000 Subject: [PATCH 2/4] fix: correct syntax error in create_pull_request.mjs and add missing parenthesis in create_issue.mjs --- .github/workflows/test-claude.lock.yml | 9 ++++----- pkg/workflow/js/create_issue.mjs | 2 +- pkg/workflow/js/create_pull_request.mjs | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-claude.lock.yml b/.github/workflows/test-claude.lock.yml index 80eb0e24aaa..2bb68759358 100644 --- a/.github/workflows/test-claude.lock.yml +++ b/.github/workflows/test-claude.lock.yml @@ -618,11 +618,11 @@ jobs: console.log('Detected issue context, parent issue #' + parentIssueNumber); // Add reference to parent issue in the child issue body - bodyLines.push(`Related to #${parentIssueNumber}`; + bodyLines.push(`Related to #${parentIssueNumber}`); } // Add AI disclaimer with run id, run htmlurl - bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${context.run.id}](${context.run.html_url})`); + bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${context.run.id}](${context.run.html_url})`, ''); // Prepare the body content const body = bodyLines.join('\n').trim(); @@ -745,7 +745,7 @@ jobs: let body = outputContent.trim(); // Add AI disclaimer with run id, run htmlurl - body += `\n\n> Generated by Agentic Workflow Run [${context.run.id}](${context.run.html_url})`; + body += `\n\n> Generated by Agentic Workflow Run [${context.run.id}](${context.run.html_url})\n`; console.log(`Creating comment on ${commentEndpoint} #${issueNumber}`); console.log('Comment content length:', body.length); @@ -808,10 +808,9 @@ jobs: GITHUB_AW_PR_LABELS: "claude,automation,bot" with: script: | - // Required Node.js modules import * as fs from "fs"; import * as crypto from "crypto"; - import { execSync } from "child_process": + import { execSync } from "child_process"; async function main() { diff --git a/pkg/workflow/js/create_issue.mjs b/pkg/workflow/js/create_issue.mjs index 39c0514c0fb..94f2279eb7a 100644 --- a/pkg/workflow/js/create_issue.mjs +++ b/pkg/workflow/js/create_issue.mjs @@ -59,7 +59,7 @@ async function main() { console.log('Detected issue context, parent issue #' + parentIssueNumber); // Add reference to parent issue in the child issue body - bodyLines.push(`Related to #${parentIssueNumber}`; + bodyLines.push(`Related to #${parentIssueNumber}`); } // Add AI disclaimer with run id, run htmlurl diff --git a/pkg/workflow/js/create_pull_request.mjs b/pkg/workflow/js/create_pull_request.mjs index 910e4d0af13..af02e5010e5 100644 --- a/pkg/workflow/js/create_pull_request.mjs +++ b/pkg/workflow/js/create_pull_request.mjs @@ -1,6 +1,6 @@ import * as fs from "fs"; import * as crypto from "crypto"; -import { execSync } from "child_process": +import { execSync } from "child_process"; async function main() { From fb18eb9b443319c24bbb1af043fd58f286b73669 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 20 Aug 2025 21:49:18 +0000 Subject: [PATCH 3/4] feat: update AI disclaimer to include workflow run information in comments and issues --- .github/workflows/test-claude.lock.yml | 13 ++++++++++--- pkg/workflow/js/create_comment.mjs | 4 +++- pkg/workflow/js/create_issue.mjs | 5 ++++- pkg/workflow/js/create_pull_request.mjs | 4 +++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test-claude.lock.yml b/.github/workflows/test-claude.lock.yml index 2bb68759358..8becbd7d3c6 100644 --- a/.github/workflows/test-claude.lock.yml +++ b/.github/workflows/test-claude.lock.yml @@ -622,7 +622,10 @@ jobs: } // Add AI disclaimer with run id, run htmlurl - bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${context.run.id}](${context.run.html_url})`, ''); + // Add AI disclaimer with workflow run information + const runId = context.runId; + const runUrl = `${context.payload.repository.html_url}/actions/runs/${runId}`; + bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${runId}](${runUrl})`, ''); // Prepare the body content const body = bodyLines.join('\n').trim(); @@ -745,7 +748,9 @@ jobs: let body = outputContent.trim(); // Add AI disclaimer with run id, run htmlurl - body += `\n\n> Generated by Agentic Workflow Run [${context.run.id}](${context.run.html_url})\n`; + const runId = context.runId; + const runUrl = `${context.payload.repository.html_url}/actions/runs/${runId}`; + body += `\n\n> Generated by Agentic Workflow Run [${runId}](${runUrl})\n`; console.log(`Creating comment on ${commentEndpoint} #${issueNumber}`); console.log('Comment content length:', body.length); @@ -883,7 +888,9 @@ jobs: } // Add AI disclaimer with run id, run htmlurl - bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${context.run.id}](${context.run.html_url})`); + const runId = context.runId; + const runUrl = `${context.payload.repository.html_url}/actions/runs/${runId}`; + bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${runId}](${runUrl})`, ''); // Prepare the body content const body = bodyLines.join('\n').trim(); diff --git a/pkg/workflow/js/create_comment.mjs b/pkg/workflow/js/create_comment.mjs index 5484e03178e..1a619bd0bb8 100644 --- a/pkg/workflow/js/create_comment.mjs +++ b/pkg/workflow/js/create_comment.mjs @@ -52,7 +52,9 @@ async function main() { let body = outputContent.trim(); // Add AI disclaimer with run id, run htmlurl - body += `\n\n> Generated by Agentic Workflow Run [${context.run.id}](${context.run.html_url})\n`; + const runId = context.runId; + const runUrl = `${context.payload.repository.html_url}/actions/runs/${runId}`; + body += `\n\n> Generated by Agentic Workflow Run [${runId}](${runUrl})\n`; console.log(`Creating comment on ${commentEndpoint} #${issueNumber}`); console.log('Comment content length:', body.length); diff --git a/pkg/workflow/js/create_issue.mjs b/pkg/workflow/js/create_issue.mjs index 94f2279eb7a..ce0dece1954 100644 --- a/pkg/workflow/js/create_issue.mjs +++ b/pkg/workflow/js/create_issue.mjs @@ -63,7 +63,10 @@ async function main() { } // Add AI disclaimer with run id, run htmlurl - bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${context.run.id}](${context.run.html_url})`, ''); + // Add AI disclaimer with workflow run information + const runId = context.runId; + const runUrl = `${context.payload.repository.html_url}/actions/runs/${runId}`; + bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${runId}](${runUrl})`, ''); // Prepare the body content const body = bodyLines.join('\n').trim(); diff --git a/pkg/workflow/js/create_pull_request.mjs b/pkg/workflow/js/create_pull_request.mjs index af02e5010e5..c51958b45ed 100644 --- a/pkg/workflow/js/create_pull_request.mjs +++ b/pkg/workflow/js/create_pull_request.mjs @@ -73,7 +73,9 @@ async function main() { } // Add AI disclaimer with run id, run htmlurl - bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${context.run.id}](${context.run.html_url})`); + const runId = context.runId; + const runUrl = `${context.payload.repository.html_url}/actions/runs/${runId}`; + bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${runId}](${runUrl})`, ''); // Prepare the body content const body = bodyLines.join('\n').trim(); From 1c419f4ce94d9de78fdf817af0ed69f4b6f0a0c5 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 20 Aug 2025 22:00:52 +0000 Subject: [PATCH 4/4] feat: refactor workflow scripts to use CommonJS modules and update TypeScript configuration --- .github/workflows/test-claude.lock.yml | 6 +++--- pkg/workflow/js.go | 6 +++--- .../js/{create_comment.mjs => create_comment.cjs} | 0 pkg/workflow/js/{create_issue.mjs => create_issue.cjs} | 0 .../{create_pull_request.mjs => create_pull_request.cjs} | 6 +++--- tsconfig.json | 9 ++++++--- 6 files changed, 15 insertions(+), 12 deletions(-) rename pkg/workflow/js/{create_comment.mjs => create_comment.cjs} (100%) rename pkg/workflow/js/{create_issue.mjs => create_issue.cjs} (100%) rename pkg/workflow/js/{create_pull_request.mjs => create_pull_request.cjs} (97%) diff --git a/.github/workflows/test-claude.lock.yml b/.github/workflows/test-claude.lock.yml index 8becbd7d3c6..72eafd8d37d 100644 --- a/.github/workflows/test-claude.lock.yml +++ b/.github/workflows/test-claude.lock.yml @@ -813,9 +813,9 @@ jobs: GITHUB_AW_PR_LABELS: "claude,automation,bot" with: script: | - import * as fs from "fs"; - import * as crypto from "crypto"; - import { execSync } from "child_process"; + const fs = require("fs"); + const crypto = require("crypto"); + const { execSync } = require("child_process"); async function main() { diff --git a/pkg/workflow/js.go b/pkg/workflow/js.go index 80d67dc7e59..11a4e4c8133 100644 --- a/pkg/workflow/js.go +++ b/pkg/workflow/js.go @@ -4,11 +4,11 @@ import ( _ "embed" ) -//go:embed js/create_pull_request.mjs +//go:embed js/create_pull_request.cjs var createPullRequestScript string -//go:embed js/create_issue.mjs +//go:embed js/create_issue.cjs var createIssueScript string -//go:embed js/create_comment.mjs +//go:embed js/create_comment.cjs var createCommentScript string diff --git a/pkg/workflow/js/create_comment.mjs b/pkg/workflow/js/create_comment.cjs similarity index 100% rename from pkg/workflow/js/create_comment.mjs rename to pkg/workflow/js/create_comment.cjs diff --git a/pkg/workflow/js/create_issue.mjs b/pkg/workflow/js/create_issue.cjs similarity index 100% rename from pkg/workflow/js/create_issue.mjs rename to pkg/workflow/js/create_issue.cjs diff --git a/pkg/workflow/js/create_pull_request.mjs b/pkg/workflow/js/create_pull_request.cjs similarity index 97% rename from pkg/workflow/js/create_pull_request.mjs rename to pkg/workflow/js/create_pull_request.cjs index c51958b45ed..889fbc22453 100644 --- a/pkg/workflow/js/create_pull_request.mjs +++ b/pkg/workflow/js/create_pull_request.cjs @@ -1,6 +1,6 @@ -import * as fs from "fs"; -import * as crypto from "crypto"; -import { execSync } from "child_process"; +const fs = require("fs"); +const crypto = require("crypto"); +const { execSync } = require("child_process"); async function main() { diff --git a/tsconfig.json b/tsconfig.json index a97cfa17118..9f2be05c623 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { "target": "es2022", - "module": "esnext", - "lib": ["es2022", "dom"], + "module": "es2022", + "lib": ["es2022"], "allowJs": true, "checkJs": true, "declaration": false, @@ -31,7 +31,10 @@ "typeRoots": ["./node_modules/@types", "./pkg/workflow/js/types"] }, "include": [ - "pkg/workflow/js/**/*" + "pkg/workflow/js/**/*.js", + "pkg/workflow/js/**/*.cjs", + "pkg/workflow/js/**/*.ts", + "pkg/workflow/js/**/*.d.ts" ], "exclude": [ "node_modules",