Skip to content

Extract shared safe-output target parsing - #53841

Open
pelikhan with Copilot wants to merge 7 commits into
mainfrom
copilot/duplicate-code-extract-target-parsing
Open

Extract shared safe-output target parsing#53841
pelikhan with Copilot wants to merge 7 commits into
mainfrom
copilot/duplicate-code-extract-target-parsing

Conversation

Copilot AI commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Several safe-output config parsers duplicated the same cross-repo parsing flow for target, target-repo, and allowed-repos. This centralizes that behavior so wildcard and expression handling stay consistent across handlers.

  • Shared parser
    • Added an options-based parseSafeOutputTargetConfig helper.
    • Keeps parser policy explicit per caller: target parsing, target-repo parsing, wildcard allowance, and expression-aware allowed-repos.
targetConfig, isInvalid := parseSafeOutputTargetConfig(configMap, log, safeOutputTargetConfigOptions{
    parseTarget:                 true,
    parseTargetRepo:             true,
    allowTargetRepoWildcard:     true,
    parseAllowedRepos:           true,
    allowAllowedReposExpression: true,
})
  • Handler refactor

    • Replaced repeated parsing scaffolds in safe-output handlers including dispatch workflow, PR review/comment, push-to-PR-branch, link-sub-issue, update-project, and code-scanning alert config.
    • Preserved existing handler-specific behavior, including wildcard support where it was already accepted.
  • Focused coverage

    • Added helper-level coverage for option behavior.
    • Added/updated handler coverage for allowed-repos and wildcard preservation.

run: https://github.com/github/gh-aw/actions/runs/32204573204> Generated by 👨‍🍳 PR Sous Chef · gpt54 · 25.9 AIC · ⌖ 8.32 AIC · ⊞ 9.3K ·

Comment /souschef to run again


Run: https://github.com/github/gh-aw/actions/runs/32210439073> Generated by 👨‍🍳 PR Sous Chef · gpt54 · 25.8 AIC · ⌖ 8.18 AIC · ⊞ 9.3K ·

Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 33.9 AIC · ⌖ 8.18 AIC · ⊞ 9.3K ·
Comment /souschef to run again

Copilot AI and others added 2 commits August 18, 2026 22:14
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] Extract shared cross-repo target parsing from safe output config handlers Extract shared safe-output target parsing Aug 18, 2026
Copilot AI requested a review from pelikhan August 18, 2026 22:23
@github-actions

Copy link
Copy Markdown
Contributor

PR Triage

Part of a 3-PR cluster refactoring safe-output config parsing. Recommend reviewing all three together for consistency before merging.

Generated by 🔧 PR Triage Agent · auto · 58.5 AIC · ⌖ 2.15 AIC · ⊞ 8.3K ·

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Ponytail Reviewer completed successfully!

Lean already. Ship.

Generated by Ponytail Reviewer for #53841

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ failed during design decision gate check.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel skipped because pre-fetch PR data was unavailable: unable to fetch test file diff

🧪 Test quality analysis by Test Quality Sentinel

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Centralizes safe-output target parsing while preserving handler-specific wildcard and expression policies.

Changes:

  • Adds an options-based shared target parser.
  • Refactors eight safe-output handlers to use it.
  • Expands parser and cross-repository behavior tests.
Show a summary per file
File Description
pkg/workflow/safe_outputs_parser.go Adds the shared configurable parser.
pkg/workflow/config_helpers.go Delegates repository validation to the shared parser.
pkg/workflow/update_project.go Uses shared cross-repository parsing.
pkg/workflow/submit_pr_review.go Consolidates review target parsing.
pkg/workflow/reply_to_pr_review_comment.go Consolidates reply target parsing.
pkg/workflow/create_pr_review_comment.go Consolidates comment target parsing.
pkg/workflow/push_to_pull_request_branch.go Preserves wildcard and expression support.
pkg/workflow/link_sub_issue.go Preserves expression-aware repository parsing.
pkg/workflow/dispatch_workflow.go Centralizes dispatch repository parsing.
pkg/workflow/create_code_scanning_alert.go Centralizes alert repository parsing.
pkg/workflow/config_parsing_helpers_test.go Tests parser options and handler behavior.
pkg/workflow/safe_outputs_cross_repo_config_test.go Verifies code-scanning wildcard preservation.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 12/12 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

reviewed_at: 2026-08-19T00:00:00Z
review_event: REQUEST_CHANGES
top_themes:
  - expression-handling regression
  - cross-repo safe-output parsing
files_reviewed:
  - pkg/workflow/config_helpers.go
  - pkg/workflow/config_parsing_helpers_test.go
  - pkg/workflow/create_code_scanning_alert.go
  - pkg/workflow/create_pr_review_comment.go
  - pkg/workflow/dispatch_workflow.go
  - pkg/workflow/link_sub_issue.go
  - pkg/workflow/push_to_pull_request_branch.go
  - pkg/workflow/reply_to_pr_review_comment.go
  - pkg/workflow/safe_outputs_cross_repo_config_test.go
  - pkg/workflow/safe_outputs_parser.go
  - pkg/workflow/submit_pr_review.go
  - pkg/workflow/update_project.go
comment_count: 1

Note

This comment is managed by comment memory.

It stores persistent context for this thread in the code block at the top of this comment.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 51.5 AIC · ⌖ 7.69 AIC · ⊞ 7K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Request changes

This refactor introduced at least one behavior regression in safe-output cross-repo parsing: create-pull-request-review-comment no longer preserves expression-based allowed-repos, so workflows that relied on ${{ ... }} there will quietly lose their repo allowlist at compile time.

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 51.5 AIC · ⌖ 7.69 AIC · ⊞ 7K
Comment /review to run again

targetConfig, isInvalid := parseSafeOutputTargetConfig(configMap, createPRReviewCommentLog, safeOutputTargetConfigOptions{
parseTarget: true,
parseTargetRepo: true,
parseAllowedRepos: true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This refactor drops expression support for allowed-repos on create-pull-request-review-comment, because the parser now uses ParseStringArrayFromConfig while the handler still expects to pass templated values through to runtime. Any workflow that previously fed allowed-repos: ${{ ... }} into review comments will silently lose its repo allowlist and stop targeting cross-repo PRs correctly.

💡 Why this is a regression and how to fix it

create_pull_request_review_comment is still emitted with AddStringSlice("allowed_repos", c.AllowedRepos), so it only works when c.AllowedRepos preserves the raw expression. The new shared helper only preserves expressions when allowAllowedReposExpression is enabled, but this caller does not opt in.

Use the expression-aware path here as well, or add a regression test that proves ${{ inputs['allowed-repos'] }} survives parsing and reaches the generated handler config.

targetConfig, isInvalid := parseSafeOutputTargetConfig(configMap, createPRReviewCommentLog, safeOutputTargetConfigOptions{
    parseTarget:                 true,
    parseTargetRepo:             true,
    parseAllowedRepos:           true,
    allowAllowedReposExpression: true,
})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a0aebb4: create-pull-request-review-comment now opts into expression-aware allowed-repos parsing, with regression coverage proving ${{ inputs['allowed-repos'] }} is preserved.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Clean refactoring that successfully extracts shared safe-output target parsing into a single parseSafeOutputTargetConfig helper with configurable options. The approach is sound — good use of options struct to control parse behavior per handler. One stale comment found (inline).

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 26.3 AIC · ⌖ 8.82 AIC · ⊞ 5.7K

Comment thread pkg/workflow/link_sub_issue.go Outdated
allowAllowedReposExpression: true,
})
if isInvalid {
return nil // Invalid configuration (e.g., wildcard target-repo), return nil to cause validation error

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The inline comment says "Invalid configuration (e.g., wildcard target-repo)", but allowTargetRepoWildcard: true is set in the options above, so wildcards are allowed for this handler. The example in the comment is now misleading and will confuse future readers.

Suggested fix:

return nil // Invalid configuration, return nil to cause validation error

@copilot please address this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 619a311: removed the misleading wildcard example from the invalid-configuration comment in pkg/workflow/link_sub_issue.go.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /codebase-design — two small follow-ups; no blocking issues.

📋 Key Themes & Highlights

Key Themes

  • Struct inconsistency: CreatePullRequestReviewCommentsConfig assigns Target/TargetRepoSlug/AllowedRepos individually rather than embedding SafeOutputTargetConfig like its sibling structs now do.
  • Undocumented policy gap: create_code_scanning_alert silently drops allowAllowedReposExpression while similar handlers enable it — the intent isn't documented.

Positive Highlights

  • ✅ Clean options-struct pattern — explicit, testable, no hidden globals
  • nil guard on debugLog is a small but good defensive detail
  • ✅ Test coverage is solid: option-by-option cases, wildcard, expression-aware paths all covered
  • ParseTargetConfig preserved as a thin adapter — existing callers unaffected

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 51.5 AIC · ⌖ 10.1 AIC · ⊞ 7.8K
Comment /matt to run again

Comments that could not be inline-anchored

pkg/workflow/create_pr_review_comment.go:16

[/codebase-design] CreatePullRequestReviewCommentsConfig still expands Target, TargetRepoSlug, and AllowedRepos as individual fields instead of embedding SafeOutputTargetConfig — unlike the sibling structs (SubmitPullRequestReviewConfig, ReplyToPRReviewCommentConfig) that this PR already migrated to the embedded form.

<details>
<summary>💡 Suggested change</summary>

Embed SafeOutputTargetConfig in the struct definition:

type CreatePullRequestReviewCommentsConfig str</details>

<details><summary>pkg/workflow/create_code_scanning_alert.go:164</summary>

**[/codebase-design]** `create_code_scanning_alert.go` no longer passes `allowAllowedReposExpression: true`, but the pre-existing `ParseStringArrayFromConfig` call it replaced did not support expressions either — so this is a pre-existing limitation, not a regression. However, it is now inconsistent with other handlers that accept security-sensitive configs (e.g. `dispatch_workflow`, `push_to_pull_request_branch`) which do allow expression-based `allowed-repos`. Worth documenting or aligning in…

</details>

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please address the latest blocking review feedback on this PR and then run the pr-finisher skill.

Current blocker to resolve:

  • github-actions[bot] requested changes because create-pull-request-review-comment no longer preserves expression-based allowed-repos, which regresses safe-output cross-repo parsing behavior.

Failing checks on the current head:

A branch refresh was attempted by sous-chef as well.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 25.9 AIC · ⌖ 8.32 AIC · ⊞ 9.3K ·
Comment /souschef to run again

Copilot AI and others added 2 commits August 19, 2026 01:39
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please address the latest blocking review feedback on this PR and then run the pr-finisher skill.

Current blocker to resolve:...

Addressed in a0aebb4 by enabling expression-aware allowed-repos parsing for create-pull-request-review-comment and adding regression coverage. I also ran pr-finisher; local validation passed except for unrelated pre-existing make lint failures in pkg/intent/governance_formal_test.go.

Copilot AI requested a review from gh-aw-bot August 19, 2026 01:51
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot A recent author update landed on this PR, but there is still no maintainer-visible resolution on the blocking review. Please refresh the branch if needed, re-run the affected checks, and then run the pr-finisher skill once the regression fix is clearly reflected for reviewers.

Current maintainer-visible blocker:

  • github-actions[bot] requested changes because create-pull-request-review-comment regressed expression-based allowed-repos parsing.

A branch refresh was attempted by sous-chef as well.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 25.8 AIC · ⌖ 8.18 AIC · ⊞ 9.3K ·
Comment /souschef to run again

Copilot AI commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot A recent author update landed on this PR, but there is still no maintainer-visible resolution on the blocking review. Please refresh the branch if needed, re-run the affected checks, and then...

Confirmed on current head 619a311: the blocking regression is fixed by a0aebb4, where create-pull-request-review-comment opts into expression-aware allowed-repos parsing and regression coverage preserves ${{ inputs['allowed-repos'] }}. I re-ran the affected parser test plus pr-finisher validation (make fmt, make test-unit, make test, make recompile, and BASE_REF=origin/main make agent-report-progress). make lint still fails only on unrelated pre-existing testifylint findings in pkg/intent/governance_formal_test.go.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot A recent author update landed on this PR, but the blocking github-actions[bot] review is still unresolved for maintainers.

Current maintainer-visible blocker:

  • Please re-confirm in a reviewer-facing handoff that the expression-based allowed-repos regression is fixed on the current head, refresh the branch if needed, and then run the pr-finisher skill.
  • A branch refresh was attempted by sous-chef as well.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 33.9 AIC · ⌖ 8.18 AIC · ⊞ 9.3K ·
Comment /souschef to run again

Copilot AI commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot A recent author update landed on this PR, but the blocking github-actions[bot] review is still unresolved for maintainers.

Current maintainer-visible blocker:...

Confirmed on current head f3e72ba: the expression-based allowed-repos regression remains fixed by a0aebb4. pkg/workflow/create_pr_review_comment.go passes allowAllowedReposExpression: true, and TestParsePRReviewCommentsConfigPreservesAllowedReposExpression verifies ${{ inputs['allowed-repos'] }} is preserved.

I refreshed against origin/main and ran pr-finisher validation: targeted parser test, make fmt, make test-unit, make test, make recompile, and BASE_REF=origin/main make agent-report-progress all passed. Full make lint still fails only on unrelated pre-existing testifylint findings in pkg/intent/governance_formal_test.go.

@github-actions

Copy link
Copy Markdown
Contributor

Triage: category=refactor · risk=medium · score=47/100 (impact 22/50, urgency 15/30, quality 10/20)
Recommended action: batch_review

Part of the B1-safeoutput-refactor batch (with #53840, #53838). CHANGES_REQUESTED outstanding and mergeable_state=blocked; active resolution thread with gh-aw-bot. Batch-review alongside sibling PRs once threads are resolved.

Generated by 🔧 PR Triage Agent · auto · 58.8 AIC · ⌖ 2.56 AIC · ⊞ 8.3K ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[duplicate-code] Extract shared cross-repo target parsing from safe output config handlers

4 participants