Skip to content

Commit

Permalink
Merge pull request #357 from jstrachan/changes40
Browse files Browse the repository at this point in the history
fix: add retry around looking up the PullRequest
  • Loading branch information
jenkins-x-bot-test authored Apr 6, 2021
2 parents 4bb6b89 + 027ce99 commit 5461d9f
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 29 deletions.
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
22 changes: 20 additions & 2 deletions pkg/environments/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/environments/types.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/jxtesthelpers/jx_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
6 changes: 3 additions & 3 deletions pkg/promote/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/promote/promote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions pkg/promote/promote_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pkg/promote/promote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/promoteconfig/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions pkg/rules/factory/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/rules/file/file_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/rules/helm/helm_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/rules/helmfile/helmfile_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/rules/kpt/kpt_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/rules/types.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 5461d9f

Please sign in to comment.