Skip to content

Commit

Permalink
chore: refactor refTarget logic
Browse files Browse the repository at this point in the history
  • Loading branch information
michelmzs committed Dec 5, 2022
1 parent a2dd0a2 commit b7c3e14
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions server/events/vcs/gitlab_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,20 @@ func (g *GitlabClient) UpdateStatus(repo models.Repo, pull models.PullRequest, s
gitlabState = gitlab.Success
}

mr, _ := g.GetMergeRequest(pull.BaseRepo.FullName, pull.Num)
refTarget := ""

if mr.Pipeline == nil {
refTarget = pull.HeadBranch
} else if mr.Pipeline.Source == "merge_request_event" {
refTarget = fmt.Sprintf("refs/merge-requests/%v/head", pull.Num)
} else {
refTarget = pull.HeadBranch
mr, err := g.GetMergeRequest(pull.BaseRepo.FullName, pull.Num)
if err != nil {
return err
}

// refTarget is set to current branch if no pipeline is assigned to the commit,
// otherwise it is set to the pipeline created by the merge_request_event rule
refTarget := pull.HeadBranch
if mr.Pipeline != nil {
if mr.Pipeline.Source == "merge_request_event" {
refTarget = fmt.Sprintf("refs/merge-requests/%d/head", pull.Num)
}
}
_, _, err := g.Client.Commits.SetCommitStatus(repo.FullName, pull.HeadCommit, &gitlab.SetCommitStatusOptions{
_, _, err = g.Client.Commits.SetCommitStatus(repo.FullName, pull.HeadCommit, &gitlab.SetCommitStatusOptions{
State: gitlabState,
Context: gitlab.String(src),
Description: gitlab.String(description),
Expand Down

0 comments on commit b7c3e14

Please sign in to comment.