/
commit_status_input.go
45 lines (40 loc) · 1.24 KB
/
commit_status_input.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package pipelinerun
import (
"github.com/jenkins-x/go-scm/scm"
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
)
// getCommitStatusInput extracts the various bits from a PipelineRun and
// returns a status record for submitting to the upstream Git Hosting
// Service.
//
// See https://developer.github.com/v3/repos/statuses/#create-a-status and
// https://github.com/jenkins-x/go-scm/blob/b48d209334ed7b167bad3326a481ae3964c7c1a1/scm/repo.go#L88
func getCommitStatusInput(pr *pipelinev1.PipelineRun) *scm.StatusInput {
return &scm.StatusInput{
State: convertState(getPipelineRunState(pr)),
Label: getAnnotationByName(pr, statusContextName, "default"),
Desc: getAnnotationByName(pr, statusDescriptionName, ""),
Target: getAnnotationByName(pr, statusTargetURLName, ""),
}
}
func getAnnotationByName(pr *pipelinev1.PipelineRun, name, def string) string {
for k, v := range pr.Annotations {
if k == name {
return v
}
}
return def
}
// convertState converts between pipeline run state, and the commit status.
func convertState(s State) scm.State {
switch s {
case Failed:
return scm.StateFailure
case Pending:
return scm.StatePending
case Successful:
return scm.StateSuccess
default:
return scm.StateUnknown
}
}