Skip to content

Commit 026fc8d

Browse files
Copilotpelikhan
andcommitted
fix: staged mode is independent of target-repo, add test cases for all handler types
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 52450e4 commit 026fc8d

2 files changed

Lines changed: 387 additions & 81 deletions

File tree

pkg/workflow/compiler_safe_outputs_env.go

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ func (c *Compiler) addAllSafeOutputConfigEnvVars(steps *[]string, data *Workflow
1414
}
1515

1616
// Add the global staged env var once if staged mode is enabled, not in trial mode,
17-
// and at least one configured handler targets the current repository.
18-
if !c.trialMode && data.SafeOutputs.Staged && hasSafeOutputWithoutTargetRepo(data.SafeOutputs) {
17+
// and at least one handler is configured. Staged mode is independent of target-repo.
18+
if !c.trialMode && data.SafeOutputs.Staged && hasSafeOutputConfigured(data.SafeOutputs) {
1919
*steps = append(*steps, " GH_AW_SAFE_OUTPUTS_STAGED: \"true\"\n")
2020
compilerSafeOutputsEnvLog.Print("Added staged flag")
2121
}
@@ -31,11 +31,10 @@ func (c *Compiler) addAllSafeOutputConfigEnvVars(steps *[]string, data *Workflow
3131
// Note: All handler configuration is read from the config.json file at runtime.
3232
}
3333

34-
// hasSafeOutputWithoutTargetRepo returns true if any configured safe output handler
35-
// targets the current repository (i.e., has no target-repo specified).
36-
// Handlers without a target-repo field always target the current repo,
37-
// while handlers with a target-repo field qualify only when no cross-repo target is set.
38-
func hasSafeOutputWithoutTargetRepo(so *SafeOutputsConfig) bool {
34+
// hasSafeOutputConfigured returns true if any safe output handler is configured.
35+
// Staged mode is independent of target-repo: it activates whenever staged is set
36+
// and at least one handler is present.
37+
func hasSafeOutputConfigured(so *SafeOutputsConfig) bool {
3938
if so.AutofixCodeScanningAlert != nil {
4039
return true
4140
}
@@ -63,96 +62,94 @@ func hasSafeOutputWithoutTargetRepo(so *SafeOutputsConfig) bool {
6362
if so.NoOp != nil {
6463
return true
6564
}
66-
67-
// Handlers with a target-repo field qualify only when no cross-repo target is specified.
68-
if so.CreateIssues != nil && so.CreateIssues.TargetRepoSlug == "" {
65+
if so.CreateIssues != nil {
6966
return true
7067
}
71-
if so.CreateDiscussions != nil && so.CreateDiscussions.TargetRepoSlug == "" {
68+
if so.CreateDiscussions != nil {
7269
return true
7370
}
74-
if so.CloseDiscussions != nil && so.CloseDiscussions.TargetRepoSlug == "" {
71+
if so.CloseDiscussions != nil {
7572
return true
7673
}
77-
if so.CloseIssues != nil && so.CloseIssues.TargetRepoSlug == "" {
74+
if so.CloseIssues != nil {
7875
return true
7976
}
80-
if so.ClosePullRequests != nil && so.ClosePullRequests.TargetRepoSlug == "" {
77+
if so.ClosePullRequests != nil {
8178
return true
8279
}
83-
if so.MarkPullRequestAsReadyForReview != nil && so.MarkPullRequestAsReadyForReview.TargetRepoSlug == "" {
80+
if so.MarkPullRequestAsReadyForReview != nil {
8481
return true
8582
}
86-
if so.AddComments != nil && so.AddComments.TargetRepoSlug == "" {
83+
if so.AddComments != nil {
8784
return true
8885
}
89-
if so.CreatePullRequests != nil && so.CreatePullRequests.TargetRepoSlug == "" {
86+
if so.CreatePullRequests != nil {
9087
return true
9188
}
92-
if so.CreatePullRequestReviewComments != nil && so.CreatePullRequestReviewComments.TargetRepoSlug == "" {
89+
if so.CreatePullRequestReviewComments != nil {
9390
return true
9491
}
95-
if so.SubmitPullRequestReview != nil && so.SubmitPullRequestReview.TargetRepoSlug == "" {
92+
if so.SubmitPullRequestReview != nil {
9693
return true
9794
}
98-
if so.ReplyToPullRequestReviewComment != nil && so.ReplyToPullRequestReviewComment.TargetRepoSlug == "" {
95+
if so.ReplyToPullRequestReviewComment != nil {
9996
return true
10097
}
101-
if so.ResolvePullRequestReviewThread != nil && so.ResolvePullRequestReviewThread.TargetRepoSlug == "" {
98+
if so.ResolvePullRequestReviewThread != nil {
10299
return true
103100
}
104-
if so.CreateCodeScanningAlerts != nil && so.CreateCodeScanningAlerts.TargetRepoSlug == "" {
101+
if so.CreateCodeScanningAlerts != nil {
105102
return true
106103
}
107-
if so.AddLabels != nil && so.AddLabels.TargetRepoSlug == "" {
104+
if so.AddLabels != nil {
108105
return true
109106
}
110-
if so.RemoveLabels != nil && so.RemoveLabels.TargetRepoSlug == "" {
107+
if so.RemoveLabels != nil {
111108
return true
112109
}
113-
if so.AddReviewer != nil && so.AddReviewer.TargetRepoSlug == "" {
110+
if so.AddReviewer != nil {
114111
return true
115112
}
116-
if so.AssignMilestone != nil && so.AssignMilestone.TargetRepoSlug == "" {
113+
if so.AssignMilestone != nil {
117114
return true
118115
}
119-
if so.AssignToAgent != nil && so.AssignToAgent.TargetRepoSlug == "" {
116+
if so.AssignToAgent != nil {
120117
return true
121118
}
122-
if so.AssignToUser != nil && so.AssignToUser.TargetRepoSlug == "" {
119+
if so.AssignToUser != nil {
123120
return true
124121
}
125-
if so.UnassignFromUser != nil && so.UnassignFromUser.TargetRepoSlug == "" {
122+
if so.UnassignFromUser != nil {
126123
return true
127124
}
128-
if so.UpdateIssues != nil && so.UpdateIssues.TargetRepoSlug == "" {
125+
if so.UpdateIssues != nil {
129126
return true
130127
}
131-
if so.UpdatePullRequests != nil && so.UpdatePullRequests.TargetRepoSlug == "" {
128+
if so.UpdatePullRequests != nil {
132129
return true
133130
}
134-
if so.UpdateDiscussions != nil && so.UpdateDiscussions.TargetRepoSlug == "" {
131+
if so.UpdateDiscussions != nil {
135132
return true
136133
}
137-
if so.UpdateRelease != nil && so.UpdateRelease.TargetRepoSlug == "" {
134+
if so.UpdateRelease != nil {
138135
return true
139136
}
140-
if so.PushToPullRequestBranch != nil && so.PushToPullRequestBranch.TargetRepoSlug == "" {
137+
if so.PushToPullRequestBranch != nil {
141138
return true
142139
}
143-
if so.HideComment != nil && so.HideComment.TargetRepoSlug == "" {
140+
if so.HideComment != nil {
144141
return true
145142
}
146-
if so.SetIssueType != nil && so.SetIssueType.TargetRepoSlug == "" {
143+
if so.SetIssueType != nil {
147144
return true
148145
}
149-
if so.DispatchWorkflow != nil && so.DispatchWorkflow.TargetRepoSlug == "" {
146+
if so.DispatchWorkflow != nil {
150147
return true
151148
}
152-
if so.CreateAgentSessions != nil && so.CreateAgentSessions.TargetRepoSlug == "" {
149+
if so.CreateAgentSessions != nil {
153150
return true
154151
}
155-
if so.LinkSubIssue != nil && so.LinkSubIssue.TargetRepoSlug == "" {
152+
if so.LinkSubIssue != nil {
156153
return true
157154
}
158155
return false

0 commit comments

Comments
 (0)