better description

This commit is contained in:
ston1th 2019-12-06 23:20:46 +01:00
commit 9ee2dc4d06

27
main.go
View file

@ -59,18 +59,18 @@ func mapGitAPI(s string) string {
return "" return ""
} }
func mapState(s string) string { func mapState(s string) (state, description string) {
switch s { switch s {
case "Running": case "Running":
return "pending" return "pending", "Pending - Job triggered."
case "PipelineRunCancelled": case "PipelineRunCancelled":
return "error" return "error", "Job cancelled."
case "Failed": case "Failed":
return "failure" return "failure", "Job failed."
case "Succeeded": case "Succeeded":
return "success" return "success", "Job succeeded."
} }
return "" return "", ""
} }
type Status struct { type Status struct {
@ -184,7 +184,7 @@ func statusUpdate(obj interface{}, s *StatusCache, sec typedcorev1.SecretInterfa
fin = (*f).Time fin = (*f).Time
} }
sha, url := getGit(pr) sha, url := getGit(pr)
if sha == "" { if sha == "" || sha == "master" {
return return
} }
if !s.Set(sha, status, start, fin) { if !s.Set(sha, status, start, fin) {
@ -263,10 +263,15 @@ func postStatus(pr *PipelineRun, gitUrl, sha, status string, sec *corev1.Secret)
if tektonurl == "" { if tektonurl == "" {
log.Printf("missing tektonurl parameter for %s/%s", pr.Namespace, pr.Name) log.Printf("missing tektonurl parameter for %s/%s", pr.Namespace, pr.Name)
} }
pipeline := "tekton"
if pr.Spec.PipelineRef != nil {
pipeline += "-" + pr.Spec.PipelineRef.Name
}
state, desc := mapState(status)
s := &GitStatus{ s := &GitStatus{
Context: "tekton", Context: pipeline,
Description: pr.Name, Description: desc,
State: mapState(status), State: state,
TargetURL: tektonurl, TargetURL: tektonurl,
} }
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
@ -401,7 +406,7 @@ func main() {
return return
} }
sha, _ := getGit(pr) sha, _ := getGit(pr)
if sha != "" { if sha != "" && sha != "master" {
s.Remove(sha) s.Remove(sha)
} }
}, },