Skip to content

Commit

Permalink
feat(RHTAPREL-874): add e2e test for rhtap-service-push
Browse files Browse the repository at this point in the history
Signed-off-by: Jing Qi <[email protected]>

Add e2e test case for rhtap-service-push pipeline
  • Loading branch information
jinqi7 committed Mar 15, 2024
1 parent 38f7b46 commit 2b19d90
Show file tree
Hide file tree
Showing 10 changed files with 440 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pkg/clients/github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"time"

"github.com/gofri/go-github-ratelimit/github_ratelimit"
"github.com/google/go-github/v44/github"
"github.com/google/go-github/v60/github"
"golang.org/x/oauth2"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/clients/github/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

. "github.com/onsi/gomega"

"github.com/google/go-github/v44/github"
"github.com/google/go-github/v60/github"
)

func (g *Github) DeleteRef(repository, branchName string) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/clients/github/pull_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"time"

"github.com/google/go-github/v44/github"
"github.com/google/go-github/v60/github"
)

func (g *Github) GetPullRequest(repository string, id int) (*github.PullRequest, error) {
Expand Down
83 changes: 82 additions & 1 deletion pkg/clients/github/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,92 @@ package github
import (
"context"
"fmt"
"strings"

"github.com/google/go-github/v44/github"
"github.com/google/go-github/v60/github"
. "github.com/onsi/ginkgo/v2"
)

func (g *Github) CheckIfForkExist(repositoryName, ownerName string) (bool, error) {
opt := &github.RepositoryListByUserOptions{Type: "owner",}
_, _, err := g.client.Repositories.ListByUser(context.Background(), ownerName, opt)
if err != nil {
GinkgoWriter.Printf("error when listing forks by user %s : %v\n", ownerName, err)
return false, err
}
GinkgoWriter.Printf("Fork for owner %s in repo %s exists\n", ownerName, repositoryName)
return true, nil
}

func (g *Github) CreateFork(repositoryName string) error {
opt := &github.RepositoryCreateForkOptions{Organization: g.organization, Name: repositoryName, DefaultBranchOnly: true}
repo, _, err := g.client.Repositories.CreateFork(context.Background(), g.organization, repositoryName, opt)
if err != nil {
GinkgoWriter.Printf("error when creating fork for repository %s : %v\n", repositoryName, err)
return err
}
GinkgoWriter.Printf("Created a fork for repository %s\n", repo.Name)
return nil
}

func (g *Github) MergeUpstream(owner, repositoryName, baseBranch string) (bool, error) {
input := &github.RepoMergeUpstreamRequest{Branch: &baseBranch}
_, _, err := g.client.Repositories.MergeUpstream(context.Background(), owner, repositoryName, input)
if err != nil {
GinkgoWriter.Printf("error when syncing with upstream %s/%s : %v\n", repositoryName,baseBranch, err)
return false, err
}
GinkgoWriter.Printf("Merged with upstream repository\n")
return true, nil
}

func (g *Github) CheckIfReleaseExist(owner, repositoryName, releaseURL string) bool {
urlParts := strings.Split(releaseURL, "/")
tagName := urlParts[len(urlParts)-1]
_, _, err := g.client.Repositories.GetReleaseByTag(context.Background(), owner, repositoryName, tagName)
if err != nil {
GinkgoWriter.Printf("GetReleaseByTag returned error in repo %s : %v\n", repositoryName, err)
return false
}
GinkgoWriter.Printf("Release tag %s is found in repository %s \n", tagName, repositoryName)
return true
}

func (g *Github) DeleteRelease(owner, repositoryName, releaseURL string) bool {
urlParts := strings.Split(releaseURL, "/")
tagName := urlParts[len(urlParts)-1]
release, _, err := g.client.Repositories.GetReleaseByTag(context.Background(), owner, repositoryName, tagName)
if err != nil {
GinkgoWriter.Printf("GetReleaseByTag returned error in repo %s : %v\n", repositoryName, err)
return false
}

_, err = g.client.Repositories.DeleteRelease(context.Background(), owner, repositoryName, *release.ID)
if err != nil {
GinkgoWriter.Printf("DeleteRelease returned error: %v", err)
}
GinkgoWriter.Printf("Release tag %s is deleted in repository %s \n", tagName, repositoryName)
return true
}

func (g *Github) CheckReleaseExist(owner, repositoryName, tagName string) bool {
opt := &github.ListOptions{Page: 2}
releases, _, err := g.client.Repositories.ListReleases(context.Background(), owner, repositoryName, opt)
if err != nil {
GinkgoWriter.Printf("error when listing Releases %s : %v\n", repositoryName, err)
return false
}
//https://github.com/google/go-github/blob/master/github/repos_releases.go#L21
for _, release := range releases {
releaseTagName := release.TagName
if tagName == *releaseTagName {
return true
}
}
GinkgoWriter.Printf("Release tag %s is not found in repository %s \n", tagName, repositoryName)
return false
}

func (g *Github) CheckIfRepositoryExist(repository string) bool {
_, resp, err := g.client.Repositories.Get(context.Background(), g.organization, repository)
if err != nil {
Expand Down
12 changes: 7 additions & 5 deletions pkg/clients/github/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/google/go-github/v44/github"
"github.com/google/go-github/v60/github"
)

type Webhook struct {
Expand All @@ -20,12 +20,14 @@ func (g *Github) ListRepoWebhooks(repository string) ([]*github.Hook, error) {
}

func (g *Github) CreateWebhook(repository, url string) (int64, error) {
jsonStr := "json"
zeroStr := "0"
newWebhook := &github.Hook{
Events: []string{"push"},
Config: map[string]interface{}{
"content_type": "json",
"insecure_ssl": 0,
"url": url,
Config: &github.HookConfig{
ContentType: &jsonStr,
InsecureSSL: &zeroStr,
URL: &url,
},
}

Expand Down
2 changes: 1 addition & 1 deletion tests/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

pointer "k8s.io/utils/ptr"

"github.com/google/go-github/v44/github"
"github.com/google/go-github/v60/github"
appservice "github.com/redhat-appstudio/application-api/api/v1alpha1"
"github.com/redhat-appstudio/e2e-tests/pkg/clients/has"
"github.com/redhat-appstudio/e2e-tests/pkg/utils/build"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/devfile/library/v2/pkg/util"
"github.com/google/go-github/v44/github"
"github.com/google/go-github/v60/github"
"github.com/redhat-appstudio/e2e-tests/pkg/clients/has"
"github.com/redhat-appstudio/e2e-tests/pkg/constants"
"github.com/redhat-appstudio/e2e-tests/pkg/framework"
Expand Down
1 change: 1 addition & 0 deletions tests/release/pipelines/fbc_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release-

_, err = devFw.AsKubeDeveloper.HasController.CreateApplication(fbcApplicationName, devNamespace)
Expect(err).NotTo(HaveOccurred())
GinkgoWriter.Println("Application is created", fbcApplicationName)

_, err = devFw.AsKubeDeveloper.ReleaseController.CreateReleasePlan(fbcReleasePlanName, devNamespace, fbcApplicationName, managedNamespace, "true")
Expect(err).NotTo(HaveOccurred())
Expand Down
Loading

0 comments on commit 2b19d90

Please sign in to comment.