Repository navigation
refactor(pkg/workflow): centralize condition/token helpers and normalize entity helper naming - #32227
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors pkg/workflow to consolidate related helper logic (conditions + token resolution) and to normalize helper naming for safe-outputs entity config parsing, reducing “function-location drift” and improving discoverability/consistency.
Changes:
- Centralizes multiple
ConditionNodebuilder helpers intoexpression_builder.goand removes duplicates from compiler files. - Normalizes create-* safe-outputs parser method names (
parse*Config→parseCreate*Config) and renames update-entity helper files to verb-aligned filenames. - Centralizes safe-outputs token resolution helpers into
github_token.gowith consistentresolve*naming, removing token logic fromsafe_outputs_config_helpers.go.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/update_pull_request.go | Adds update-pull-request config type + parser under normalized filename. |
| pkg/workflow/update_issue.go | Adds update-issue config type + parser under normalized filename. |
| pkg/workflow/update_discussion.go | Adds update-discussion config type + parser under normalized filename. |
| pkg/workflow/update_entity_helpers.go | Updates documentation pointers to renamed update-* files. |
| pkg/workflow/safe_outputs_config.go | Updates call sites to renamed create-* parser methods. |
| pkg/workflow/safe_outputs_config_helpers.go | Removes token resolution helpers; leaves config serialization helpers. |
| pkg/workflow/github_token.go | Adds centralized resolve* token helpers for safe-outputs operations. |
| pkg/workflow/expression_builder.go | Becomes the canonical home for moved condition builder helpers. |
| pkg/workflow/create_pull_request.go | Renames parser to parseCreatePullRequestsConfig and updates related comments. |
| pkg/workflow/create_issue.go | Renames parser to parseCreateIssuesConfig. |
| pkg/workflow/create_discussion.go | Renames parser to parseCreateDiscussionsConfig. |
| pkg/workflow/create_discussion_validation_test.go | Updates tests to call renamed discussion parser. |
| pkg/workflow/create_discussion_dependencies_test.go | Updates tests and messages to use renamed discussion parser. |
| pkg/workflow/create_code_scanning_alert.go | Updates static checkout token helper call to resolveStaticCheckoutToken. |
| pkg/workflow/config_parsing_helpers_test.go | Updates tests to use renamed create-* parser methods. |
| pkg/workflow/config_helpers.go | Updates comment to reference renamed create-* parsers. |
| pkg/workflow/compiler_safe_outputs_steps.go | Switches PR checkout token resolution to resolvePRCheckoutToken and project token helper to resolveProjectURLAndToken. |
| pkg/workflow/compiler_safe_outputs_job.go | Removes detection condition helpers that were moved into expression_builder.go. |
| pkg/workflow/compiler_pre_activation_job.go | Removes moved condition helpers and cleans up imports accordingly. |
| pkg/workflow/close_entity_helpers.go | Updates documentation references to renamed update-* files. |
| DEVGUIDE.md | Updates documentation examples to reflect renamed create-issue parser method. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 18/21 changed files
- Comments generated: 1
| func buildAuthorAssociationNodeForEvent(eventName string) ConditionNode { | ||
| switch eventName { | ||
| case "issue_comment", "pull_request_review_comment", "pull_request_review", "discussion_comment": | ||
| return BuildPropertyAccess("github.event.comment.author_association") | ||
| case "issues": | ||
| return BuildPropertyAccess("github.event.issue.author_association") | ||
| case "pull_request", "pull_request_target": | ||
| return BuildPropertyAccess("github.event.pull_request.author_association") | ||
| default: | ||
| return &ExpressionNode{Expression: "github.event.comment.author_association || github.event.issue.author_association || github.event.pull_request.author_association || github.event.author_association"} | ||
| } |
|
@copilot review all comments and reviews |
🧪 Test Quality Sentinel ReportTest Quality Score: N/A — No New Testsi️ No new test functions were added or modified in this PR. The three test files listed as changed contain only mechanical renames:
No test logic, assertions, or test function signatures were changed. All changes are keeping tests in sync with the production-code refactoring (function renames). Verdict
Language SupportTests analyzed:
References: §25893510355
|
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /zoom-out and /improve-codebase-architecture — this is a refactor that consolidates module ownership, so those lenses are most relevant.
Key Themes
- Depth improvement ✅ —
expression_builder.gonow owns allConditionNodeconstruction andgithub_token.goowns all token resolution. The deletion test passes: removing either old scattering would have forced callers to reconstruct the logic. Module depth is genuinely increased. - Naming consistency ✅ —
parseCreate*andresolve*prefixes are now aligned with the verb-prefixed convention used elsewhere in the package.update_*_helpers.go→update_*.gois a nice cleanup of a gratuitous_helperssuffix. - Comment locality loss
⚠️ — Two minor comment drops during the move:buildAuthorAssociationNodeForEventarrived without a doc comment, andbuildCommentAuthorAssociationConditionlost the inline explanation of whygithub.actoris used for bot exemption instead ofauthor_association. Both encoded non-obvious design decisions. - Named return readability
⚠️ —resolveProjectURLAndTokenuses named returns with barereturnstatements. With three distinct priority branches it makes the data flow slightly harder to follow.
Positive Highlights
- ✅
safe_outputs_config_helpers.gois now genuinely focused on safe-output serialisation — the file's stated purpose finally matches its contents - ✅
resolveProjectTokenis a clean, shallow helper that removes duplication across the three project-URL branches - ✅ Doc comments on the new
resolve*functions are thorough and include explicit precedence ladders - ✅ No behaviour changes — this is a pure structural move, which keeps the diff reviewable
Verdict
Observations only — no blocking issues. The comment-loss items are small enough to address in a follow-up or in this PR.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · ● 8.6M
| return result | ||
| } | ||
|
|
||
| func buildAuthorAssociationNodeForEvent(eventName string) ConditionNode { |
There was a problem hiding this comment.
[/zoom-out] buildAuthorAssociationNodeForEvent lost its doc comment during the move. The function encodes non-obvious domain knowledge — specifically, which GitHub event schema field carries author_association for each event type, and why the default branch emits a multi-field OR expression. A short doc comment would preserve that intent for future readers:
// buildAuthorAssociationNodeForEvent returns the ConditionNode that reads the correct
// author_association field for the given event name. Each event type exposes the field
// at a different path in the GitHub event payload; the default fallback tries all known
// paths so unknown events still work.
func buildAuthorAssociationNodeForEvent(eventName string) ConditionNode {| BuildStringLiteral(bot), | ||
| ) | ||
| } | ||
| result = BuildOr(result, BuildDisjunction(false, botTerms...)) |
There was a problem hiding this comment.
[/zoom-out] The move dropped four inline comments from the bot-exemption block that explained why github.actor is used instead of author_association, and why BuildDisjunction is preferred over nested BuildOr calls. These are non-obvious design decisions worth preserving:
// Allow explicitly listed bot/app actors so on.bots behaviour is preserved.
// Bots typically carry no OWNER/MEMBER/COLLABORATOR association, so we exempt
// them by actor login rather than by author_association.
// Use BuildDisjunction to collect all bot conditions into a flat OR rather than
// building a deeply nested binary tree with repeated BuildOr calls.
result = BuildOr(result, BuildDisjunction(false, botTerms...))Re-adding them maintains the locality of design rationale inside expression_builder.go.
| tokenLog.Printf("Setting GH_AW_PROJECT_GITHUB_TOKEN from create-project config") | ||
| } | ||
|
|
||
| return |
There was a problem hiding this comment.
[/improve-codebase-architecture] Named returns with bare return statements reduce readability here. The caller has to scroll back to the function signature to know what's being returned, and it's easy to accidentally return zero values by falling off the end of a branch. Explicit returns would make the function clearer, especially given the three distinct priority paths:
// instead of bare return:
return projectURL, projectTokenIf named returns are kept for the early-exit return "", "" path, consider using them only there and making the remaining returns explicit.
Generated by the Design Decision Gate workflow. Documents the centralization of ConditionNode builders into expression_builder.go, the verb-prefixed create-entity parser rename, the update-entity file rename (drop _helpers suffix), and the token-resolution move to github_token.go with resolve* prefix. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Commit pushed:
|
🏗️ Design Decision Gate — ADR RequiredThis PR makes significant changes to core business logic in AI has analyzed the PR diff and generated a draft ADR to help you get started: 📄 Draft ADR: The draft was inferred from the diff and PR description. It documents three structural decisions:
What to do next
Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision. Why ADRs MatterADRs create a searchable, permanent record of why the codebase looks the way it does. This PR is the fourth in a series of file-placement refactors (ADR-27325, ADR-28282, ADR-29336); recording it as an ADR keeps the chain of reasoning intact for future contributors and for the next round of semantic clustering analysis. 📋 Michael Nygard ADR Format ReferenceAn ADR must contain these four narrative sections to be considered complete:
This repo's ADRs additionally include a Part 2 normative specification using RFC 2119 keywords (MUST, SHOULD, MAY) for machine-checkable conformance. All ADRs are stored in
References:
|
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Addressed the actionable review thread in commit |
✨ Enhancement
pkg/workflowhad function-location drift across three areas:ConditionNodebuilders were spread across compiler files, create/update/close helper naming was inconsistent, and token-resolution logic was split between unrelated helper files. This change consolidates ownership so symbol location and naming now match responsibility.Condition builders canonicalized
Moved scattered
build*Conditionhelpers intoexpression_builder.go(canonicalConditionNodehome), including:Compiler files now consume these helpers instead of owning duplicate builder logic.
Entity helper naming normalized
Aligned create parser naming with existing verb-prefixed convention:
parseIssuesConfig→parseCreateIssuesConfigparseDiscussionsConfig→parseCreateDiscussionsConfigparsePullRequestsConfig→parseCreatePullRequestsConfigAlso normalized update helper file names:
update_issue_helpers.go→update_issue.goupdate_discussion_helpers.go→update_discussion.goupdate_pull_request_helpers.go→update_pull_request.goUpdated all internal call sites, tests, and relevant docs/comments.
Token resolution centralized and consistently named
Moved token-resolution helpers out of
safe_outputs_config_helpers.gointogithub_token.goand standardized naming toresolve*:resolvePRCheckoutTokenresolveStaticCheckoutTokenresolveProjectTokenresolveProjectURLAndTokensafe_outputs_config_helpers.gonow focuses on safe-output config serialization utilities.