Skip to content

Commit

Permalink
fix: more resilient check for missing configs
Browse files Browse the repository at this point in the history
  • Loading branch information
jippi committed Aug 30, 2024
1 parent 0e94cc9 commit 32a5a32
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cmd/gitlab_server_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ func GitLabWebhookHandler(ctx context.Context, webhookSecret string) http.Handle
return
}

// Check if there exists scm-config file in the repo before moving forward
if _, err := client.MergeRequests().GetRemoteConfig(ctx, state.ConfigFilePath(ctx), ""); err != nil {
errHandler(ctx, w, http.StatusOK, err)

return
}

// Process the MR
if err := ProcessMR(ctx, client, nil, fullEventPayload); err != nil {
errHandler(ctx, w, http.StatusOK, err)
Expand Down
8 changes: 7 additions & 1 deletion pkg/scm/gitlab/client_merge_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ func (client *MergeRequestClient) GetRemoteConfig(ctx context.Context, filename,
return nil, fmt.Errorf("could not parse project id: %w", err)
}

file, _, err := client.client.wrapped.RepositoryFiles.GetRawFile(project, filename, &go_gitlab.GetRawFileOptions{Ref: scm.Ptr(ref)})
var refPtr *string

if len(ref) != 0 {
refPtr = scm.Ptr(ref)
}

file, _, err := client.client.wrapped.RepositoryFiles.GetRawFile(project, filename, &go_gitlab.GetRawFileOptions{Ref: refPtr})
if err != nil {
return nil, fmt.Errorf("failed to read remote raw file: %w", err)
}
Expand Down

0 comments on commit 32a5a32

Please sign in to comment.