From 32eaa110375af1d357caba09d9c73141e9480ec1 Mon Sep 17 00:00:00 2001 From: ston1th Date: Wed, 4 Dec 2019 14:35:13 +0100 Subject: [PATCH] updated readme --- README.md | 6 +++--- main.go | 30 ++++++++++++++---------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 1588156..1dbebae 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # status-reporter -The status reporter is a controller that watches pipelineruns for status cahnges. +The status reporter is a controller that watches tekton `PipelineRuns` for status cahnges. These are synced to the associated git commit hashes. For successful runs a preview environment comment will be added to the pull request. @@ -13,11 +13,11 @@ Params: * issue - pull request issue id * scheme - `http://` or `https://` * tektonurl - `http://tekton-dashboard.example.com` -* previewurl - url to your deployed preview environment +* previewurl - `my-preview-env.example.com` Resources: -* git - revision: githash, url: clone_url +* git - revision: git commit hash, url: `https://github.com/example/repo.git` # Requirements diff --git a/main.go b/main.go index a3bedb2..e336c86 100644 --- a/main.go +++ b/main.go @@ -21,12 +21,11 @@ import ( pipelinev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/client/clientset/versioned" extinf "github.com/tektoncd/pipeline/pkg/client/informers/externalversions" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1" - //"k8s.io/apimachinery/pkg/types" - //"k8s.io/client-go/informers" "k8s.io/client-go/kubernetes" + typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1" "k8s.io/client-go/rest" "k8s.io/client-go/tools/cache" ) @@ -88,7 +87,7 @@ func NewStatusCache() *StatusCache { return &StatusCache{cache: make(map[string]Status)} } -func (sc *StatusCache) Set(sha, status string, st, fin time.Time) bool { +func (sc *StatusCache) Set(sha, status string, st, fin time.Time) (ret bool) { sc.Lock() defer sc.Unlock() s, ok := sc.cache[sha] @@ -102,26 +101,25 @@ func (sc *StatusCache) Set(sha, status string, st, fin time.Time) bool { return true } if fin.After(s.Date) { - log.Printf("updating status in cache: %s %s", sha, status) sc.cache[sha] = Status{status, fin} - return true + ret = true } - if st.After(s.Date) { - log.Printf("updating status in cache: %s %s", sha, status) + if !ret && st.After(s.Date) { sc.cache[sha] = Status{status, st} - return true + ret = true } - if fin.Equal(s.Date) && s.Type != status { - log.Printf("updating status in cache: %s %s", sha, status) + if !ret && fin.Equal(s.Date) && s.Type != status { sc.cache[sha] = Status{status, fin} - return true + ret = true } - if st.Equal(s.Date) && s.Type != status { - log.Printf("updating status in cache: %s %s", sha, status) + if !ret && st.Equal(s.Date) && s.Type != status { sc.cache[sha] = Status{status, st} - return true + ret = true } - return false + if ret { + log.Printf("updating status in cache: %s %s", sha, status) + } + return ret } func (sc *StatusCache) Remove(sha string) {