Skip to content

Commit 0838afc

Browse files
committed
fix: erroring when repository config is not present
1 parent c605458 commit 0838afc

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Diff for: cmd/gitlab_server_handlers.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ func GitLabWebhookHandler(ctx context.Context, webhookSecret string) http.Handle
114114

115115
// Check if there exists scm-config file in the repo before moving forward
116116
file, err := client.MergeRequests().GetRemoteConfig(ctx, state.ConfigFilePath(ctx), state.CommitSHA(ctx))
117-
if err != nil {
117+
// only error when global config is not set
118+
if err != nil && state.GlobalConfigFilePath(ctx) == "" {
118119
errHandler(ctx, w, http.StatusOK, err)
119120

120121
return
@@ -125,7 +126,13 @@ func GitLabWebhookHandler(ctx context.Context, webhookSecret string) http.Handle
125126
// In case of a parse error cfg remains "nil" and ProcessMR will try to read-and-parse it
126127
// (but obviously also fail), but will surface the error within the GitLab External Pipeline (if enabled)
127128
// which will surface the issue to the end-user directly
128-
cfg, _ := config.ParseFile(file)
129+
var cfg *config.Config
130+
if file != nil { // file could be nil if no scm-config file is found when global config is set
131+
cfg, _ = config.ParseFile(file)
132+
} else {
133+
// avoid trying to read-and-parse again if global config is set
134+
cfg = config.FromContext(ctx)
135+
}
129136

130137
// Process the MR
131138
if err := ProcessMR(ctx, client, cfg, fullEventPayload); err != nil {

Diff for: cmd/shared.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func ProcessMR(ctx context.Context, client scm.Client, cfg *config.Config, event
115115

116116
// Parse the file
117117
cfg, err = config.ParseFile(file)
118-
if err != nil {
118+
if err != nil { // error on parsing failures when present
119119
return fmt.Errorf("could not parse config file: %w", err)
120120
}
121121
}

0 commit comments

Comments
 (0)