Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 22, 2025

Implementation Complete: close-issue Safe Output Type

Changes Made

  • Create CloseIssuesConfig struct in pkg/workflow/compiler.go
  • Create close_issue.go with parsing and job building logic (following close_discussion.go pattern)
  • Create close_issue.cjs JavaScript implementation (following close_discussion.cjs pattern)
  • Create close_issue.test.cjs comprehensive test suite ✅ NEW
  • Update safe_outputs.go to include CloseIssues in:
    • HasSafeOutputsEnabled() function ✓
    • Safe output prompt generation ✓
    • MCP server tools enablement ✓
  • Add schema definition to pkg/parser/schemas/main_workflow_schema.json
  • Embed the JavaScript file in pkg/workflow/scripts.go
  • Add getter function in pkg/workflow/scripts.go (getCloseIssueScript())
  • Update semantic-function-refactor.md to use close-issue instead of update-issue
  • Add close_issue tool to safe_outputs_tools.json
  • Update compiler_jobs.go to build close_issue job
  • Update test expectations in safe_outputs_tools_test.go
  • Run tests and compile workflow to verify ✓

Test Coverage for close_issue.cjs

10 comprehensive test cases:

  1. Handle empty agent output
  2. Handle missing agent output
  3. Close issue with comment in triggering context
  4. Close specific issue when target is "*"
  5. Filter by required title prefix
  6. Filter by required labels
  7. Skip already closed issues
  8. Work in staged mode
  9. Handle multiple issues in batch
  10. Skip when not in issue context and target is triggering

Test Results

✓ All JavaScript tests pass (10/10 close_issue tests)
✓ All unit tests pass
✓ Linter passes
✓ Workflow compiles successfully (267.0 KB)
Original prompt

This section details on the original issue you should resolve

<issue_title>[q] Close existing [refactor] issues before creating new one</issue_title>
<issue_description># Q Workflow Optimization Report

Context

This fix addresses issue #4543, where the semantic-function-refactor workflow was creating duplicate issues with the [refactor] title prefix. Currently, there are 7 open issues with this prefix, all created by this workflow.

Issue Evidence:

Changes Made

Modified Workflow: semantic-function-refactor.md

1. Added Safe Output Capabilities

safe-outputs:
  update-issue:
    status:           # Allow closing issues
    target: "*"       # Allow targeting any issue (not just triggering)
    max: 10           # Allow closing up to 10 issues
  add-comment:
    max: 10           # Allow commenting on up to 10 issues
  create-issue:       # Existing create-issue config
    title-prefix: "[refactor] "
    labels: [refactoring, code-quality, automated-analysis]
    max: 1

2. Enhanced GitHub Tools

tools:
  github:
    toolsets: [default, issues]  # Added 'issues' toolset for issue operations

3. Updated Mission Instructions

Added explicit instructions to close existing [refactor] issues BEFORE performing analysis:

## Mission

**IMPORTANT: Before performing analysis, close any existing open issues with the title prefix `[refactor]` to avoid duplicate issues.**

Analyze all Go source files (`.go` files, excluding test files) in the repository to:
1. **First, close existing open issues** with the `[refactor]` prefix
2. Collect all function names per file
...

4. Added New Task Step

Inserted a new critical first step:

### 1. Close Existing Refactor Issues

**CRITICAL FIRST STEP**: Before performing any analysis, close existing open issues with the `[refactor]` prefix to prevent duplicate issues.

Use the GitHub API to:
1. Search for open issues with title containing `[refactor]`
2. Close each found issue with a comment explaining a new analysis is being performed
3. Use the `github-search_issues` and `github-issue_read` tools to find and close these issues

Example workflow:
1. Search: github-search_issues with query "is:issue is:open [refactor] in:title repo:${{ github.repository }}"
2. For each found issue:
   - Add comment: "Closing this issue as a new semantic function refactoring analysis is being performed."
   - Close the issue using update_issue tool

**Do not proceed with analysis until all existing `[refactor]` issues are closed.**

5. Updated Permissions

permissions:
  contents: read
  issues: read
  pull-requests: read
  actions: read       # Added for safe outputs

Note: Removed issues: write permission as the workflow uses strict: true mode. Write operations are handled safely through the safe-outputs system.

Expected Improvements

Immediate Impact

  • Eliminates duplicate issues: Each workflow run will now close existing [refactor] issues before creating a new one
  • Cleaner issue tracking: Only one active refactoring analysis issue at a time
  • Better workflow hygiene: Prevents accumulation of stale refactoring recommendations

Behavior Change

Before:

  • Workflow creates a new [refactor] issue each run
  • Multiple duplicate issues accumulate over time
  • 7 open issues with same purpose currently exist

After:

  • Workflow searches for existing [refactor] issues
  • Closes all found issues with explanatory comment
  • Creates one new issue with fresh analysis
  • Result: Always exactly 1 active [refactor] issue

Validation

✅ Workflow compiled successfully:

✓ .github/workflows/semantic-function-refactor.md (284.9 KB)
✓ Compiled 1 workflow(s): 0 error(s), 0 warning(s)

Schema Validation

  • ✅ Safe outputs configuration validated
  • ✅ Permissions validated in strict mode
  • ✅ Tool configuration validated
  • ✅ YAML frontmatter syntax validated

Testing Recommendations

  1. Test the workflow manually using workflow_dispatch trigger
  2. Verify it closes existing issues before creating new one
  3. Check the comment text on closed issues is clear and informative
  4. Confirm only one new issue is created after closing duplicates

Implementation Notes

  • The workflow uses `sa...

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 22, 2025 12:18
… workflow

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] Close duplicate [refactor] issues in workflow Add close-issue safe output for automated issue cleanup Nov 22, 2025
Copilot AI requested a review from pelikhan November 22, 2025 12:26
Copilot finished work on behalf of pelikhan November 22, 2025 12:26
@pelikhan pelikhan marked this pull request as ready for review November 22, 2025 12:27
Copilot AI review requested due to automatic review settings November 22, 2025 12:27
Copilot finished reviewing on behalf of pelikhan November 22, 2025 12:30
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 a new close-issue safe output type to enable automated cleanup of duplicate issues. The implementation follows the established close-discussion pattern and includes Go backend code, JavaScript execution script, JSON schema validation, and a practical example in the semantic-function-refactor workflow.

Key changes:

  • Implements close-issue safe output with filtering by title prefix, labels, and target
  • Adds security features (required title prefix prevents closing wrong issues)
  • Supports batch operations (configurable max 1-100 issues)
  • Includes cross-repo support via target-repo field

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/workflow/close_issue.go Core Go implementation with config parser and job builder
pkg/workflow/js/close_issue.cjs JavaScript script for GitHub API operations (has critical bug)
pkg/workflow/safe_outputs.go Integration points for safe output system
pkg/workflow/compiler.go Type definition for CloseIssuesConfig struct
pkg/workflow/compiler_jobs.go Job builder integration
pkg/workflow/scripts.go Script embedding and bundling setup
pkg/parser/schemas/main_workflow_schema.json JSON schema validation rules
pkg/workflow/js/safe_outputs_tools.json MCP tool definition for AI agents
pkg/workflow/safe_outputs_tools_test.go Test expectations update
.github/workflows/semantic-function-refactor.md Example workflow using close-issue
.github/workflows/semantic-function-refactor.lock.yml Compiled workflow output

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

@pelikhan
Copy link
Contributor

@copilot lint and fix JavaScript tests

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

Copilot AI commented Nov 22, 2025

@copilot lint and fix JavaScript tests

Added comprehensive test suite for close_issue.cjs with 10 test cases covering all functionality including filtering, batch operations, staged mode, and error handling. All tests and linting pass. (commit 121732f)

Copilot finished work on behalf of pelikhan November 22, 2025 12:44
@pelikhan pelikhan merged commit 2da37d5 into main Nov 22, 2025
4 checks passed
@pelikhan pelikhan deleted the copilot/close-existing-refactor-issues branch November 22, 2025 16:05
github-actions bot added a commit that referenced this pull request Nov 23, 2025
Add documentation for three new safe output types merged in the last 24 hours:

- close-issue: Close GitHub issues with comment and state reason filtering
- add-reviewer: Add reviewers to pull requests with allowlist support
- close-pull-request: Close PRs without merging with label/title filtering

Changes made:
- Added entries to safe outputs table in reference documentation
- Added detailed configuration sections for each new safe output type
- Included examples with all configuration options
- Documented target modes, filtering options, and cross-repo support

Features documented from:
- PR #4568: close-pull-request safe output
- PR #4564: add-reviewer safe output
- PR #4554: close-issue safe output

🤖 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.

[q] Close existing [refactor] issues before creating new one

2 participants