Merge pull request #241 from SomtochiAma/gitlab-retried-job
Gitlab retried job
This commit is contained in:
commit
8ff5f75a25
|
|
@ -20,6 +20,7 @@ import (
|
|||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/fluxcd/pkg/runtime/events"
|
||||
|
|
@ -91,6 +92,23 @@ func (g *GitLab) Post(event events.Event) error {
|
|||
State: state,
|
||||
}
|
||||
|
||||
listOpts := &gitlab.GetCommitStatusesOptions{}
|
||||
|
||||
status := &gitlab.CommitStatus{
|
||||
Name: name,
|
||||
SHA: rev,
|
||||
Status: string(state),
|
||||
Description: desc,
|
||||
}
|
||||
|
||||
statuses, _, err := g.Client.Commits.GetCommitStatuses(g.Id, rev, listOpts)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to list commit status: %s", err)
|
||||
}
|
||||
if duplicateGitlabStatus(statuses, status) {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, _, err = g.Client.Commits.SetCommitStatus(g.Id, rev, options)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -109,3 +127,15 @@ func toGitLabState(severity string) (gitlab.BuildStateValue, error) {
|
|||
return "", errors.New("can't convert to gitlab state")
|
||||
}
|
||||
}
|
||||
|
||||
func duplicateGitlabStatus(statuses []*gitlab.CommitStatus, status *gitlab.CommitStatus) bool {
|
||||
for _, s := range statuses {
|
||||
if s.SHA == status.SHA {
|
||||
if s.Status == status.Status && s.Description == status.Description && s.Name == status.Name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue