Skip to content

Add job dependencies and environment variables to add_comment for referencing created items#2006

Merged
pelikhan merged 4 commits intomainfrom
copilot/add-comment-environment-variables
Oct 20, 2025
Merged

Add job dependencies and environment variables to add_comment for referencing created items#2006
pelikhan merged 4 commits intomainfrom
copilot/add-comment-environment-variables

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 19, 2025

Implementation Complete: add_comment Job Dependencies

This PR implements the requirement that the add_comment job should depend on (needs) the create_issue, create_discussion, and create_pull_request jobs if they are created, and pass their output URLs as environment variables.

Changes Completed:

  • Understand current codebase structure
  • Modify buildCreateOutputAddCommentJob to add conditional job dependencies
  • Pass output URLs from create_issue, create_discussion, create_pull_request jobs as environment variables to add_comment step
  • Update add_comment.cjs JavaScript to use the new environment variables
  • Add tests for the new functionality
  • Verify compilation and test the changes
  • Run final validation with make agent-finish
  • Initialize outputs in create_issue.cjs, create_discussion.cjs, and create_pull_request.cjs to ensure they're always set

Implementation Details:

1. Job Dependencies:

  • The add_comment job now depends on create_issue, create_discussion, and create_pull_request jobs when they exist
  • Dependencies are added conditionally based on which jobs are created in the workflow
  • Example: A workflow with all three safe outputs will have add_comment depend on all three jobs

2. Environment Variables:
The following environment variables are now passed to the add_comment JavaScript step:

  • GITHUB_AW_CREATED_ISSUE_URL - URL of the created issue
  • GITHUB_AW_CREATED_ISSUE_NUMBER - Number of the created issue
  • GITHUB_AW_CREATED_DISCUSSION_URL - URL of the created discussion
  • GITHUB_AW_CREATED_DISCUSSION_NUMBER - Number of the created discussion
  • GITHUB_AW_CREATED_PULL_REQUEST_URL - URL of the created pull request
  • GITHUB_AW_CREATED_PULL_REQUEST_NUMBER - Number of the created pull request

3. JavaScript Changes:

  • The add_comment.cjs script now appends a "Related Items" section to comments when any of the above URLs are available
  • The section includes markdown links to the created issues, discussions, and pull requests
  • Also updated staged mode preview to show the related items

4. Output Initialization:

  • create_issue.cjs: Initializes issue_number and issue_url outputs at the start
  • create_discussion.cjs: Initializes discussion_number and discussion_url outputs at the start
  • create_pull_request.cjs: Initializes all PR-related outputs at the start
  • This ensures outputs are always set, preventing undefined values when scripts exit early

5. Job Ordering:

  • Reordered the job creation in compiler.go to build create_pull_request before add_comment so the dependency can be established

6. Test Coverage:

  • Added add_comment_dependencies_test.go with comprehensive test cases covering all combinations of job dependencies
  • Updated existing tests to work with the new function signature
  • All tests pass successfully

Example Output:

When a workflow has create-issue, create-discussion, and create-pull-request configured along with add-comment, the generated workflow will:

  1. Create dependencies in the add_comment job:
add_comment:
  needs:
    - agent
    - create_issue
    - create_discussion
    - create_pull_request
    - detection
  1. Pass environment variables:
env:
  GITHUB_AW_CREATED_ISSUE_URL: ${{ needs.create_issue.outputs.issue_url }}
  GITHUB_AW_CREATED_ISSUE_NUMBER: ${{ needs.create_issue.outputs.issue_number }}
  GITHUB_AW_CREATED_DISCUSSION_URL: ${{ needs.create_discussion.outputs.discussion_url }}
  GITHUB_AW_CREATED_DISCUSSION_NUMBER: ${{ needs.create_discussion.outputs.discussion_number }}
  GITHUB_AW_CREATED_PULL_REQUEST_URL: ${{ needs.create_pull_request.outputs.pull_request_url }}
  GITHUB_AW_CREATED_PULL_REQUEST_NUMBER: ${{ needs.create_pull_request.outputs.pull_request_number }}
  1. Append a "Related Items" section to the comment:
## Related Items

- Issue: [#123](https://github.com/owner/repo/issues/123)
- Discussion: [#456](https://github.com/owner/repo/discussions/456)
- Pull Request: [#789](https://github.com/owner/repo/pull/789)

Validation:

  • ✅ All unit tests pass
  • ✅ Linting passes
  • ✅ Code formatting applied
  • ✅ All 66 workflow files compile successfully with make agent-finish
  • ✅ Outputs are properly initialized in all safe output job scripts
Original prompt

The "add_comment" job should needs the "create_issue", "create_discussion", "create_pull_request" jobs if they are created.

The output of those jobs (issue url or pull request url) should be passed as environment variables to the add_comment JavaScript step so that the generated comment can reference those URLs in the markdown.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Modified buildCreateOutputAddCommentJob to accept createIssueJobName, createDiscussionJobName, and createPullRequestJobName parameters
- Added conditional job dependencies based on which safe output jobs are created
- Added environment variables (GITHUB_AW_CREATED_ISSUE_URL, GITHUB_AW_CREATED_DISCUSSION_URL, GITHUB_AW_CREATED_PULL_REQUEST_URL, etc.) to pass output URLs from other jobs
- Updated add_comment.cjs to display a "Related Items" section with links to created issues, discussions, and pull requests
- Reordered job creation in compiler.go to build create_pull_request before add_comment
- Updated all test files that call buildCreateOutputAddCommentJob to pass the new parameters
- Added comprehensive test coverage in add_comment_dependencies_test.go

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review October 19, 2025 23:56
@github-actions
Copy link
Copy Markdown
Contributor

Agentic Changeset Generator triggered by this pull request.

Copilot AI changed the title [WIP] Add environment variables for comment referencing Add job dependencies and environment variables to add_comment for referencing created items Oct 19, 2025
Copilot AI requested a review from pelikhan October 19, 2025 23:57
Copy link
Copy Markdown
Collaborator

@pelikhan pelikhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot make sure the create_issue.cjs, create_discussion.cjs and create_pull_pull_request.cjs job setup the outputs properly.

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot make sure the create_issue.cjs, create_discussion.cjs and create_pull_pull_request.cjs job setup the outputs properly

…nd create_pull_request scripts

Ensures that job outputs are always set, even when scripts exit early (e.g., in staged mode, when no items are found, or on errors). This prevents the add_comment job from receiving undefined/empty values when referencing these outputs.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 20, 2025

@copilot make sure the create_issue.cjs, create_discussion.cjs and create_pull_pull_request.cjs job setup the outputs properly

Fixed in commit 1693686. All three scripts (create_issue.cjs, create_discussion.cjs, and create_pull_request.cjs) now initialize their outputs to empty strings at the start of the main() function. This ensures outputs are always set, even when the scripts exit early due to staged mode, missing items, or errors.

@pelikhan pelikhan merged commit cebd8e0 into main Oct 20, 2025
4 checks passed
@pelikhan pelikhan deleted the copilot/add-comment-environment-variables branch October 20, 2025 00:17
github-actions Bot added a commit that referenced this pull request Oct 20, 2025
This update documents the new feature from PR #2006 where add_comment
automatically depends on create_issue, create_discussion, and
create_pull_request jobs, and includes a "Related Items" section with
links to created items.

Key additions:
- Documented automatic job dependencies between safe outputs
- Explained the Related Items section appended to comments
- Listed available environment variables for cross-referencing
- Provided configuration examples and generated output format

Addresses feature merged in #2006

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants