func()

in pkg/event_processor/gitlab/gitlab.go [73:116]


func (p *EventProcessor) processCommentEvent(ctx context.Context, body []byte, ns string) (*event_processor.EventInfo, error) {
	gitLabEvent := &event_processor.GitLabCommentEvent{}
	if err := json.Unmarshal(body, gitLabEvent); err != nil {
		return nil, fmt.Errorf("failed to unmarshal GitLab event: %w", err)
	}

	if gitLabEvent.Project.PathWithNamespace == "" {
		return nil, errors.New("gitlab repository path empty")
	}

	repoPath := event_processor.ConvertRepositoryPath(gitLabEvent.Project.PathWithNamespace)

	codebase, err := event_processor.GetCodebaseByRepoPath(ctx, p.ksClient, ns, repoPath)
	if err != nil {
		return nil, fmt.Errorf("failed to get codebase by repo path: %w", err)
	}

	// The comment was added not to the merge request if TargetBranch is empty.
	// Skip processing such events.
	if gitLabEvent.MergeRequest.TargetBranch == "" {
		return &event_processor.EventInfo{
			GitProvider:        event_processor.GitProviderGitLab,
			Type:               event_processor.EventTypeReviewComment,
			Codebase:           codebase,
			HasPipelineRecheck: false,
		}, nil
	}

	return &event_processor.EventInfo{
		GitProvider:        event_processor.GitProviderGitLab,
		RepoPath:           repoPath,
		TargetBranch:       gitLabEvent.MergeRequest.TargetBranch,
		Type:               event_processor.EventTypeReviewComment,
		Codebase:           codebase,
		HasPipelineRecheck: event_processor.ContainsPipelineRecheck(gitLabEvent.ObjectAttributes.Note),
		PullRequest: &event_processor.PullRequest{
			HeadSha:           gitLabEvent.MergeRequest.LastCommit.ID,
			Title:             gitLabEvent.MergeRequest.Title,
			HeadRef:           gitLabEvent.MergeRequest.SourceBranch,
			ChangeNumber:      gitLabEvent.MergeRequest.ChangeNumber,
			LastCommitMessage: gitLabEvent.MergeRequest.LastCommit.Message,
		},
	}, nil
}