Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 8, 2025

Refactor: Extract updateActivationComment to separate file

Extracted the updateActivationComment function from create_pull_request.cjs into a separate reusable module as requested.

Changes

  1. New File: update_activation_comment.cjs

    • Extracted updateActivationComment function with full functionality
    • Supports both issue/PR comments (REST API) and discussion comments (GraphQL)
    • Takes github, context, core as parameters (following existing patterns)
    • Properly handles errors without failing workflow
    • Validates comment_repo format with fallback to context
    • Null-checks for deleted comments (both GraphQL and REST API)
  2. Updated: create_pull_request.cjs

    • Added require("./update_activation_comment.cjs") at top
    • Removed duplicated function code
    • Updated function call to pass required parameters: updateActivationComment(github, context, core, url, number)
  3. Updated: js.go

    • Removed createPullRequestScript (moved to scripts.go)
    • Added //go:embed directive for update_activation_comment.cjs
    • Registered file in GetJavaScriptSources() map for bundler support
  4. Updated: scripts.go

    • Added createPullRequestScriptSource with //go:embed
    • Added bundling variables with sync.Once pattern
    • Created getCreatePullRequestScript() getter function for lazy bundling
    • Ensures require statements are inlined during compilation
  5. Updated: create_pull_request.go

    • Changed from using createPullRequestScript directly to getCreatePullRequestScript()
    • Ensures bundling happens before script is used in workflows
  6. New File: update_activation_comment.test.cjs

    • 10 comprehensive tests covering all scenarios:
      • Skip when comment_id not set
      • Update issue comment via REST API
      • Update discussion comment via GraphQL
      • Use default repo from context
      • Handle errors gracefully
      • Handle invalid comment_repo format
      • Handle deleted discussion comment (null body)
      • Handle deleted discussion comment (null node)
      • Handle deleted issue comment (null body)
      • Handle deleted issue comment (undefined body)
  7. Updated: create_pull_request.test.cjs

    • Added mock updateActivationComment function to dependencies
    • Updated test extraction to remove require statement
    • Simplified activation comment tests to verify mock was called
    • All 45 tests pass

Test Results

✅ All JavaScript tests pass (763 tests)
✅ All Go unit tests pass
✅ Build successful
✅ Code formatting verified
✅ Linting passes
✅ All 74 workflows recompiled successfully
✅ No require statements in compiled workflows - all properly bundled

Bundling Verification

The bundler now properly inlines the require("./update_activation_comment.cjs") statement:

  • ✅ updateActivationComment function is inlined in all compiled workflows
  • ✅ No require statements remain in .lock.yml files
  • ✅ Function appears exactly once per workflow (deduplicated)

The refactoring follows existing patterns in the codebase (similar to how sanitize_content.cjs, load_agent_output.cjs, etc. are structured).

Original prompt

Update the create_pull_request safe output JavaScript code to update the comment with a link to the created pull request (if a comment was created in the activation). It should append to the comment description with the link to the pull request.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 8, 2025 23:39
- Add GH_AW_COMMENT_ID and GH_AW_COMMENT_REPO environment variables to create_pull_request job
- Implement updateActivationComment function in create_pull_request.cjs
- Support both issue/PR comments (REST API) and discussion comments (GraphQL)
- Append PR link to activation comment after successful PR creation
- Add comprehensive tests for the new functionality

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Update comment to include link to created pull request Update activation comment with PR link after create_pull_request Nov 8, 2025
Copilot finished work on behalf of pelikhan November 8, 2025 23:49
Copilot AI requested a review from pelikhan November 8, 2025 23:49
* @param {string} pullRequestUrl - URL of the created pull request
* @param {number} pullRequestNumber - Number of the pull request
*/
async function updateActivationComment(pullRequestUrl, pullRequestNumber) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot move to separate .cjs file that gets imported. update compiler and bundler for requires.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored into separate file update_activation_comment.cjs that gets imported via require(). Updated compiler and bundler to handle the require. Commit: bb45c8a

- Extract updateActivationComment function to update_activation_comment.cjs
- Update create_pull_request.cjs to use require() for the extracted function
- Add update_activation_comment.cjs to GetJavaScriptSources() in js.go
- Create comprehensive tests for update_activation_comment.cjs
- Update create_pull_request.test.cjs to use mock function
- All tests pass (758 JS tests, all Go unit tests)

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan November 9, 2025 00:15
Copilot finished work on behalf of pelikhan November 9, 2025 00:15
@pelikhan pelikhan marked this pull request as ready for review November 9, 2025 01:50
Copilot AI review requested due to automatic review settings November 9, 2025 01:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds functionality to update activation comments with a link to the created pull request. When a workflow is triggered by an issue or discussion comment and subsequently creates a pull request, the original activation comment is updated with a reference to the new PR.

Key Changes:

  • New JavaScript module update_activation_comment.cjs that updates issue/discussion comments with PR links
  • Integration with create_pull_request.cjs to automatically call the update function after PR creation
  • Environment variable passing from Go to provide activation comment context

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/workflow/js/update_activation_comment.cjs New utility module that handles updating both issue comments (REST API) and discussion comments (GraphQL) with PR links
pkg/workflow/js/update_activation_comment.test.cjs Comprehensive test suite covering various scenarios including issue comments, discussion comments, missing comment IDs, and error handling
pkg/workflow/js/create_pull_request.cjs Updated to import and call the new updateActivationComment function after successfully creating a PR
pkg/workflow/js/create_pull_request.test.cjs Updated tests to mock the updateActivationComment function and verify it's called with correct parameters
pkg/workflow/js.go Registered the new utility module in the JavaScript sources map for bundling
pkg/workflow/create_pull_request.go Added environment variable passing for GH_AW_COMMENT_ID and GH_AW_COMMENT_REPO to the safe output job
docs/src/content/docs/status.mdx Updated workflow path reference from super-linter-report.md to super-linter.md
Multiple .lock.yml files Generated workflow files with the bundled JavaScript including the new updateActivationComment function inlined

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

pelikhan and others added 3 commits November 8, 2025 17:55
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@pelikhan
Copy link
Contributor

pelikhan commented Nov 9, 2025

@copilot fix tests

- Add test for invalid comment_repo format validation
- Add test for deleted discussion comment (null body)
- Add test for deleted discussion comment (null node)
- Add test for deleted issue comment (null body in REST API)
- Add test for deleted issue comment (undefined body in REST API)
- All 763 JavaScript tests pass
- All Go unit tests pass

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

Copilot AI commented Nov 9, 2025

@copilot fix tests

Added 5 new tests for the validation and null-check logic that was added in the recent commits. All 763 JavaScript tests pass. Commit: fea319e

Copilot AI requested a review from pelikhan November 9, 2025 02:06
Copilot finished work on behalf of pelikhan November 9, 2025 02:06
script: |
const fs = require("fs");
const crypto = require("crypto");
const { updateActivationComment } = require("./update_activation_comment.cjs");
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot make sure bundled inlines this require

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bundler now inlines the require statement. Created getCreatePullRequestScript() with lazy bundling using sync.Once pattern. All require("./update_activation_comment.cjs") statements are now inlined in compiled workflows. Commit: b63e92a

- Move createPullRequestScript from js.go to scripts.go as createPullRequestScriptSource
- Add bundling with sync.Once pattern for lazy bundling
- Create getCreatePullRequestScript() getter function
- Update create_pull_request.go to use getter instead of direct variable
- Update js_test.go to use getter for testing
- All require("./update_activation_comment.cjs") statements now inlined in compiled workflows
- All 763 JavaScript tests pass
- All Go unit tests pass
- All 74 workflows recompiled successfully

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan November 9, 2025 05:58
Copilot finished work on behalf of pelikhan November 9, 2025 05:58
@pelikhan pelikhan merged commit 98d22af into main Nov 9, 2025
46 of 50 checks passed
@pelikhan pelikhan deleted the copilot/update-comment-with-pr-link branch November 9, 2025 18:41
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