diff --git a/.github/workflows/brave.lock.yml b/.github/workflows/brave.lock.yml index e7a666b451..a711976012 100644 --- a/.github/workflows/brave.lock.yml +++ b/.github/workflows/brave.lock.yml @@ -4117,8 +4117,17 @@ jobs: GITHUB_AW_WORKFLOW_NAME: "Brave Web Search Agent" with: script: | - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -4248,6 +4257,25 @@ jobs: context.eventName === "pull_request_review" || context.eventName === "pull_request_review_comment"; const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const repoUrl = getRepositoryUrl(); + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } if (commentTarget === "triggering" && !isIssueContext && !isPRContext && !isDiscussionContext) { core.info('Target is "triggering" but not running in issue, pull request, or discussion context, skipping comment creation'); return; @@ -4318,7 +4346,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL); + body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext); try { let comment; if (isDiscussion) { diff --git a/.github/workflows/ci-doctor.lock.yml b/.github/workflows/ci-doctor.lock.yml index 622ea278f7..838be78049 100644 --- a/.github/workflows/ci-doctor.lock.yml +++ b/.github/workflows/ci-doctor.lock.yml @@ -3518,8 +3518,17 @@ jobs: sanitized = sanitized.replace(/[<>&'"]/g, ""); return sanitized.trim(); } - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -3575,6 +3584,34 @@ jobs: return; } const parentIssueNumber = context.payload?.issue?.number; + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } const labelsEnv = process.env.GITHUB_AW_ISSUE_LABELS; let envLabels = labelsEnv ? labelsEnv @@ -3625,7 +3662,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL).trimEnd(), ""); + bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext).trimEnd(), ""); const body = bodyLines.join("\n").trim(); core.info(`Creating issue with title: ${title}`); core.info(`Labels: ${labels}`); @@ -3761,8 +3798,17 @@ jobs: GITHUB_AW_WORKFLOW_SOURCE_URL: "${{ github.server_url }}/githubnext/agentics/tree/main/workflows/ci-doctor.md" with: script: | - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -3892,6 +3938,25 @@ jobs: context.eventName === "pull_request_review" || context.eventName === "pull_request_review_comment"; const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const repoUrl = getRepositoryUrl(); + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } if (commentTarget === "triggering" && !isIssueContext && !isPRContext && !isDiscussionContext) { core.info('Target is "triggering" but not running in issue, pull request, or discussion context, skipping comment creation'); return; @@ -3962,7 +4027,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL); + body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext); try { let comment; if (isDiscussion) { diff --git a/.github/workflows/cli-version-checker.lock.yml b/.github/workflows/cli-version-checker.lock.yml index 1080c6b212..c422e4dfeb 100644 --- a/.github/workflows/cli-version-checker.lock.yml +++ b/.github/workflows/cli-version-checker.lock.yml @@ -3339,13 +3339,32 @@ jobs: if (titlePrefix && !title.startsWith(titlePrefix)) { title = titlePrefix + title; } + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringReference = ""; + if (isIssueContext && context.payload.issue) { + triggeringReference = ` for #${context.payload.issue.number}`; + } else if (isPRContext && context.payload.pull_request) { + triggeringReference = ` for #${context.payload.pull_request.number}`; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + const discussionUrl = `${repoUrl}/discussions/${context.payload.discussion.number}`; + triggeringReference = ` for [discussion #${context.payload.discussion.number}](${discussionUrl})`; + } const workflowName = process.env.GITHUB_AW_WORKFLOW_NAME || "Workflow"; const runId = context.runId; const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, `> AI generated by [${workflowName}](${runUrl})`, ""); + bodyLines.push(``, ``, `> AI generated by [${workflowName}](${runUrl})${triggeringReference}`, ""); const body = bodyLines.join("\n").trim(); const labelsEnv = process.env.GITHUB_AW_PR_LABELS; const labels = labelsEnv diff --git a/.github/workflows/dev.lock.yml b/.github/workflows/dev.lock.yml index 04fdbff9f3..e85b5a33cb 100644 --- a/.github/workflows/dev.lock.yml +++ b/.github/workflows/dev.lock.yml @@ -3352,8 +3352,17 @@ jobs: sanitized = sanitized.replace(/[<>&'"]/g, ""); return sanitized.trim(); } - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -3409,6 +3418,34 @@ jobs: return; } const parentIssueNumber = context.payload?.issue?.number; + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } const labelsEnv = process.env.GITHUB_AW_ISSUE_LABELS; let envLabels = labelsEnv ? labelsEnv @@ -3459,7 +3496,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL).trimEnd(), ""); + bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext).trimEnd(), ""); const body = bodyLines.join("\n").trim(); core.info(`Creating issue with title: ${title}`); core.info(`Labels: ${labels}`); diff --git a/.github/workflows/duplicate-code-detector.lock.yml b/.github/workflows/duplicate-code-detector.lock.yml index 590911b752..f38baed5f3 100644 --- a/.github/workflows/duplicate-code-detector.lock.yml +++ b/.github/workflows/duplicate-code-detector.lock.yml @@ -3036,8 +3036,17 @@ jobs: sanitized = sanitized.replace(/[<>&'"]/g, ""); return sanitized.trim(); } - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -3093,6 +3102,34 @@ jobs: return; } const parentIssueNumber = context.payload?.issue?.number; + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } const labelsEnv = process.env.GITHUB_AW_ISSUE_LABELS; let envLabels = labelsEnv ? labelsEnv @@ -3143,7 +3180,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL).trimEnd(), ""); + bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext).trimEnd(), ""); const body = bodyLines.join("\n").trim(); core.info(`Creating issue with title: ${title}`); core.info(`Labels: ${labels}`); diff --git a/.github/workflows/example-workflow-analyzer.lock.yml b/.github/workflows/example-workflow-analyzer.lock.yml index e9eb954ae4..f260d808ad 100644 --- a/.github/workflows/example-workflow-analyzer.lock.yml +++ b/.github/workflows/example-workflow-analyzer.lock.yml @@ -3006,8 +3006,17 @@ jobs: sanitized = sanitized.replace(/[<>&'"]/g, ""); return sanitized.trim(); } - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -3063,6 +3072,34 @@ jobs: return; } const parentIssueNumber = context.payload?.issue?.number; + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } const labelsEnv = process.env.GITHUB_AW_ISSUE_LABELS; let envLabels = labelsEnv ? labelsEnv @@ -3113,7 +3150,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL).trimEnd(), ""); + bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext).trimEnd(), ""); const body = bodyLines.join("\n").trim(); core.info(`Creating issue with title: ${title}`); core.info(`Labels: ${labels}`); diff --git a/.github/workflows/go-pattern-detector.lock.yml b/.github/workflows/go-pattern-detector.lock.yml index 7f715beda2..6932492d7a 100644 --- a/.github/workflows/go-pattern-detector.lock.yml +++ b/.github/workflows/go-pattern-detector.lock.yml @@ -3122,8 +3122,17 @@ jobs: sanitized = sanitized.replace(/[<>&'"]/g, ""); return sanitized.trim(); } - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -3179,6 +3188,34 @@ jobs: return; } const parentIssueNumber = context.payload?.issue?.number; + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } const labelsEnv = process.env.GITHUB_AW_ISSUE_LABELS; let envLabels = labelsEnv ? labelsEnv @@ -3229,7 +3266,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL).trimEnd(), ""); + bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext).trimEnd(), ""); const body = bodyLines.join("\n").trim(); core.info(`Creating issue with title: ${title}`); core.info(`Labels: ${labels}`); diff --git a/.github/workflows/pdf-summary.lock.yml b/.github/workflows/pdf-summary.lock.yml index 8dabdf6344..1f209c120f 100644 --- a/.github/workflows/pdf-summary.lock.yml +++ b/.github/workflows/pdf-summary.lock.yml @@ -4071,8 +4071,17 @@ jobs: GITHUB_AW_WORKFLOW_NAME: "Resource Summarizer Agent" with: script: | - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -4202,6 +4211,25 @@ jobs: context.eventName === "pull_request_review" || context.eventName === "pull_request_review_comment"; const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const repoUrl = getRepositoryUrl(); + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } if (commentTarget === "triggering" && !isIssueContext && !isPRContext && !isDiscussionContext) { core.info('Target is "triggering" but not running in issue, pull request, or discussion context, skipping comment creation'); return; @@ -4272,7 +4300,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL); + body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext); try { let comment; if (isDiscussion) { diff --git a/.github/workflows/plan.lock.yml b/.github/workflows/plan.lock.yml index 1bc51e0fc0..007d9441b6 100644 --- a/.github/workflows/plan.lock.yml +++ b/.github/workflows/plan.lock.yml @@ -3958,8 +3958,17 @@ jobs: sanitized = sanitized.replace(/[<>&'"]/g, ""); return sanitized.trim(); } - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -4015,6 +4024,34 @@ jobs: return; } const parentIssueNumber = context.payload?.issue?.number; + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } const labelsEnv = process.env.GITHUB_AW_ISSUE_LABELS; let envLabels = labelsEnv ? labelsEnv @@ -4065,7 +4102,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL).trimEnd(), ""); + bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext).trimEnd(), ""); const body = bodyLines.join("\n").trim(); core.info(`Creating issue with title: ${title}`); core.info(`Labels: ${labels}`); diff --git a/.github/workflows/poem-bot.lock.yml b/.github/workflows/poem-bot.lock.yml index 14acfb09dd..8651c31ab0 100644 --- a/.github/workflows/poem-bot.lock.yml +++ b/.github/workflows/poem-bot.lock.yml @@ -4110,8 +4110,17 @@ jobs: sanitized = sanitized.replace(/[<>&'"]/g, ""); return sanitized.trim(); } - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -4167,6 +4176,34 @@ jobs: return; } const parentIssueNumber = context.payload?.issue?.number; + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } const labelsEnv = process.env.GITHUB_AW_ISSUE_LABELS; let envLabels = labelsEnv ? labelsEnv @@ -4217,7 +4254,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL).trimEnd(), ""); + bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext).trimEnd(), ""); const body = bodyLines.join("\n").trim(); core.info(`Creating issue with title: ${title}`); core.info(`Labels: ${labels}`); @@ -4351,8 +4388,17 @@ jobs: GITHUB_AW_SAFE_OUTPUTS_STAGED: "true" with: script: | - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -4482,6 +4528,25 @@ jobs: context.eventName === "pull_request_review" || context.eventName === "pull_request_review_comment"; const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const repoUrl = getRepositoryUrl(); + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } if (commentTarget === "triggering" && !isIssueContext && !isPRContext && !isDiscussionContext) { core.info('Target is "triggering" but not running in issue, pull request, or discussion context, skipping comment creation'); return; @@ -4552,7 +4617,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL); + body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext); try { let comment; if (isDiscussion) { @@ -4621,8 +4686,17 @@ jobs: GITHUB_AW_SAFE_OUTPUTS_STAGED: "true" with: script: | - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -4707,6 +4781,13 @@ jobs: context.eventName === "pull_request_review" || context.eventName === "pull_request_review_comment" || (context.eventName === "issue_comment" && context.payload.issue && context.payload.issue.pull_request); + let triggeringContext = undefined; + if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } if (commentTarget === "triggering" && !isPRContext) { core.info('Target is "triggering" but not running in pull request context, skipping review comment creation'); return; @@ -4811,7 +4892,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL); + body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext); core.info( `Creating review comment on PR #${pullRequestNumber} at ${commentItem.path}:${line}${startLine ? ` (lines ${startLine}-${line})` : ""} [${side}]` ); @@ -5075,13 +5156,32 @@ jobs: if (titlePrefix && !title.startsWith(titlePrefix)) { title = titlePrefix + title; } + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringReference = ""; + if (isIssueContext && context.payload.issue) { + triggeringReference = ` for #${context.payload.issue.number}`; + } else if (isPRContext && context.payload.pull_request) { + triggeringReference = ` for #${context.payload.pull_request.number}`; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + const discussionUrl = `${repoUrl}/discussions/${context.payload.discussion.number}`; + triggeringReference = ` for [discussion #${context.payload.discussion.number}](${discussionUrl})`; + } const workflowName = process.env.GITHUB_AW_WORKFLOW_NAME || "Workflow"; const runId = context.runId; const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, `> AI generated by [${workflowName}](${runUrl})`, ""); + bodyLines.push(``, ``, `> AI generated by [${workflowName}](${runUrl})${triggeringReference}`, ""); const body = bodyLines.join("\n").trim(); const labelsEnv = process.env.GITHUB_AW_PR_LABELS; const labels = labelsEnv diff --git a/.github/workflows/q.lock.yml b/.github/workflows/q.lock.yml index 8f34d64a8d..8428338835 100644 --- a/.github/workflows/q.lock.yml +++ b/.github/workflows/q.lock.yml @@ -4617,13 +4617,32 @@ jobs: if (titlePrefix && !title.startsWith(titlePrefix)) { title = titlePrefix + title; } + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringReference = ""; + if (isIssueContext && context.payload.issue) { + triggeringReference = ` for #${context.payload.issue.number}`; + } else if (isPRContext && context.payload.pull_request) { + triggeringReference = ` for #${context.payload.pull_request.number}`; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + const discussionUrl = `${repoUrl}/discussions/${context.payload.discussion.number}`; + triggeringReference = ` for [discussion #${context.payload.discussion.number}](${discussionUrl})`; + } const workflowName = process.env.GITHUB_AW_WORKFLOW_NAME || "Workflow"; const runId = context.runId; const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, `> AI generated by [${workflowName}](${runUrl})`, ""); + bodyLines.push(``, ``, `> AI generated by [${workflowName}](${runUrl})${triggeringReference}`, ""); const body = bodyLines.join("\n").trim(); const labelsEnv = process.env.GITHUB_AW_PR_LABELS; const labels = labelsEnv diff --git a/.github/workflows/scout.lock.yml b/.github/workflows/scout.lock.yml index fbe48af7d5..c209bce1dd 100644 --- a/.github/workflows/scout.lock.yml +++ b/.github/workflows/scout.lock.yml @@ -4439,8 +4439,17 @@ jobs: GITHUB_AW_WORKFLOW_NAME: "Scout" with: script: | - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -4570,6 +4579,25 @@ jobs: context.eventName === "pull_request_review" || context.eventName === "pull_request_review_comment"; const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const repoUrl = getRepositoryUrl(); + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } if (commentTarget === "triggering" && !isIssueContext && !isPRContext && !isDiscussionContext) { core.info('Target is "triggering" but not running in issue, pull request, or discussion context, skipping comment creation'); return; @@ -4640,7 +4668,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL); + body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext); try { let comment; if (isDiscussion) { diff --git a/.github/workflows/security-fix-pr.lock.yml b/.github/workflows/security-fix-pr.lock.yml index 40e33e517f..13955e353f 100644 --- a/.github/workflows/security-fix-pr.lock.yml +++ b/.github/workflows/security-fix-pr.lock.yml @@ -3427,13 +3427,32 @@ jobs: if (titlePrefix && !title.startsWith(titlePrefix)) { title = titlePrefix + title; } + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringReference = ""; + if (isIssueContext && context.payload.issue) { + triggeringReference = ` for #${context.payload.issue.number}`; + } else if (isPRContext && context.payload.pull_request) { + triggeringReference = ` for #${context.payload.pull_request.number}`; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + const discussionUrl = `${repoUrl}/discussions/${context.payload.discussion.number}`; + triggeringReference = ` for [discussion #${context.payload.discussion.number}](${discussionUrl})`; + } const workflowName = process.env.GITHUB_AW_WORKFLOW_NAME || "Workflow"; const runId = context.runId; const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, `> AI generated by [${workflowName}](${runUrl})`, ""); + bodyLines.push(``, ``, `> AI generated by [${workflowName}](${runUrl})${triggeringReference}`, ""); const body = bodyLines.join("\n").trim(); const labelsEnv = process.env.GITHUB_AW_PR_LABELS; const labels = labelsEnv diff --git a/.github/workflows/smoke-claude.lock.yml b/.github/workflows/smoke-claude.lock.yml index 6980374674..5170e34e38 100644 --- a/.github/workflows/smoke-claude.lock.yml +++ b/.github/workflows/smoke-claude.lock.yml @@ -2964,8 +2964,17 @@ jobs: sanitized = sanitized.replace(/[<>&'"]/g, ""); return sanitized.trim(); } - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -3021,6 +3030,34 @@ jobs: return; } const parentIssueNumber = context.payload?.issue?.number; + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } const labelsEnv = process.env.GITHUB_AW_ISSUE_LABELS; let envLabels = labelsEnv ? labelsEnv @@ -3071,7 +3108,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL).trimEnd(), ""); + bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext).trimEnd(), ""); const body = bodyLines.join("\n").trim(); core.info(`Creating issue with title: ${title}`); core.info(`Labels: ${labels}`); diff --git a/.github/workflows/smoke-codex.lock.yml b/.github/workflows/smoke-codex.lock.yml index 89c7505b54..8d85469073 100644 --- a/.github/workflows/smoke-codex.lock.yml +++ b/.github/workflows/smoke-codex.lock.yml @@ -2782,8 +2782,17 @@ jobs: sanitized = sanitized.replace(/[<>&'"]/g, ""); return sanitized.trim(); } - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -2839,6 +2848,34 @@ jobs: return; } const parentIssueNumber = context.payload?.issue?.number; + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } const labelsEnv = process.env.GITHUB_AW_ISSUE_LABELS; let envLabels = labelsEnv ? labelsEnv @@ -2889,7 +2926,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL).trimEnd(), ""); + bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext).trimEnd(), ""); const body = bodyLines.join("\n").trim(); core.info(`Creating issue with title: ${title}`); core.info(`Labels: ${labels}`); diff --git a/.github/workflows/smoke-copilot.lock.yml b/.github/workflows/smoke-copilot.lock.yml index 5fd15eef25..99c4f0f183 100644 --- a/.github/workflows/smoke-copilot.lock.yml +++ b/.github/workflows/smoke-copilot.lock.yml @@ -3350,8 +3350,17 @@ jobs: sanitized = sanitized.replace(/[<>&'"]/g, ""); return sanitized.trim(); } - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -3407,6 +3416,34 @@ jobs: return; } const parentIssueNumber = context.payload?.issue?.number; + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } const labelsEnv = process.env.GITHUB_AW_ISSUE_LABELS; let envLabels = labelsEnv ? labelsEnv @@ -3457,7 +3494,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL).trimEnd(), ""); + bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext).trimEnd(), ""); const body = bodyLines.join("\n").trim(); core.info(`Creating issue with title: ${title}`); core.info(`Labels: ${labels}`); diff --git a/.github/workflows/smoke-genaiscript.lock.yml b/.github/workflows/smoke-genaiscript.lock.yml index fef8fa5e17..dac162cb7f 100644 --- a/.github/workflows/smoke-genaiscript.lock.yml +++ b/.github/workflows/smoke-genaiscript.lock.yml @@ -2143,8 +2143,17 @@ jobs: sanitized = sanitized.replace(/[<>&'"]/g, ""); return sanitized.trim(); } - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -2200,6 +2209,34 @@ jobs: return; } const parentIssueNumber = context.payload?.issue?.number; + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } const labelsEnv = process.env.GITHUB_AW_ISSUE_LABELS; let envLabels = labelsEnv ? labelsEnv @@ -2250,7 +2287,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL).trimEnd(), ""); + bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext).trimEnd(), ""); const body = bodyLines.join("\n").trim(); core.info(`Creating issue with title: ${title}`); core.info(`Labels: ${labels}`); diff --git a/.github/workflows/smoke-opencode.lock.yml b/.github/workflows/smoke-opencode.lock.yml index fa6eec16c4..e9ee37a387 100644 --- a/.github/workflows/smoke-opencode.lock.yml +++ b/.github/workflows/smoke-opencode.lock.yml @@ -2111,8 +2111,17 @@ jobs: sanitized = sanitized.replace(/[<>&'"]/g, ""); return sanitized.trim(); } - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -2168,6 +2177,34 @@ jobs: return; } const parentIssueNumber = context.payload?.issue?.number; + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } const labelsEnv = process.env.GITHUB_AW_ISSUE_LABELS; let envLabels = labelsEnv ? labelsEnv @@ -2218,7 +2255,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL).trimEnd(), ""); + bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext).trimEnd(), ""); const body = bodyLines.join("\n").trim(); core.info(`Creating issue with title: ${title}`); core.info(`Labels: ${labels}`); diff --git a/.github/workflows/technical-doc-writer.lock.yml b/.github/workflows/technical-doc-writer.lock.yml index 9924d8dd0e..e47cba7dc6 100644 --- a/.github/workflows/technical-doc-writer.lock.yml +++ b/.github/workflows/technical-doc-writer.lock.yml @@ -3328,8 +3328,17 @@ jobs: GITHUB_AW_WORKFLOW_NAME: "Technical Documentation Writer for GitHub Actions" with: script: | - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -3459,6 +3468,25 @@ jobs: context.eventName === "pull_request_review" || context.eventName === "pull_request_review_comment"; const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const repoUrl = getRepositoryUrl(); + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } if (commentTarget === "triggering" && !isIssueContext && !isPRContext && !isDiscussionContext) { core.info('Target is "triggering" but not running in issue, pull request, or discussion context, skipping comment creation'); return; @@ -3529,7 +3557,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL); + body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext); try { let comment; if (isDiscussion) { @@ -3791,13 +3819,32 @@ jobs: if (titlePrefix && !title.startsWith(titlePrefix)) { title = titlePrefix + title; } + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringReference = ""; + if (isIssueContext && context.payload.issue) { + triggeringReference = ` for #${context.payload.issue.number}`; + } else if (isPRContext && context.payload.pull_request) { + triggeringReference = ` for #${context.payload.pull_request.number}`; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + const discussionUrl = `${repoUrl}/discussions/${context.payload.discussion.number}`; + triggeringReference = ` for [discussion #${context.payload.discussion.number}](${discussionUrl})`; + } const workflowName = process.env.GITHUB_AW_WORKFLOW_NAME || "Workflow"; const runId = context.runId; const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, `> AI generated by [${workflowName}](${runUrl})`, ""); + bodyLines.push(``, ``, `> AI generated by [${workflowName}](${runUrl})${triggeringReference}`, ""); const body = bodyLines.join("\n").trim(); const labelsEnv = process.env.GITHUB_AW_PR_LABELS; const labels = labelsEnv diff --git a/.github/workflows/tidy.lock.yml b/.github/workflows/tidy.lock.yml index 71fdbf0577..9a71684ee4 100644 --- a/.github/workflows/tidy.lock.yml +++ b/.github/workflows/tidy.lock.yml @@ -4081,13 +4081,32 @@ jobs: if (titlePrefix && !title.startsWith(titlePrefix)) { title = titlePrefix + title; } + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringReference = ""; + if (isIssueContext && context.payload.issue) { + triggeringReference = ` for #${context.payload.issue.number}`; + } else if (isPRContext && context.payload.pull_request) { + triggeringReference = ` for #${context.payload.pull_request.number}`; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + const discussionUrl = `${repoUrl}/discussions/${context.payload.discussion.number}`; + triggeringReference = ` for [discussion #${context.payload.discussion.number}](${discussionUrl})`; + } const workflowName = process.env.GITHUB_AW_WORKFLOW_NAME || "Workflow"; const runId = context.runId; const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, `> AI generated by [${workflowName}](${runUrl})`, ""); + bodyLines.push(``, ``, `> AI generated by [${workflowName}](${runUrl})${triggeringReference}`, ""); const body = bodyLines.join("\n").trim(); const labelsEnv = process.env.GITHUB_AW_PR_LABELS; const labels = labelsEnv diff --git a/.github/workflows/unbloat-docs.lock.yml b/.github/workflows/unbloat-docs.lock.yml index c3fc33f000..2525756d25 100644 --- a/.github/workflows/unbloat-docs.lock.yml +++ b/.github/workflows/unbloat-docs.lock.yml @@ -3658,8 +3658,17 @@ jobs: GITHUB_AW_WORKFLOW_NAME: "Documentation Unbloat" with: script: | - function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { + function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -3789,6 +3798,25 @@ jobs: context.eventName === "pull_request_review" || context.eventName === "pull_request_review_comment"; const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const repoUrl = getRepositoryUrl(); + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } if (commentTarget === "triggering" && !isIssueContext && !isPRContext && !isDiscussionContext) { core.info('Target is "triggering" but not running in issue, pull request, or discussion context, skipping comment creation'); return; @@ -3859,7 +3887,7 @@ jobs: const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL); + body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext); try { let comment; if (isDiscussion) { @@ -4121,13 +4149,32 @@ jobs: if (titlePrefix && !title.startsWith(titlePrefix)) { title = titlePrefix + title; } + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + let triggeringReference = ""; + if (isIssueContext && context.payload.issue) { + triggeringReference = ` for #${context.payload.issue.number}`; + } else if (isPRContext && context.payload.pull_request) { + triggeringReference = ` for #${context.payload.pull_request.number}`; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + const discussionUrl = `${repoUrl}/discussions/${context.payload.discussion.number}`; + triggeringReference = ` for [discussion #${context.payload.discussion.number}](${discussionUrl})`; + } const workflowName = process.env.GITHUB_AW_WORKFLOW_NAME || "Workflow"; const runId = context.runId; const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, `> AI generated by [${workflowName}](${runUrl})`, ""); + bodyLines.push(``, ``, `> AI generated by [${workflowName}](${runUrl})${triggeringReference}`, ""); const body = bodyLines.join("\n").trim(); const labelsEnv = process.env.GITHUB_AW_PR_LABELS; const labels = labelsEnv diff --git a/pkg/workflow/js/add_comment.cjs b/pkg/workflow/js/add_comment.cjs index 5a88640c4b..a04a28bac2 100644 --- a/pkg/workflow/js/add_comment.cjs +++ b/pkg/workflow/js/add_comment.cjs @@ -4,11 +4,26 @@ * @param {string} runUrl - URL of the workflow run * @param {string} workflowSource - Source of the workflow (owner/repo/path@ref) * @param {string} workflowSourceURL - GitHub URL for the workflow source + * @param {object} [triggeringContext] - Context about what triggered the workflow (optional, can be null) + * @param {string} triggeringContext.type - Type of trigger: 'issue', 'pull_request', or 'discussion' + * @param {number} triggeringContext.number - Number of the triggering item + * @param {string} [triggeringContext.url] - URL for discussions (optional) * @returns {string} Footer text */ -function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { +function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + // Add triggering reference if available + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } + if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -188,6 +203,27 @@ async function main() { context.eventName === "pull_request_review_comment"; const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + // Determine triggering context for footer + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const repoUrl = getRepositoryUrl(); + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } + // Validate context based on target configuration if (commentTarget === "triggering" && !isIssueContext && !isPRContext && !isDiscussionContext) { core.info('Target is "triggering" but not running in issue, pull request, or discussion context, skipping comment creation'); @@ -272,7 +308,7 @@ async function main() { const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL); + body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext); try { let comment; diff --git a/pkg/workflow/js/create_issue.cjs b/pkg/workflow/js/create_issue.cjs index 4519e92f37..e802ce15c5 100644 --- a/pkg/workflow/js/create_issue.cjs +++ b/pkg/workflow/js/create_issue.cjs @@ -19,11 +19,26 @@ function sanitizeLabelContent(content) { * @param {string} runUrl - URL of the workflow run * @param {string} workflowSource - Source of the workflow (owner/repo/path@ref) * @param {string} workflowSourceURL - GitHub URL for the workflow source + * @param {object} [triggeringContext] - Context about what triggered the workflow (optional, can be null) + * @param {string} triggeringContext.type - Type of trigger: 'issue', 'pull_request', or 'discussion' + * @param {number} triggeringContext.number - Number of the triggering item + * @param {string} [triggeringContext.url] - URL for discussions (optional) * @returns {string} Footer text */ -function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { +function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + // Add triggering reference if available + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } + if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -81,6 +96,38 @@ async function main() { return; } const parentIssueNumber = context.payload?.issue?.number; + + // Determine triggering context for footer + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + + let triggeringContext = undefined; + if (isIssueContext && context.payload.issue) { + triggeringContext = { + type: "issue", + number: context.payload.issue.number, + }; + } else if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + triggeringContext = { + type: "discussion", + number: context.payload.discussion.number, + url: `${repoUrl}/discussions/${context.payload.discussion.number}`, + }; + } + const labelsEnv = process.env.GITHUB_AW_ISSUE_LABELS; let envLabels = labelsEnv ? labelsEnv @@ -132,7 +179,7 @@ async function main() { const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL).trimEnd(), ""); + bodyLines.push(``, ``, generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext).trimEnd(), ""); const body = bodyLines.join("\n").trim(); core.info(`Creating issue with title: ${title}`); core.info(`Labels: ${labels}`); diff --git a/pkg/workflow/js/create_issue.test.cjs b/pkg/workflow/js/create_issue.test.cjs index 974331c2aa..f9cdce3600 100644 --- a/pkg/workflow/js/create_issue.test.cjs +++ b/pkg/workflow/js/create_issue.test.cjs @@ -603,4 +603,118 @@ describe("create_issue.cjs", () => { expect(callArgs.body).not.toContain("gh aw add"); expect(callArgs.body).not.toContain("usage guide"); }); + + it("should include triggering issue reference in footer when triggered by issue", async () => { + // Set up issue context + global.context.eventName = "issues"; + global.context.payload = { + repository: { + html_url: "https://github.com/testowner/testrepo", + }, + issue: { + number: 42, + }, + }; + + process.env.GITHUB_AW_AGENT_OUTPUT = JSON.stringify({ + items: [ + { + type: "create_issue", + title: "Related Issue", + body: "This issue is related to the triggering issue", + }, + ], + }); + + const mockIssue = { + number: 100, + html_url: "https://github.com/testowner/testrepo/issues/100", + }; + + mockGithub.rest.issues.create.mockResolvedValue({ data: mockIssue }); + + // Execute the script + await eval(`(async () => { ${createIssueScript} })()`); + + const callArgs = mockGithub.rest.issues.create.mock.calls[0][0]; + + // Check that the footer includes the triggering issue reference + expect(callArgs.body).toContain("AI generated by"); + expect(callArgs.body).toContain("for #42"); + }); + + it("should include triggering PR reference in footer when triggered by pull request", async () => { + // Set up PR context + global.context.eventName = "pull_request"; + global.context.payload = { + repository: { + html_url: "https://github.com/testowner/testrepo", + }, + pull_request: { + number: 123, + }, + }; + + process.env.GITHUB_AW_AGENT_OUTPUT = JSON.stringify({ + items: [ + { + type: "create_issue", + title: "PR Related Issue", + body: "This issue is related to the triggering PR", + }, + ], + }); + + const mockIssue = { + number: 200, + html_url: "https://github.com/testowner/testrepo/issues/200", + }; + + mockGithub.rest.issues.create.mockResolvedValue({ data: mockIssue }); + + // Execute the script + await eval(`(async () => { ${createIssueScript} })()`); + + const callArgs = mockGithub.rest.issues.create.mock.calls[0][0]; + + // Check that the footer includes the triggering PR reference + expect(callArgs.body).toContain("AI generated by"); + expect(callArgs.body).toContain("for #123"); + }); + + it("should not include triggering reference when not triggered by issue/PR/discussion", async () => { + // Set up non-triggering context (e.g., push event) + global.context.eventName = "push"; + global.context.payload = { + repository: { + html_url: "https://github.com/testowner/testrepo", + }, + }; + + process.env.GITHUB_AW_AGENT_OUTPUT = JSON.stringify({ + items: [ + { + type: "create_issue", + title: "Scheduled Issue", + body: "This issue is not triggered by an issue/PR", + }, + ], + }); + + const mockIssue = { + number: 300, + html_url: "https://github.com/testowner/testrepo/issues/300", + }; + + mockGithub.rest.issues.create.mockResolvedValue({ data: mockIssue }); + + // Execute the script + await eval(`(async () => { ${createIssueScript} })()`); + + const callArgs = mockGithub.rest.issues.create.mock.calls[0][0]; + + // Check that the footer does NOT include triggering reference + expect(callArgs.body).toContain("AI generated by"); + expect(callArgs.body).not.toMatch(/for #\d+/); + }); }); diff --git a/pkg/workflow/js/create_pr_review_comment.cjs b/pkg/workflow/js/create_pr_review_comment.cjs index c114daa50e..4d9fdf1f5d 100644 --- a/pkg/workflow/js/create_pr_review_comment.cjs +++ b/pkg/workflow/js/create_pr_review_comment.cjs @@ -4,11 +4,26 @@ * @param {string} runUrl - URL of the workflow run * @param {string} workflowSource - Source of the workflow (owner/repo/path@ref) * @param {string} workflowSourceURL - GitHub URL for the workflow source + * @param {object} [triggeringContext] - Context about what triggered the workflow (optional, can be null) + * @param {string} triggeringContext.type - Type of trigger: 'issue', 'pull_request', or 'discussion' + * @param {number} triggeringContext.number - Number of the triggering item + * @param {string} [triggeringContext.url] - URL for discussions (optional) * @returns {string} Footer text */ -function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL) { +function generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext) { let footer = `\n\n> AI generated by [${workflowName}](${runUrl})`; + // Add triggering reference if available + if (triggeringContext && triggeringContext.number) { + if (triggeringContext.type === "discussion" && triggeringContext.url) { + footer += ` for [discussion #${triggeringContext.number}](${triggeringContext.url})`; + } else if (triggeringContext.type === "pull_request") { + footer += ` for #${triggeringContext.number}`; + } else if (triggeringContext.type === "issue") { + footer += ` for #${triggeringContext.number}`; + } + } + if (workflowSource && workflowSourceURL) { footer += `\n>\n> To add this workflow in your repository, run \`gh aw add ${workflowSource}\`. See [usage guide](https://githubnext.github.io/gh-aw/tools/cli/).`; } @@ -125,6 +140,15 @@ async function main() { context.eventName === "pull_request_review_comment" || (context.eventName === "issue_comment" && context.payload.issue && context.payload.issue.pull_request); + // Determine triggering context for footer + let triggeringContext = undefined; + if (isPRContext && context.payload.pull_request) { + triggeringContext = { + type: "pull_request", + number: context.payload.pull_request.number, + }; + } + // Validate context based on target configuration if (commentTarget === "triggering" && !isPRContext) { core.info('Target is "triggering" but not running in pull request context, skipping review comment creation'); @@ -258,7 +282,7 @@ async function main() { const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL); + body += generateFooter(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringContext); core.info( `Creating review comment on PR #${pullRequestNumber} at ${commentItem.path}:${line}${startLine ? ` (lines ${startLine}-${line})` : ""} [${side}]` diff --git a/pkg/workflow/js/create_pull_request.cjs b/pkg/workflow/js/create_pull_request.cjs index 24bd2caff6..d476a35c34 100644 --- a/pkg/workflow/js/create_pull_request.cjs +++ b/pkg/workflow/js/create_pull_request.cjs @@ -241,6 +241,28 @@ async function main() { title = titlePrefix + title; } + // Determine triggering context for footer + const isIssueContext = context.eventName === "issues" || context.eventName === "issue_comment"; + const isPRContext = + context.eventName === "pull_request" || + context.eventName === "pull_request_review" || + context.eventName === "pull_request_review_comment"; + const isDiscussionContext = context.eventName === "discussion" || context.eventName === "discussion_comment"; + + let triggeringReference = ""; + if (isIssueContext && context.payload.issue) { + triggeringReference = ` for #${context.payload.issue.number}`; + } else if (isPRContext && context.payload.pull_request) { + triggeringReference = ` for #${context.payload.pull_request.number}`; + } else if (isDiscussionContext && context.payload.discussion) { + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + const repoUrl = context.payload.repository + ? context.payload.repository.html_url + : `${githubServer}/${context.repo.owner}/${context.repo.repo}`; + const discussionUrl = `${repoUrl}/discussions/${context.payload.discussion.number}`; + triggeringReference = ` for [discussion #${context.payload.discussion.number}](${discussionUrl})`; + } + // Add AI disclaimer with workflow name and run url const workflowName = process.env.GITHUB_AW_WORKFLOW_NAME || "Workflow"; const runId = context.runId; @@ -248,7 +270,7 @@ async function main() { const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${runId}` : `${githubServer}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`; - bodyLines.push(``, ``, `> AI generated by [${workflowName}](${runUrl})`, ""); + bodyLines.push(``, ``, `> AI generated by [${workflowName}](${runUrl})${triggeringReference}`, ""); // Prepare the body content const body = bodyLines.join("\n").trim();