Skip to content

Srvkp 6636 test #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions .github/workflows/kind-e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:
description: "Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)"
required: false
default: false
push:
branches:
- SRVKP-6636-test
pull_request_target:
types: [opened, synchronize, reopened]
paths:
Expand Down Expand Up @@ -47,13 +50,6 @@ jobs:
run: |
nohup gosmee client --saveDir /tmp/gosmee-replay ${{ secrets.PYSMEE_URL }} "http://${CONTROLLER_DOMAIN_URL}" &

- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
with:
detached: true
limit-access-to-actor: true

- name: Start installing cluster
run: |
export PAC_DIR=${PWD}
Expand Down Expand Up @@ -118,4 +114,7 @@ jobs:
status: ${{ job.status }}
notify_when: "failure"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
4 changes: 2 additions & 2 deletions hack/gh-workflow-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ run_e2e_tests() {
export TEST_GITHUB_SECOND_TOKEN="${test_github_second_token}"

export TEST_GITLAB_API_URL="https://gitlab.com"
export TEST_GITLAB_PROJECT_ID="34405323"
export TEST_GITLAB_PROJECT_ID="62404501"
export TEST_GITLAB_TOKEN=${gitlab_token}
# https://gitlab.com/gitlab-com/alliances/ibm-red-hat/sandbox/openshift-pipelines/pac-e2e-tests
make test-e2e
go test -tags=e2e ./test/ -v -run ^TestGitlabDeleteTagEvent$
}

collect_logs() {
Expand Down
10 changes: 10 additions & 0 deletions pkg/provider/gitlab/parse_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ func (v *Provider) ParsePayload(_ context.Context, _ *params.Run, request *http.
processedEvent.TargetProjectID = gitEvent.Project.ID
processedEvent.EventType = strings.ReplaceAll(event, " Hook", "")
case *gitlab.TagEvent:
// GitLab sends same event for both Tag creation and deletion i.e. "Tag Push Hook".
// if gitEvent.After is containing all zeros and gitEvent.CheckoutSHA is empty
// it is Delete "Tag Push Hook".
if isZeroSHA(gitEvent.After) && gitEvent.CheckoutSHA == "" {
return nil, fmt.Errorf("event Delete %s is not supported", event)
}
lastCommitIdx := len(gitEvent.Commits) - 1
processedEvent.Sender = gitEvent.UserUsername
processedEvent.DefaultBranch = gitEvent.Project.DefaultBranch
Expand Down Expand Up @@ -136,3 +142,7 @@ func (v *Provider) ParsePayload(_ context.Context, _ *params.Run, request *http.
v.repoURL = processedEvent.URL
return processedEvent, nil
}

func isZeroSHA(sha string) bool {
return sha == "0000000000000000000000000000000000000000"
}
1 change: 1 addition & 0 deletions test/bitbucket_cloud_pullrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
)

func TestBitbucketCloudPullRequest(t *testing.T) {
t.Skip("Skipping for my test")
targetNS := names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("pac-e2e-ns")
ctx := context.Background()

Expand Down
55 changes: 55 additions & 0 deletions test/gitlab_delete_tag_event_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//go:build e2e
// +build e2e

package test

import (
"context"
"net/http"
"regexp"
"testing"

"github.com/openshift-pipelines/pipelines-as-code/test/pkg/cctx"
tgitlab "github.com/openshift-pipelines/pipelines-as-code/test/pkg/gitlab"
twait "github.com/openshift-pipelines/pipelines-as-code/test/pkg/wait"
"github.com/tektoncd/pipeline/pkg/names"
"github.com/xanzy/go-gitlab"
"gotest.tools/v3/assert"
)

func TestGitlabDeleteTagEvent(t *testing.T) {
targetNS := names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("pac-e2e-ns")
ctx := context.Background()
runcnx, opts, glprovider, err := tgitlab.Setup(ctx)
assert.NilError(t, err)
ctx, err = cctx.GetControllerCtxInfo(ctx, runcnx)
assert.NilError(t, err)
runcnx.Clients.Log.Info("Testing with Gitlab")

projectinfo, resp, err := glprovider.Client.Projects.GetProject(opts.ProjectID, nil)
assert.NilError(t, err)
if resp != nil && resp.StatusCode == http.StatusNotFound {
t.Errorf("Repository %s not found in %s", opts.Organization, opts.Repo)
}
defer tgitlab.TearDown(ctx, t, runcnx, glprovider, -1, "", targetNS, opts.ProjectID)

err = tgitlab.CreateCRD(ctx, projectinfo, runcnx, targetNS, nil)
assert.NilError(t, err)

tagName := "v1.0-test"
err = tgitlab.CreateTag(glprovider.Client, projectinfo.ID, tagName)
assert.NilError(t, err)
runcnx.Clients.Log.Infof("Created Tag %s in %s repository", tagName, projectinfo.Name)

err = tgitlab.DeleteTag(glprovider.Client, projectinfo.ID, tagName)
assert.NilError(t, err)
runcnx.Clients.Log.Infof("Deleted Tag %s in %s repository", tagName, projectinfo.Name)

reg := regexp.MustCompile("event Delete Tag Push Hook is not supported*")
err = twait.RegexpMatchingInControllerLog(ctx, runcnx, *reg, 10, "controller", gitlab.Ptr(int64(20)))
assert.NilError(t, err)
}

// Local Variables:
// compile-command: "go test -tags=e2e -v -run TestGitlabDeleteTagEvent$ ."
// End:
11 changes: 7 additions & 4 deletions test/pkg/gitlab/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,19 @@ func TearDown(ctx context.Context, t *testing.T, runcnx *params.Run, glprovider
runcnx.Clients.Log.Infof("Not cleaning up and closing PR since TEST_NOCLEANUP is set")
return
}
runcnx.Clients.Log.Infof("Closing PR %d", mrNumber)

if mrNumber != -1 {
runcnx.Clients.Log.Infof("Closing PR %d", mrNumber)
_, _, err := glprovider.Client.MergeRequests.UpdateMergeRequest(projectid, mrNumber,
&gitlab2.UpdateMergeRequestOptions{StateEvent: gitlab2.Ptr("close")})
if err != nil {
t.Fatal(err)
}
}
repository.NSTearDown(ctx, t, runcnx, targetNS)
runcnx.Clients.Log.Infof("Deleting Ref %s", ref)
_, err := glprovider.Client.Branches.DeleteBranch(projectid, ref)
assert.NilError(t, err)
if ref != "" {
runcnx.Clients.Log.Infof("Deleting Ref %s", ref)
_, err := glprovider.Client.Branches.DeleteBranch(projectid, ref)
assert.NilError(t, err)
}
}
32 changes: 32 additions & 0 deletions test/pkg/gitlab/test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package gitlab

import (
"fmt"
"net/http"

ghlib "github.com/xanzy/go-gitlab"
)

Expand All @@ -15,3 +18,32 @@ func CreateMR(client *ghlib.Client, pid int, sourceBranch, targetBranch, title s
}
return mr.IID, nil
}

func CreateTag(client *ghlib.Client, pid int, tagName string) error {
_, resp, err := client.Tags.CreateTag(pid, &ghlib.CreateTagOptions{
TagName: ghlib.Ptr(tagName),
Ref: ghlib.Ptr("main"),
})
if err != nil {
return err
}

if resp.StatusCode != http.StatusCreated {
return fmt.Errorf("failed to create tag : %d", resp.StatusCode)
}

return nil
}

func DeleteTag(client *ghlib.Client, pid int, tagName string) error {
resp, err := client.Tags.DeleteTag(pid, tagName)
if err != nil {
return err
}

if resp.StatusCode != http.StatusNoContent {
return fmt.Errorf("failed to delete tag : %d", resp.StatusCode)
}

return nil
}
Loading