Skip to content

Commit

Permalink
e2e: add more log of where the github push going
Browse files Browse the repository at this point in the history
we would not be able to see the github push url in the logs, this is
to help for failures.
  • Loading branch information
chmouel authored and savitaashture committed Feb 1, 2024
1 parent 4ffa114 commit 4bdfa0f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
4 changes: 2 additions & 2 deletions test/github_incoming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ func verifyIncomingWebhook(t *testing.T, randomedString string, entries map[stri
targetRefName := fmt.Sprintf("refs/heads/%s", randomedString)

title := "TestGithubAppIncoming - " + randomedString
sha, err := tgithub.PushFilesToRef(ctx, ghprovider.Client, title,
sha, vref, err := tgithub.PushFilesToRef(ctx, ghprovider.Client, title,
repoinfo.GetDefaultBranch(),
targetRefName,
opts.Organization,
opts.Repo,
entries)
assert.NilError(t, err)
runcnx.Clients.Log.Infof("Commit %s has been created and pushed to branch %s", sha, targetRefName)
runcnx.Clients.Log.Infof("Commit %s has been created and pushed to branch %s", sha, vref.GetURL())

url := fmt.Sprintf("%s/incoming?repository=%s&branch=%s&pipelinerun=%s&secret=%s", opts.ControllerURL,
randomedString, randomedString, "pipelinerun-incoming", incomingSecreteValue)
Expand Down
4 changes: 2 additions & 2 deletions test/github_pullrequest_concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ func TestGithubPullRequestConcurrency(t *testing.T) {
targetRefName := fmt.Sprintf("refs/heads/%s",
names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("pac-e2e-test"))

sha, err := tgithub.PushFilesToRef(ctx, ghcnx.Client, logmsg, repoinfo.GetDefaultBranch(), targetRefName,
sha, vref, err := tgithub.PushFilesToRef(ctx, ghcnx.Client, logmsg, repoinfo.GetDefaultBranch(), targetRefName,
opts.Organization, opts.Repo, entries)
assert.NilError(t, err)
runcnx.Clients.Log.Infof("Commit %s has been created and pushed to %s", sha, targetRefName)
runcnx.Clients.Log.Infof("Commit %s has been created and pushed to %s", sha, vref.GetURL())

prNumber, err := tgithub.PRCreate(ctx, runcnx, ghcnx, opts.Organization,
opts.Repo, targetRefName, repoinfo.GetDefaultBranch(), logmsg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ func verifyGHTokenScope(t *testing.T, remoteTaskURL, remoteTaskName string, data
targetRefName := fmt.Sprintf("refs/heads/%s",
names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("pac-e2e-test"))

sha, err := tgithub.PushFilesToRef(ctx, ghcnx.Client, "TestPullRequestRemoteAnnotations - "+targetRefName, repoinfo.GetDefaultBranch(), targetRefName, opts.Organization, opts.Repo, entries)
sha, vref, err := tgithub.PushFilesToRef(ctx, ghcnx.Client, "TestPullRequestRemoteAnnotations - "+targetRefName, repoinfo.GetDefaultBranch(), targetRefName, opts.Organization, opts.Repo, entries)
assert.NilError(t, err)
runcnx.Clients.Log.Infof("Commit %s has been created and pushed to %s", sha, targetRefName)
runcnx.Clients.Log.Infof("Commit %s has been created and pushed to %s", sha, vref.GetURL())

title := "TestPullRequestRemoteAnnotations - " + targetRefName
number, err := tgithub.PRCreate(ctx, runcnx, ghcnx, opts.Organization, opts.Repo, targetRefName, repoinfo.GetDefaultBranch(), title)
Expand Down
4 changes: 2 additions & 2 deletions test/github_tkn_pac_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ spec:
targetRefName := fmt.Sprintf("refs/heads/%s",
names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("pac-e2e-test"))

sha, err := tgithub.PushFilesToRef(ctx, ghprovider.Client, "TestPacCli - "+targetRefName, repoinfo.GetDefaultBranch(), targetRefName, opts.Organization, opts.Repo, entries)
sha, vref, err := tgithub.PushFilesToRef(ctx, ghprovider.Client, "TestPacCli - "+targetRefName, repoinfo.GetDefaultBranch(), targetRefName, opts.Organization, opts.Repo, entries)
assert.NilError(t, err)
runcnx.Clients.Log.Infof("Commit %s has been created and pushed to %s", sha, targetRefName)
runcnx.Clients.Log.Infof("Commit %s has been created and pushed to %s", sha, vref.GetURL())

title := "TestPacCli - " + targetRefName
number, err := tgithub.PRCreate(ctx, runcnx, ghprovider, opts.Organization, opts.Repo, targetRefName, repoinfo.GetDefaultBranch(), title)
Expand Down
25 changes: 12 additions & 13 deletions test/pkg/github/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
"gotest.tools/v3/assert"
)

func PushFilesToRef(ctx context.Context, client *github.Client, commitMessage, baseBranch, targetRef, owner, repo string, files map[string]string) (string, error) {
func PushFilesToRef(ctx context.Context, client *github.Client, commitMessage, baseBranch, targetRef, owner, repo string, files map[string]string) (string, *github.Reference, error) {
maintree, _, err := client.Git.GetTree(ctx, owner, repo, baseBranch, false)
if err != nil {
return "", fmt.Errorf("error getting tree: %w", err)
return "", nil, fmt.Errorf("error getting tree: %w", err)
}
mainSha := maintree.GetSHA()
entries := []*github.TreeEntry{}
Expand All @@ -34,7 +34,7 @@ func PushFilesToRef(ctx context.Context, client *github.Client, commitMessage, b
Encoding: &encoding,
})
if err != nil {
return "", fmt.Errorf("error creating blobs: %w", err)
return "", nil, fmt.Errorf("error creating blobs: %w", err)
}
sha := blob.GetSHA()

Expand All @@ -49,7 +49,7 @@ func PushFilesToRef(ctx context.Context, client *github.Client, commitMessage, b

tree, _, err := client.Git.CreateTree(ctx, owner, repo, mainSha, entries)
if err != nil {
return "", err
return "", nil, err
}

commitAuthor := "OpenShift Pipelines E2E test"
Expand All @@ -68,7 +68,7 @@ func PushFilesToRef(ctx context.Context, client *github.Client, commitMessage, b
},
}, &github.CreateCommitOptions{})
if err != nil {
return "", err
return "", nil, err
}

ref := &github.Reference{
Expand All @@ -77,12 +77,12 @@ func PushFilesToRef(ctx context.Context, client *github.Client, commitMessage, b
SHA: commit.SHA,
},
}
_, _, err = client.Git.CreateRef(ctx, owner, repo, ref)
vref, _, err := client.Git.CreateRef(ctx, owner, repo, ref)
if err != nil {
return "", err
return "", nil, err
}

return commit.GetSHA(), nil
return commit.GetSHA(), vref, nil
}

func PRCreate(ctx context.Context, cs *params.Run, ghcnx *ghprovider.Provider, owner, repo, targetRef, defaultBranch, title string) (int, error) {
Expand Down Expand Up @@ -129,11 +129,10 @@ func RunPullRequest(ctx context.Context, t *testing.T, label string, yamlFiles [
targetRefName := fmt.Sprintf("refs/heads/%s",
names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("pac-e2e-test"))

sha, err := PushFilesToRef(ctx, ghcnx.Client, logmsg, repoinfo.GetDefaultBranch(), targetRefName,
sha, vref, err := PushFilesToRef(ctx, ghcnx.Client, logmsg, repoinfo.GetDefaultBranch(), targetRefName,
opts.Organization, opts.Repo, entries)
assert.NilError(t, err)
runcnx.Clients.Log.Infof("Commit %s has been created and pushed to %s", sha, targetRefName)

runcnx.Clients.Log.Infof("Commit %s has been created and pushed to %s", sha, vref.GetURL())
number, err := PRCreate(ctx, runcnx, ghcnx, opts.Organization,
opts.Repo, targetRefName, repoinfo.GetDefaultBranch(), logmsg)
assert.NilError(t, err)
Expand Down Expand Up @@ -182,8 +181,8 @@ func RunPushRequest(ctx context.Context, t *testing.T, label string, yamlFiles [
assert.NilError(t, err)

targetRefName := fmt.Sprintf("refs/heads/%s", targetBranch)
sha, err := PushFilesToRef(ctx, ghcnx.Client, logmsg, repoinfo.GetDefaultBranch(), targetRefName, opts.Organization, opts.Repo, entries)
runcnx.Clients.Log.Infof("Commit %s has been created and pushed to %s", sha, targetRefName)
sha, vref, err := PushFilesToRef(ctx, ghcnx.Client, logmsg, repoinfo.GetDefaultBranch(), targetRefName, opts.Organization, opts.Repo, entries)
runcnx.Clients.Log.Infof("Commit %s has been created and pushed to %s", sha, vref.GetURL())
assert.NilError(t, err)

sopt := wait.SuccessOpt{
Expand Down

0 comments on commit 4bdfa0f

Please sign in to comment.