e2e: Retry the GitHub API calls
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
1
.github/workflows/bootstrap.yaml
vendored
1
.github/workflows/bootstrap.yaml
vendored
@@ -79,6 +79,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITPROVIDER_BOT_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITPROVIDER_BOT_TOKEN }}
|
||||||
GITHUB_REPO_NAME: ${{ steps.vars.outputs.test_repo_name }}
|
GITHUB_REPO_NAME: ${{ steps.vars.outputs.test_repo_name }}
|
||||||
|
GITHUB_ORG_NAME: fluxcd-testing
|
||||||
- name: libgit2
|
- name: libgit2
|
||||||
run: |
|
run: |
|
||||||
/tmp/flux create source git test-libgit2 \
|
/tmp/flux create source git test-libgit2 \
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fluxcd/go-git-providers/github"
|
"github.com/fluxcd/go-git-providers/github"
|
||||||
"github.com/fluxcd/go-git-providers/gitprovider"
|
"github.com/fluxcd/go-git-providers/gitprovider"
|
||||||
|
"k8s.io/client-go/util/retry"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -55,8 +56,10 @@ spec:
|
|||||||
Content: &patchContent,
|
Content: &patchContent,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
orgName := os.Getenv("GITHUB_ORG_NAME")
|
||||||
repoName := os.Getenv("GITHUB_REPO_NAME")
|
repoName := os.Getenv("GITHUB_REPO_NAME")
|
||||||
githubToken := os.Getenv("GITHUB_TOKEN")
|
githubToken := os.Getenv(github.TokenVariable)
|
||||||
client, err := github.NewClient(github.WithOAuth2Token(githubToken))
|
client, err := github.NewClient(github.WithOAuth2Token(githubToken))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error initializing github client: %s", err)
|
log.Fatalf("error initializing github client: %s", err)
|
||||||
@@ -64,12 +67,27 @@ spec:
|
|||||||
|
|
||||||
repoRef := gitprovider.OrgRepositoryRef{
|
repoRef := gitprovider.OrgRepositoryRef{
|
||||||
OrganizationRef: gitprovider.OrganizationRef{
|
OrganizationRef: gitprovider.OrganizationRef{
|
||||||
Organization: "flux-testing",
|
Organization: orgName,
|
||||||
Domain: "github.com",
|
Domain: github.DefaultDomain,
|
||||||
},
|
},
|
||||||
RepositoryName: repoName,
|
RepositoryName: repoName,
|
||||||
}
|
}
|
||||||
repo, err := client.OrgRepositories().Get(context.Background(), repoRef)
|
|
||||||
|
if ok, err := client.HasTokenPermission(context.Background(), gitprovider.TokenPermissionRWRepository); err != nil {
|
||||||
|
log.Fatalf("error getting token permission: %s", err)
|
||||||
|
} else {
|
||||||
|
if !ok {
|
||||||
|
log.Fatal("token has no write permissions")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var repo gitprovider.OrgRepository
|
||||||
|
err = retry.OnError(retry.DefaultRetry, func(err error) bool {
|
||||||
|
return err != nil
|
||||||
|
}, func() error {
|
||||||
|
repo, err = client.OrgRepositories().Get(context.Background(), repoRef)
|
||||||
|
return err
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error getting %s repository in org %s: %s", repoRef.RepositoryName, repoRef.Organization, err)
|
log.Fatalf("error getting %s repository in org %s: %s", repoRef.RepositoryName, repoRef.Organization, err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user