Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/pipeline-controller/config_data_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"sigs.k8s.io/prow/pkg/config"
)

// RepoLister is a function that returns a list of "org/repo" strings that should be processed
// RepoLister i s a function that returns a list of "org/repo" strings that should be processed
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix the new typo in the RepoLister comment.

The updated wording now reads “i s” instead of “is”. Please remove the extra space to keep the doc comment readable.

🤖 Prompt for AI Agents
In cmd/pipeline-controller/config_data_provider.go around line 13, the doc
comment for RepoLister contains a typo "i s" instead of "is"; edit the comment
to remove the extra space so it reads "is" (e.g., change 'i s' to 'is') to
restore correct wording and readability.

type RepoLister func() []string

type presubmitTests struct {
Expand Down
23 changes: 11 additions & 12 deletions cmd/pipeline-controller/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ func sendComment(presubmits presubmitTests, pj *v1.ProwJob, ghc minimalGhClient,
}

func sendCommentWithMode(presubmits presubmitTests, pj *v1.ProwJob, ghc minimalGhClient, deleteIds func()) error {
testContexts, err := acquireConditionalContexts(pj, presubmits.pipelineConditionallyRequired, ghc, deleteIds)
testContexts, manualControlMessage, err := acquireConditionalContexts(pj, presubmits.pipelineConditionallyRequired, ghc, deleteIds)
if err != nil {
deleteIds()
return err
}

var comment string

// Check if testContexts contains a manual control message (starts with "Pipeline can be controlled")
if strings.HasPrefix(testContexts, "Pipeline can be controlled") {
comment = testContexts
if manualControlMessage != "" {
comment = manualControlMessage
} else {
var protectedCommands string
for _, presubmit := range presubmits.protected {
Expand All @@ -56,7 +55,7 @@ func sendCommentWithMode(presubmits presubmitTests, pj *v1.ProwJob, ghc minimalG
return nil
}

func acquireConditionalContexts(pj *v1.ProwJob, pipelineConditionallyRequired []config.Presubmit, ghc minimalGhClient, deleteIds func()) (string, error) {
func acquireConditionalContexts(pj *v1.ProwJob, pipelineConditionallyRequired []config.Presubmit, ghc minimalGhClient, deleteIds func()) (string, string, error) {
repoBaseRef := pj.Spec.Refs.Repo + "-" + pj.Spec.Refs.BaseRef
var testCommands string
if len(pipelineConditionallyRequired) != 0 {
Expand All @@ -76,12 +75,12 @@ func acquireConditionalContexts(pj *v1.ProwJob, pipelineConditionallyRequired []
psList[0].RegexpChangeMatcher = config.RegexpChangeMatcher{RunIfChanged: run}
if err := config.SetPresubmitRegexes(psList); err != nil {
deleteIds()
return "", err
return "", "", err
}
_, shouldRunResult, err := psList[0].RegexpChangeMatcher.ShouldRun(cfp)
if err != nil {
deleteIds()
return "", err
return "", "", err
}
shouldRun = shouldRunResult
} else if skip, ok := presubmit.Annotations["pipeline_skip_if_only_changed"]; ok && skip != "" {
Expand All @@ -90,12 +89,12 @@ func acquireConditionalContexts(pj *v1.ProwJob, pipelineConditionallyRequired []
psList[0].RegexpChangeMatcher = config.RegexpChangeMatcher{SkipIfOnlyChanged: skip}
if err := config.SetPresubmitRegexes(psList); err != nil {
deleteIds()
return "", err
return "", "", err
}
_, shouldRunResult, err := psList[0].RegexpChangeMatcher.ShouldRun(cfp)
if err != nil {
deleteIds()
return "", err
return "", "", err
}
shouldRun = shouldRunResult
} else {
Expand All @@ -112,7 +111,7 @@ func acquireConditionalContexts(pj *v1.ProwJob, pipelineConditionallyRequired []
statuses, err := ghc.ListStatuses(pj.Spec.Refs.Org, pj.Spec.Refs.Repo, pj.Spec.Refs.Pulls[0].SHA)
if err != nil {
deleteIds()
return "", err
return "", "", err
}

// Check if any of the tests we want to run have already been triggered manually
Expand All @@ -123,7 +122,7 @@ func acquireConditionalContexts(pj *v1.ProwJob, pipelineConditionallyRequired []
for _, status := range statuses {
if strings.Contains(status.Context, testName) {
deleteIds()
return "Tests from second stage were triggered manually. Pipeline can be controlled only manually, until HEAD changes. Use `/pipeline required` to trigger second stage.", nil
return "", "Tests from second stage were triggered manually. Pipeline can be controlled only manually, until HEAD changes. Use `/pipeline required` to trigger second stage.", nil
}
}
}
Expand All @@ -133,5 +132,5 @@ func acquireConditionalContexts(pj *v1.ProwJob, pipelineConditionallyRequired []
testCommands += "\n" + presubmit.RerunCommand
}
}
return testCommands, nil
return testCommands, "", nil
}
65 changes: 41 additions & 24 deletions cmd/pipeline-controller/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func TestAcquireConditionalContexts(t *testing.T) {
changes []github.PullRequestChange
statuses []github.Status
expectedTestCommands []string
expectedManualControlMessage string
expectedError string
}{
{
Expand All @@ -104,9 +105,10 @@ func TestAcquireConditionalContexts(t *testing.T) {
{Filename: "main.go"},
{Filename: "README.md"},
},
statuses: []github.Status{},
expectedTestCommands: []string{"/test test"},
expectedError: "",
statuses: []github.Status{},
expectedTestCommands: []string{"/test test"},
expectedManualControlMessage: "",
expectedError: "",
},
{
name: "pipeline_run_if_changed does not match files",
Expand All @@ -129,9 +131,10 @@ func TestAcquireConditionalContexts(t *testing.T) {
{Filename: "README.md"},
{Filename: "docs/guide.md"},
},
statuses: []github.Status{},
expectedTestCommands: []string{},
expectedError: "",
statuses: []github.Status{},
expectedTestCommands: []string{},
expectedManualControlMessage: "",
expectedError: "",
},
{
name: "pipeline_skip_if_only_changed skips when only matching files changed",
Expand All @@ -154,9 +157,10 @@ func TestAcquireConditionalContexts(t *testing.T) {
{Filename: "docs/guide.md"},
{Filename: "README.md"},
},
statuses: []github.Status{},
expectedTestCommands: []string{},
expectedError: "",
statuses: []github.Status{},
expectedTestCommands: []string{},
expectedManualControlMessage: "",
expectedError: "",
},
{
name: "pipeline_skip_if_only_changed runs when other files are changed",
Expand All @@ -178,9 +182,10 @@ func TestAcquireConditionalContexts(t *testing.T) {
{Filename: "docs/guide.md"},
{Filename: "main.go"},
},
statuses: []github.Status{},
expectedTestCommands: []string{"/test test"},
expectedError: "",
statuses: []github.Status{},
expectedTestCommands: []string{"/test test"},
expectedManualControlMessage: "",
expectedError: "",
},
{
name: "pipeline_run_if_changed takes precedence over pipeline_skip_if_only_changed",
Expand All @@ -202,9 +207,10 @@ func TestAcquireConditionalContexts(t *testing.T) {
changes: []github.PullRequestChange{
{Filename: "test/test.go"},
},
statuses: []github.Status{},
expectedTestCommands: []string{"/test test"},
expectedError: "",
statuses: []github.Status{},
expectedTestCommands: []string{"/test test"},
expectedManualControlMessage: "",
expectedError: "",
},
{
name: "multiple jobs with different annotations",
Expand Down Expand Up @@ -238,9 +244,10 @@ func TestAcquireConditionalContexts(t *testing.T) {
{Filename: "main.go"},
{Filename: "docs/guide.md"},
},
statuses: []github.Status{},
expectedTestCommands: []string{"/test test1", "/test test2"},
expectedError: "",
statuses: []github.Status{},
expectedTestCommands: []string{"/test test1", "/test test2"},
expectedManualControlMessage: "",
expectedError: "",
},
{
name: "job name does not contain repo-baseRef",
Expand All @@ -261,9 +268,10 @@ func TestAcquireConditionalContexts(t *testing.T) {
changes: []github.PullRequestChange{
{Filename: "main.go"},
},
statuses: []github.Status{},
expectedTestCommands: []string{},
expectedError: "",
statuses: []github.Status{},
expectedTestCommands: []string{},
expectedManualControlMessage: "",
expectedError: "",
},
{
name: "test already running - should return manual control message",
Expand All @@ -290,15 +298,16 @@ func TestAcquireConditionalContexts(t *testing.T) {
State: "pending",
},
},
expectedTestCommands: []string{"Pipeline can be controlled only manually, until HEAD changes."},
expectedError: "",
expectedTestCommands: []string{},
expectedManualControlMessage: "Tests from second stage were triggered manually. Pipeline can be controlled only manually, until HEAD changes. Use `/pipeline required` to trigger second stage.",
expectedError: "",
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
ghc := &fakeGhClientWithStatuses{changes: tc.changes, statuses: tc.statuses}
testCmds, err := acquireConditionalContexts(basePJ, tc.pipelineConditionallyRequired, ghc, func() {})
testCmds, manualControlMessage, err := acquireConditionalContexts(basePJ, tc.pipelineConditionallyRequired, ghc, func() {})

// Check expected error
if tc.expectedError != "" {
Expand All @@ -314,6 +323,14 @@ func TestAcquireConditionalContexts(t *testing.T) {
t.Errorf("unexpected error: %v", err)
}

// Check manual control message
if tc.expectedManualControlMessage != "" {
if manualControlMessage != tc.expectedManualControlMessage {
t.Errorf("expected manual control message %q, got %q", tc.expectedManualControlMessage, manualControlMessage)
}
return
}

Comment on lines +327 to +333
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Tighten assertions around manualControlMessage.

Right now we only check the positive case. If expectedManualControlMessage is empty we silently ignore any unexpected manual message, and when a manual message is expected we return before confirming testCmds stayed empty. Please extend the test to assert that manualControlMessage == "" whenever no message is expected, and that testCmds is empty in the manual branch. Without these checks a regression could slip through unnoticed.

🤖 Prompt for AI Agents
In cmd/pipeline-controller/helpers_test.go around lines 327 to 333, the test
only asserts the positive case for expectedManualControlMessage and returns
early, leaving two gaps: it never fails if an unexpected manualControlMessage
appears when none is expected, and it doesn't assert that testCmds remained
empty in the manual branch. Fix by adding an assertion that manualControlMessage
== "" whenever tc.expectedManualControlMessage is empty, and in the branch where
tc.expectedManualControlMessage is non-empty assert testCmds is empty before
returning (i.e., move or add the testCmds emptiness check into the manual branch
prior to the return).

// Check test commands
for _, expected := range tc.expectedTestCommands {
if !strings.Contains(testCmds, expected) {
Expand Down