diff --git a/.github/workflows/test-claude.lock.yml b/.github/workflows/test-claude.lock.yml index cd6a49aa3a6..72eafd8d37d 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,33 @@ 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 + // 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(); - // 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 +745,22 @@ jobs: return; } + + let body = outputContent.trim(); + // Add AI disclaimer with run id, run htmlurl + 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:', 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 +813,11 @@ jobs: GITHUB_AW_PR_LABELS: "claude,automation,bot" with: script: | + const fs = require("fs"); + const crypto = require("crypto"); + const { execSync } = require("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 +887,11 @@ jobs: title = titlePrefix + title; } + // Add AI disclaimer with run id, run htmlurl + 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.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 87% rename from pkg/workflow/js/create_comment.mjs rename to pkg/workflow/js/create_comment.cjs index bc3997fa53b..1a619bd0bb8 100644 --- a/pkg/workflow/js/create_comment.mjs +++ b/pkg/workflow/js/create_comment.cjs @@ -49,15 +49,22 @@ async function main() { return; } + + let body = outputContent.trim(); + // Add AI disclaimer with run id, run htmlurl + 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:', 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.cjs similarity index 89% rename from pkg/workflow/js/create_issue.mjs rename to pkg/workflow/js/create_issue.cjs index 59a9a0b6d5f..ce0dece1954 100644 --- a/pkg/workflow/js/create_issue.mjs +++ b/pkg/workflow/js/create_issue.cjs @@ -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,33 @@ 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 + // 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(); - // 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.cjs similarity index 93% rename from pkg/workflow/js/create_pull_request.mjs rename to pkg/workflow/js/create_pull_request.cjs index bd57d9a13af..889fbc22453 100644 --- a/pkg/workflow/js/create_pull_request.mjs +++ b/pkg/workflow/js/create_pull_request.cjs @@ -1,8 +1,8 @@ +const fs = require("fs"); +const crypto = require("crypto"); +const { execSync } = require("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,11 @@ async function main() { title = titlePrefix + title; } + // Add AI disclaimer with run id, run htmlurl + 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/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",