diff --git a/go.mod b/go.mod index 30dd036..e30bf4f 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,13 @@ module github.com/jenkins-x-plugins/jx-promote require ( github.com/Azure/go-autorest/autorest/azure/auth v0.4.2 // indirect github.com/blang/semver v3.5.1+incompatible + github.com/cenkalti/backoff v2.2.1+incompatible github.com/cpuguy83/go-md2man v1.0.10 github.com/hashicorp/go-retryablehttp v0.6.6 // indirect github.com/hashicorp/vault/api v1.0.5-0.20190909201928-35325e2c3262 // indirect - github.com/jenkins-x-plugins/jx-gitops v0.2.42 + github.com/jenkins-x-plugins/jx-gitops v0.2.45 github.com/jenkins-x/go-scm v1.6.13 - github.com/jenkins-x/jx-api/v4 v4.0.27 + github.com/jenkins-x/jx-api/v4 v4.0.28 github.com/jenkins-x/jx-helpers/v3 v3.0.94 github.com/jenkins-x/jx-logging/v3 v3.0.3 github.com/mitchellh/mapstructure v1.3.1 // indirect diff --git a/go.sum b/go.sum index bfd1fe1..3893f15 100644 --- a/go.sum +++ b/go.sum @@ -777,25 +777,26 @@ github.com/jcmturner/gofork v0.0.0-20190328161633-dc7c13fece03/go.mod h1:MK8+TM0 github.com/jcmturner/gofork v1.0.0/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o= github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4= github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag= -github.com/jenkins-x-plugins/jx-gitops v0.2.42 h1:sj5dkqEau81xg6ROL0dql0/HQsZuXD3+mLPAlYXumPk= -github.com/jenkins-x-plugins/jx-gitops v0.2.42/go.mod h1:4m18XQV3wrJ/3i1FDpOugi+eB2lsMXLbvr7td6tvRSk= +github.com/jenkins-x-plugins/jx-gitops v0.2.45 h1:97rOTmdyQ9CUvVnzVgMz/oDobo2dwUJgrkeLtsn/w/4= +github.com/jenkins-x-plugins/jx-gitops v0.2.45/go.mod h1:P95+D6KWj2VyOmlBT8RVY1ARA/xrz8LD0JsySqYo0ds= github.com/jenkins-x/go-scm v1.5.117/go.mod h1:PCT338UhP/pQ0IeEeMEf/hoLTYKcH7qjGEKd7jPkeYg= github.com/jenkins-x/go-scm v1.6.7 h1:Tc8yLV1B0OdKCbtQX76Bc5FfbsvShqa+HWrTky92vGY= github.com/jenkins-x/go-scm v1.6.7/go.mod h1:yVqpMl3ZSkPWVcPi9EhcK3QtTM/anrtYqI//FqwrdxQ= -github.com/jenkins-x/go-scm v1.6.12/go.mod h1:yVqpMl3ZSkPWVcPi9EhcK3QtTM/anrtYqI//FqwrdxQ= github.com/jenkins-x/go-scm v1.6.13 h1:KSAWADqZ2JHj8ZUXOhV4Ua+1wySP1i4dfAREU1lMF4E= github.com/jenkins-x/go-scm v1.6.13/go.mod h1:z7xTO9/VzqW3xEbEMH2z5cpOGrZ8+nOHOWfU1ngFGxs= github.com/jenkins-x/jx-api/v4 v4.0.25 h1:G80im88KcIOH8smhzvK/6qOI76RB328dAX9Wneb+xyo= github.com/jenkins-x/jx-api/v4 v4.0.25/go.mod h1:IC88X+24Nmexuj7lRNRgzfrchzlo0qysfwkICpqDmMQ= github.com/jenkins-x/jx-api/v4 v4.0.27 h1:jTobmwxeoGW/srvgIjLs/w9l5kf+rdwj8eFqik6P1bQ= github.com/jenkins-x/jx-api/v4 v4.0.27/go.mod h1:IC88X+24Nmexuj7lRNRgzfrchzlo0qysfwkICpqDmMQ= +github.com/jenkins-x/jx-api/v4 v4.0.28 h1:pbOOWGsGDKdgx24wRGl/ktZujHXZGTSA1C5pnPX3p8c= +github.com/jenkins-x/jx-api/v4 v4.0.28/go.mod h1:IC88X+24Nmexuj7lRNRgzfrchzlo0qysfwkICpqDmMQ= github.com/jenkins-x/jx-helpers/v3 v3.0.94 h1:THD8JO12kqmWMSicR5MeNGfv39jYi6cXSMhFGoQznZE= github.com/jenkins-x/jx-helpers/v3 v3.0.94/go.mod h1:izx/zfU0JS0XsQY0paBDcUtnWodgxKG7urA12koeLpU= github.com/jenkins-x/jx-kube-client/v3 v3.0.2 h1:sJs6FaIwycDYwE4UsA7j9tpdXOxXEta9KNUJp6s45VI= github.com/jenkins-x/jx-kube-client/v3 v3.0.2/go.mod h1:C/mKnCT5wvolX61eLKJVBNev9sqnkGNpi4skTQ1Gr3Q= github.com/jenkins-x/jx-logging/v3 v3.0.3 h1:sVACbwiKuaDFYPfJeVAU10MJI4DA6LcH1RqJKwfNozc= github.com/jenkins-x/jx-logging/v3 v3.0.3/go.mod h1:Vp2ER2SYgGhAgEEHlLwfi2ZB54tz6ya1qExq0A4CKMI= -github.com/jenkins-x/lighthouse-client v0.0.88/go.mod h1:FZQJ/tzKIiG0IAUksTqfWdjqcMyue1sJka0DUBP+FMQ= +github.com/jenkins-x/lighthouse-client v0.0.89/go.mod h1:zCT07+5vUglC0nyRcTRAWW/FVOtLYb5qkM2Z3NzX4Oo= github.com/jenkins-x/logrus-stackdriver-formatter v0.2.3 h1:NuRWKUPCEX1wKlXA8ZYSG28qGKd41R7BK11YDQkPwqo= github.com/jenkins-x/logrus-stackdriver-formatter v0.2.3/go.mod h1:litPp7VZWDRCl8LvXuqGngy+65kkg/+T23TgFnDmfTk= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= diff --git a/pkg/environments/pr.go b/pkg/environments/pr.go index a6a0d1c..1c6c6d2 100644 --- a/pkg/environments/pr.go +++ b/pkg/environments/pr.go @@ -4,6 +4,9 @@ import ( "context" "fmt" "strings" + "time" + + "github.com/cenkalti/backoff" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/jx-helpers/v3/pkg/cmdrunner" @@ -186,10 +189,25 @@ func (o *EnvironmentPullRequestOptions) addLabelsToPullRequest(ctx context.Conte return pr, nil } var err error - pr, _, err = scmClient.PullRequests.Find(ctx, repoFullName, prNumber) + + // lets use a retry loop to push in case the repository is not yet setup quite yet + f := func() error { + pr, _, err = scmClient.PullRequests.Find(ctx, repoFullName, prNumber) + if err != nil { + return errors.Wrapf(err, "failed to lookup PullRequest #%d on repo %s", prNumber, repoFullName) + } + return nil + } + + bo := backoff.NewExponentialBackOff() + bo.InitialInterval = 3 * time.Second + bo.MaxElapsedTime = time.Minute + bo.Reset() + err = backoff.Retry(f, bo) if err != nil { - return nil, errors.Wrapf(err, "failed to lookup PullRequest #%d on repo %s", prNumber, repoFullName) + return pr, err } + return pr, nil } diff --git a/pkg/environments/types.go b/pkg/environments/types.go index d3cb3bc..5b4e0d2 100644 --- a/pkg/environments/types.go +++ b/pkg/environments/types.go @@ -1,14 +1,14 @@ package environments import ( + "github.com/jenkins-x-plugins/jx-promote/pkg/apis/promote/v1alpha1" + "github.com/jenkins-x-plugins/jx-promote/pkg/envctx" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/jx-api/v4/pkg/client/clientset/versioned" "github.com/jenkins-x/jx-helpers/v3/pkg/cmdrunner" "github.com/jenkins-x/jx-helpers/v3/pkg/gitclient" "github.com/jenkins-x/jx-helpers/v3/pkg/helmer" "github.com/jenkins-x/jx-helpers/v3/pkg/scmhelpers" - "github.com/jenkins-x-plugins/jx-promote/pkg/apis/promote/v1alpha1" - "github.com/jenkins-x-plugins/jx-promote/pkg/envctx" "helm.sh/helm/v3/pkg/chart" ) diff --git a/pkg/jxtesthelpers/jx_resources.go b/pkg/jxtesthelpers/jx_resources.go index 21755bd..2e8a193 100644 --- a/pkg/jxtesthelpers/jx_resources.go +++ b/pkg/jxtesthelpers/jx_resources.go @@ -4,11 +4,11 @@ import ( "path" "testing" + "github.com/jenkins-x-plugins/jx-promote/pkg/envctx" jxcore "github.com/jenkins-x/jx-api/v4/pkg/apis/core/v4beta1" v1 "github.com/jenkins-x/jx-api/v4/pkg/apis/jenkins.io/v1" "github.com/jenkins-x/jx-helpers/v3/pkg/kube/jxenv" "github.com/jenkins-x/jx-helpers/v3/pkg/versionstream" - "github.com/jenkins-x-plugins/jx-promote/pkg/envctx" "github.com/stretchr/testify/assert" ) diff --git a/pkg/promote/pr.go b/pkg/promote/pr.go index 1de8e98..b8e9ecd 100644 --- a/pkg/promote/pr.go +++ b/pkg/promote/pr.go @@ -7,12 +7,12 @@ import ( jxcore "github.com/jenkins-x/jx-api/v4/pkg/apis/core/v4beta1" - "github.com/jenkins-x/go-scm/scm" - "github.com/jenkins-x/jx-helpers/v3/pkg/gitclient" - "github.com/jenkins-x/jx-helpers/v3/pkg/gitclient/gitconfig" "github.com/jenkins-x-plugins/jx-promote/pkg/promoteconfig" "github.com/jenkins-x-plugins/jx-promote/pkg/rules" "github.com/jenkins-x-plugins/jx-promote/pkg/rules/factory" + "github.com/jenkins-x/go-scm/scm" + "github.com/jenkins-x/jx-helpers/v3/pkg/gitclient" + "github.com/jenkins-x/jx-helpers/v3/pkg/gitclient/gitconfig" "github.com/pkg/errors" ) diff --git a/pkg/promote/promote.go b/pkg/promote/promote.go index a6e7a28..ff0155d 100644 --- a/pkg/promote/promote.go +++ b/pkg/promote/promote.go @@ -14,9 +14,10 @@ import ( "github.com/jenkins-x/jx-helpers/v3/pkg/gitclient/cli" + "github.com/jenkins-x-plugins/jx-gitops/pkg/cmd/git/setup" + "github.com/jenkins-x-plugins/jx-promote/pkg/environments" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/jx-api/v4/pkg/client/clientset/versioned" - "github.com/jenkins-x-plugins/jx-gitops/pkg/cmd/git/setup" "github.com/jenkins-x/jx-helpers/v3/pkg/builds" "github.com/jenkins-x/jx-helpers/v3/pkg/files" "github.com/jenkins-x/jx-helpers/v3/pkg/gitclient" @@ -31,7 +32,6 @@ import ( "github.com/jenkins-x/jx-helpers/v3/pkg/options" "github.com/jenkins-x/jx-helpers/v3/pkg/stringhelpers" "github.com/jenkins-x/jx-helpers/v3/pkg/termcolor" - "github.com/jenkins-x-plugins/jx-promote/pkg/environments" "k8s.io/client-go/kubernetes" "github.com/jenkins-x/jx-helpers/v3/pkg/cobras/helper" diff --git a/pkg/promote/promote_integration_test.go b/pkg/promote/promote_integration_test.go index 6033d1c..39aa302 100644 --- a/pkg/promote/promote_integration_test.go +++ b/pkg/promote/promote_integration_test.go @@ -14,14 +14,14 @@ import ( "github.com/roboll/helmfile/pkg/state" "k8s.io/api/extensions/v1beta1" + "github.com/jenkins-x-plugins/jx-promote/pkg/jxtesthelpers" + "github.com/jenkins-x-plugins/jx-promote/pkg/promote" "github.com/jenkins-x/go-scm/scm" v1 "github.com/jenkins-x/jx-api/v4/pkg/apis/jenkins.io/v1" v1fake "github.com/jenkins-x/jx-api/v4/pkg/client/clientset/versioned/fake" "github.com/jenkins-x/jx-helpers/v3/pkg/cmdrunner" "github.com/jenkins-x/jx-helpers/v3/pkg/cmdrunner/fakerunner" "github.com/jenkins-x/jx-helpers/v3/pkg/stringhelpers" - "github.com/jenkins-x-plugins/jx-promote/pkg/jxtesthelpers" - "github.com/jenkins-x-plugins/jx-promote/pkg/promote" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/promote/promote_test.go b/pkg/promote/promote_test.go index 9366cbe..01d0b1f 100644 --- a/pkg/promote/promote_test.go +++ b/pkg/promote/promote_test.go @@ -9,10 +9,10 @@ import ( jxcore "github.com/jenkins-x/jx-api/v4/pkg/apis/core/v4beta1" "github.com/stretchr/testify/require" + "github.com/jenkins-x-plugins/jx-promote/pkg/promote" v1 "github.com/jenkins-x/jx-api/v4/pkg/apis/jenkins.io/v1" "github.com/jenkins-x/jx-helpers/v3/pkg/input/fake" "github.com/jenkins-x/jx-helpers/v3/pkg/testhelpers" - "github.com/jenkins-x-plugins/jx-promote/pkg/promote" "github.com/stretchr/testify/assert" ) diff --git a/pkg/promoteconfig/helpers.go b/pkg/promoteconfig/helpers.go index 55e1c8f..9054e13 100644 --- a/pkg/promoteconfig/helpers.go +++ b/pkg/promoteconfig/helpers.go @@ -5,8 +5,8 @@ import ( "io/ioutil" "path/filepath" - "github.com/jenkins-x/jx-helpers/v3/pkg/files" "github.com/jenkins-x-plugins/jx-promote/pkg/apis/promote/v1alpha1" + "github.com/jenkins-x/jx-helpers/v3/pkg/files" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/yaml" diff --git a/pkg/rules/factory/factory_test.go b/pkg/rules/factory/factory_test.go index e835d18..757f426 100644 --- a/pkg/rules/factory/factory_test.go +++ b/pkg/rules/factory/factory_test.go @@ -6,13 +6,13 @@ import ( "strings" "testing" - "github.com/jenkins-x/jx-helpers/v3/pkg/files" - "github.com/jenkins-x/jx-helpers/v3/pkg/testhelpers" "github.com/jenkins-x-plugins/jx-promote/pkg/apis/promote/v1alpha1" "github.com/jenkins-x-plugins/jx-promote/pkg/jxtesthelpers" "github.com/jenkins-x-plugins/jx-promote/pkg/promoteconfig" "github.com/jenkins-x-plugins/jx-promote/pkg/rules" "github.com/jenkins-x-plugins/jx-promote/pkg/rules/factory" + "github.com/jenkins-x/jx-helpers/v3/pkg/files" + "github.com/jenkins-x/jx-helpers/v3/pkg/testhelpers" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/rules/file/file_rule.go b/pkg/rules/file/file_rule.go index 3073855..7b45fe2 100644 --- a/pkg/rules/file/file_rule.go +++ b/pkg/rules/file/file_rule.go @@ -7,11 +7,11 @@ import ( "strings" "text/template" + "github.com/jenkins-x-plugins/jx-promote/pkg/apis/promote/v1alpha1" + "github.com/jenkins-x-plugins/jx-promote/pkg/rules" "github.com/jenkins-x/jx-helpers/v3/pkg/files" "github.com/jenkins-x/jx-helpers/v3/pkg/termcolor" "github.com/jenkins-x/jx-logging/v3/pkg/log" - "github.com/jenkins-x-plugins/jx-promote/pkg/apis/promote/v1alpha1" - "github.com/jenkins-x-plugins/jx-promote/pkg/rules" "github.com/pkg/errors" ) diff --git a/pkg/rules/helm/helm_rule.go b/pkg/rules/helm/helm_rule.go index 3276fad..b65bb9f 100644 --- a/pkg/rules/helm/helm_rule.go +++ b/pkg/rules/helm/helm_rule.go @@ -3,9 +3,9 @@ package helm import ( "path/filepath" + "github.com/jenkins-x-plugins/jx-promote/pkg/rules" "github.com/jenkins-x/jx-helpers/v3/pkg/files" "github.com/jenkins-x/jx-helpers/v3/pkg/helmer" - "github.com/jenkins-x-plugins/jx-promote/pkg/rules" "github.com/pkg/errors" ) diff --git a/pkg/rules/helmfile/helmfile_rule.go b/pkg/rules/helmfile/helmfile_rule.go index a16211f..8c12252 100644 --- a/pkg/rules/helmfile/helmfile_rule.go +++ b/pkg/rules/helmfile/helmfile_rule.go @@ -8,11 +8,11 @@ import ( jxcore "github.com/jenkins-x/jx-api/v4/pkg/apis/core/v4beta1" - "github.com/jenkins-x/jx-helpers/v3/pkg/files" - "github.com/jenkins-x/jx-helpers/v3/pkg/yaml2s" "github.com/jenkins-x-plugins/jx-promote/pkg/apis/promote/v1alpha1" "github.com/jenkins-x-plugins/jx-promote/pkg/envctx" "github.com/jenkins-x-plugins/jx-promote/pkg/rules" + "github.com/jenkins-x/jx-helpers/v3/pkg/files" + "github.com/jenkins-x/jx-helpers/v3/pkg/yaml2s" "github.com/pkg/errors" "github.com/roboll/helmfile/pkg/state" ) diff --git a/pkg/rules/kpt/kpt_rule.go b/pkg/rules/kpt/kpt_rule.go index 940d17e..13099f1 100644 --- a/pkg/rules/kpt/kpt_rule.go +++ b/pkg/rules/kpt/kpt_rule.go @@ -5,10 +5,10 @@ import ( "path/filepath" "strings" + "github.com/jenkins-x-plugins/jx-promote/pkg/rules" "github.com/jenkins-x/jx-helpers/v3/pkg/cmdrunner" "github.com/jenkins-x/jx-helpers/v3/pkg/files" "github.com/jenkins-x/jx-logging/v3/pkg/log" - "github.com/jenkins-x-plugins/jx-promote/pkg/rules" "github.com/pkg/errors" ) diff --git a/pkg/rules/types.go b/pkg/rules/types.go index 91d1bb1..282cd03 100644 --- a/pkg/rules/types.go +++ b/pkg/rules/types.go @@ -1,9 +1,9 @@ package rules import ( - "github.com/jenkins-x/jx-helpers/v3/pkg/cmdrunner" "github.com/jenkins-x-plugins/jx-promote/pkg/apis/promote/v1alpha1" "github.com/jenkins-x-plugins/jx-promote/pkg/envctx" + "github.com/jenkins-x/jx-helpers/v3/pkg/cmdrunner" ) // PromoteRule represents a profile rule