Skip to content

Commit

Permalink
prow/plugins: prioritise repo level triggers over org level ones
Browse files Browse the repository at this point in the history
So far, `TriggerFor` prioristised returning org level trigger configs.
There might be cases where in a trigger would need to be configured
specifically for a repo (ex: allowing `/retest` to trigger GH workflows).
In cases like this, we should return the trigger that is defined at the
repo level, rather than its corresponding org level trigger.

We could "work around" the above constraint by simply defining the repo
level trigger higher up in the config, but then this trigger config would
shadow the org level trigger, which is not desirable.

This change returns a repo level trigger if it finds one, if not, it returns
the first org level trigger it sees (keeping in sync with the previous behaviour).

Fwiw - I'm not sure why multiple org level or multiple repo level triggers for the
same org or repo would be specified.

Signed-off-by: Madhav Jivrajani <[email protected]>
  • Loading branch information
MadhavJivrajani committed Jan 9, 2024
1 parent bd1af29 commit ab1703d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
20 changes: 14 additions & 6 deletions prow/plugins/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,14 +882,22 @@ func (c *Configuration) LgtmFor(org, repo string) *Lgtm {
// a trigger can be listed for the repo itself or for the
// owning organization
func (c *Configuration) TriggerFor(org, repo string) Trigger {
orgRepo := fmt.Sprintf("%s/%s", org, repo)
for _, tr := range c.Triggers {
for _, r := range tr.Repos {
if r == org || r == orgRepo {
return tr
}
fullName := fmt.Sprintf("%s/%s", org, repo)
// Prioritize repo level triggers over org level triggers.
for _, trigger := range c.Triggers {
if !sets.NewString(trigger.Repos...).Has(fullName) {
continue
}
return trigger
}
// If you don't find anything, loop again looking for an org config
for _, trigger := range c.Triggers {
if !sets.NewString(trigger.Repos...).Has(org) {
continue
}
return trigger
}

var tr Trigger
tr.SetDefaults()
return tr
Expand Down
10 changes: 10 additions & 0 deletions prow/plugins/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ func TestTriggerFor(t *testing.T) {
Repos: []string{"k8s/t-i"},
TrustedOrg: "org3",
},
{
Repos: []string{"kuber/utils"},
TrustedOrg: "org4",
},
},
}
config.setDefaults()
Expand All @@ -248,6 +252,12 @@ func TestTriggerFor(t *testing.T) {
repo: "t-i",
expectedTrusted: "org3",
},
{
name: "repo trigger",
org: "kuber",
repo: "utils",
expectedTrusted: "org4",
},
{
name: "default trigger",
org: "other",
Expand Down

0 comments on commit ab1703d

Please sign in to comment.