Skip to content

Commit

Permalink
fix: trigger jobs only when there is a GUID
Browse files Browse the repository at this point in the history
Signed-off-by: ankitm123 <ankitmohapatra123@gmail.com>
  • Loading branch information
ankitm123 committed Feb 16, 2022
1 parent aadde90 commit e77c1da
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/plugins/trigger/pull-request.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package trigger
import (
"fmt"
"net/url"
"os"

"github.com/jenkins-x/go-scm/scm"
"github.com/jenkins-x/lighthouse/pkg/config/job"
Expand Down
4 changes: 3 additions & 1 deletion pkg/plugins/trigger/pull-request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package trigger

import (
"os"
"testing"

"github.com/jenkins-x/go-scm/scm"
Expand Down Expand Up @@ -259,7 +260,7 @@ func TestHandlePullRequest(t *testing.T) {
}
for _, tc := range testcases {
t.Logf("running scenario %q", tc.name)

os.Setenv("GIT_KIND", "github")
g := &fake2.SCMClient{
PullRequestComments: map[int][]*scm.Comment{},
OrgMembers: map[string][]string{"org": {"t"}},
Expand Down Expand Up @@ -317,6 +318,7 @@ func TestHandlePullRequest(t *testing.T) {
},
},
},
GUID: "test-guid",
}
if tc.prChanges {
pr.Changes = scm.PullRequestHookChanges{
Expand Down
7 changes: 7 additions & 0 deletions pkg/plugins/trigger/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ func runRequested(c Client, pr *scm.PullRequest, requestedJobs []job.Presubmit,
return err
}

// If there is no eventguid from the scm provider, let's skip the build
// Also, for now, let's skip only github, not sure how other SCM providers handle GUID
if eventGUID == "" && os.Getenv("GIT_KIND") == "github" {
c.Logger.Infof("Skipping build as event GUID is missing for provider %s", os.Getenv("GIT_KIND"))
return fmt.Errorf("event GUID is empty")
}

var errors []error
for _, job := range requestedJobs {
c.Logger.Infof("Starting %s build.", job.Name)
Expand Down
1 change: 0 additions & 1 deletion pkg/triggerconfig/inrepo/load_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func TestMergeConfigIntegration(t *testing.T) {
flag, err := MergeTriggers(cfg, pluginCfg, fileBrowsers, fc, NewResolverCache(), repoOwner, repoName, sha)
require.NoError(t, err, "failed to merge configs")
assert.True(t, flag, "did not return merge flag")

// lets display the context
LogConfig(t, cfg)

Expand Down
1 change: 1 addition & 0 deletions pkg/triggerconfig/inrepo/load_triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func MergeTriggers(cfg *config.Config, pluginCfg *plugins.Configuration, fileBro
if err != nil {
return false, errors.Wrap(err, "failed to load configs")
}

if repoConfig == nil {
return false, nil
}
Expand Down

0 comments on commit e77c1da

Please sign in to comment.