From f29f037eeebc57147c85ff9c30a1b0c497da6a43 Mon Sep 17 00:00:00 2001 From: Tore Martin Hagen <93583343+ToreMerkely@users.noreply.github.com> Date: Mon, 21 Oct 2024 13:25:51 +0200 Subject: [PATCH] Changed bitbucket tests to use kosli-dev and not ewelina kosli-dev/server#2461 (#366) * Works with kosli-dev and user tore1 * Moved bitbucket username out as a secret since it has to match the password for that user * Removed ewelinz * Added bitbucket username to github workflows * Added missing bitbucket username --- .github/workflows/main.yml | 1 + .github/workflows/release.yml | 1 + .github/workflows/test.yml | 3 ++ cmd/kosli/assertPRBitbucket_test.go | 14 ++++---- cmd/kosli/attestPRBitbucket_test.go | 20 +++++------ cmd/kosli/cli_utils_test.go | 4 +-- .../reportEvidenceArtifactPRBitbucket_test.go | 33 ++++++++----------- .../reportEvidenceCommitPRBitbucket_test.go | 31 +++++++---------- internal/gitview/gitView_test.go | 8 ++--- secrets/gh-repo-kosli-bitbucket-password.txt | 23 ++++++++++--- secrets/gh-repo-kosli-bitbucket-username.txt | 14 ++++++++ secrets/gh-repo-kosli-gitlab-token.txt | 2 -- 12 files changed, 85 insertions(+), 69 deletions(-) create mode 100644 secrets/gh-repo-kosli-bitbucket-username.txt diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4783e92be..671c313b2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -68,6 +68,7 @@ jobs: azure_access_token: ${{ secrets.KOSLI_AZURE_TOKEN }} azure_client_id: ${{ secrets.AZURE_CLIENT_ID }} azure_client_secret: ${{ secrets.AZURE_CLIENT_SECRET }} + bitbucket_username: ${{ secrets.KOSLI_BITBUCKET_USERNAME }} bitbucket_password: ${{ secrets.KOSLI_BITBUCKET_PASSWORD }} jira_api_token: ${{ secrets.KOSLI_JIRA_API_TOKEN }} slack_webhook: ${{ secrets.MERKELY_SLACK_CI_FAILURES_WEBHOOK }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 17d49bdd1..026d76479 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -77,6 +77,7 @@ jobs: azure_access_token: ${{ secrets.KOSLI_AZURE_TOKEN }} azure_client_id: ${{ secrets.AZURE_CLIENT_ID }} azure_client_secret: ${{ secrets.AZURE_CLIENT_SECRET }} + bitbucket_username: ${{ secrets.KOSLI_BITBUCKET_USERNAME }} bitbucket_password: ${{ secrets.KOSLI_BITBUCKET_PASSWORD }} slack_webhook: ${{ secrets.MERKELY_SLACK_CI_FAILURES_WEBHOOK }} slack_channel: ci-failures diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b6df77685..a87e90f84 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,6 +33,8 @@ on: required: true azure_client_secret: required: true + bitbucket_username: + required: true bitbucket_password: required: true jira_api_token: @@ -131,6 +133,7 @@ jobs: KOSLI_GITHUB_TOKEN: ${{ secrets.github_access_token }} KOSLI_GITLAB_TOKEN: ${{ secrets.gitlab_access_token }} KOSLI_AZURE_TOKEN: ${{ secrets.azure_access_token }} + KOSLI_BITBUCKET_USERNAME: ${{ secrets.bitbucket_username }} KOSLI_BITBUCKET_PASSWORD: ${{ secrets.bitbucket_password }} KOSLI_JIRA_API_TOKEN: ${{ secrets.jira_api_token }} INTEGRATION_TEST_AZURE_CLIENT_SECRET: ${{ secrets.azure_client_secret }} diff --git a/cmd/kosli/assertPRBitbucket_test.go b/cmd/kosli/assertPRBitbucket_test.go index 15541b0ae..22a877ec4 100644 --- a/cmd/kosli/assertPRBitbucket_test.go +++ b/cmd/kosli/assertPRBitbucket_test.go @@ -31,21 +31,21 @@ func (suite *AssertPRBitbucketCommandTestSuite) TestAssertPRBitbucketCmd() { tests := []cmdTestCase{ { name: "assert Bitbucket PR evidence passes when commit has a PR in bitbucket", - cmd: `assert pullrequest bitbucket --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test - --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, - golden: "found [1] pull request(s) in Bitbucket for commit: 2492011ef04a9da09d35be706cf6a4c5bc6f1e69\n", + cmd: `assert pullrequest bitbucket --bitbucket-workspace kosli-dev --repository cli-test + --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments, + golden: "found [1] pull request(s) in Bitbucket for commit: fd54040fc90e7e83f7b152619bfa18917b72c34f\n", }, { wantError: true, name: "assert Bitbucket PR evidence fails when commit has no PRs in bitbucket", - cmd: `assert pullrequest bitbucket --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test - --commit cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c` + suite.defaultKosliArguments, - golden: "Error: assert failed: found no pull request(s) in Bitbucket for commit: cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c\n", + cmd: `assert pullrequest bitbucket --bitbucket-workspace kosli-dev --repository cli-test + --commit 3dce097040987c4693d2e4be817474d9d0063c93` + suite.defaultKosliArguments, + golden: "Error: assert failed: found no pull request(s) in Bitbucket for commit: 3dce097040987c4693d2e4be817474d9d0063c93\n", }, { wantError: true, name: "assert Bitbucket PR evidence fails when commit does not exist", - cmd: `assert pullrequest bitbucket --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test + cmd: `assert pullrequest bitbucket --bitbucket-workspace kosli-dev --repository cli-test --commit 19aab7f063147614451c88969602a10afba123ab` + suite.defaultKosliArguments, golden: "Error: map[error:map[message:Resource not found] type:error]\n", }, diff --git a/cmd/kosli/attestPRBitbucket_test.go b/cmd/kosli/attestPRBitbucket_test.go index 1b8e92460..c2ea10612 100644 --- a/cmd/kosli/attestPRBitbucket_test.go +++ b/cmd/kosli/attestPRBitbucket_test.go @@ -37,10 +37,10 @@ func (suite *AttestBitbucketPRCommandTestSuite) SetupTest() { var err error suite.tmpDir, err = os.MkdirTemp("", "testDir") require.NoError(suite.T(), err) - _, err = testHelpers.CloneGitRepo("https://bitbucket.org/ewelinawilkosz/cli-test.git", suite.tmpDir) + _, err = testHelpers.CloneGitRepo("https://bitbucket.org/kosli-dev/cli-test.git", suite.tmpDir) require.NoError(suite.T(), err) - suite.defaultKosliArguments = fmt.Sprintf(" --flow %s --trail %s --repo-root %s --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69 --host %s --org %s --api-token %s", suite.flowName, suite.trailName, suite.tmpDir, global.Host, global.Org, global.ApiToken) + suite.defaultKosliArguments = fmt.Sprintf(" --flow %s --trail %s --repo-root %s --commit fd54040fc90e7e83f7b152619bfa18917b72c34f --host %s --org %s --api-token %s", suite.flowName, suite.trailName, suite.tmpDir, global.Host, global.Org, global.ApiToken) CreateFlowWithTemplate(suite.flowName, "testdata/valid_template.yml", suite.T()) BeginTrail(suite.trailName, suite.flowName, "", suite.T()) CreateArtifactOnTrail(suite.flowName, suite.trailName, "cli", suite.artifactFingerprint, "file1", suite.T()) @@ -62,7 +62,7 @@ func (suite *AttestBitbucketPRCommandTestSuite) TestAttestBitbucketPRCmd() { wantError: true, name: "fails when missing a required flags", cmd: fmt.Sprintf("attest pullrequest bitbucket foo -t file %s", suite.defaultKosliArguments), - golden: "Error: required flag(s) \"bitbucket-username\", \"bitbucket-workspace\", \"name\", \"repository\" not set\n", + golden: "Error: required flag(s) \"bitbucket-workspace\", \"name\", \"repository\" not set\n", }, { wantError: true, @@ -80,43 +80,43 @@ func (suite *AttestBitbucketPRCommandTestSuite) TestAttestBitbucketPRCmd() { wantError: true, name: "attesting against an artifact that does not exist fails", cmd: fmt.Sprintf(`attest pullrequest bitbucket --fingerprint 1234e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name foo - --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test %s`, suite.defaultKosliArguments), + --bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments), goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nError: Artifact with fingerprint 1234e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 does not exist in trail \"test-123\" of flow \"attest-bitbucket-pr\" belonging to organization \"docs-cmd-test-user\"\n", }, { name: "can attest bitbucket pr against an artifact using artifact name and --artifact-type", cmd: fmt.Sprintf(`attest pullrequest bitbucket testdata/file1 --artifact-type file --name foo - --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test %s`, suite.defaultKosliArguments), + --bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments), goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nbitbucket pull request attestation 'foo' is reported to trail: test-123\n", }, { name: "can attest bitbucket pr against an artifact using artifact name and --artifact-type when --name does not exist in the trail template", cmd: fmt.Sprintf(`attest pullrequest bitbucket testdata/file1 --artifact-type file --name bar - --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test %s`, suite.defaultKosliArguments), + --bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments), goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nbitbucket pull request attestation 'bar' is reported to trail: test-123\n", }, { name: "can attest bitbucket pr against an artifact using --fingerprint", cmd: fmt.Sprintf(`attest pullrequest bitbucket --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name foo - --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test %s`, suite.defaultKosliArguments), + --bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments), goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nbitbucket pull request attestation 'foo' is reported to trail: test-123\n", }, { name: "can attest bitbucket pr against a trail", cmd: fmt.Sprintf(`attest pullrequest bitbucket --name bar - --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test %s`, suite.defaultKosliArguments), + --bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments), goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nbitbucket pull request attestation 'bar' is reported to trail: test-123\n", }, { name: "can attest bitbucket pr against a trail when name is not found in the trail template", cmd: fmt.Sprintf(`attest pullrequest bitbucket --name additional - --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test %s`, suite.defaultKosliArguments), + --bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments), goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nbitbucket pull request attestation 'additional' is reported to trail: test-123\n", }, { name: "can attest bitbucket pr against an artifact it is created using dot syntax in --name", cmd: fmt.Sprintf(`attest pullrequest bitbucket --name cli.foo - --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test %s`, suite.defaultKosliArguments), + --bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments), goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nbitbucket pull request attestation 'foo' is reported to trail: test-123\n", }, } diff --git a/cmd/kosli/cli_utils_test.go b/cmd/kosli/cli_utils_test.go index 1873d431f..ad1d6e36d 100644 --- a/cmd/kosli/cli_utils_test.go +++ b/cmd/kosli/cli_utils_test.go @@ -172,9 +172,9 @@ func (suite *CliUtilsTestSuite) TestDefaultValue() { ci: circleci, flag: "commit-url", unsetTestsEnvVar: true, - envVars: map[string]string{"CIRCLE_REPOSITORY_URL": "git@bitbucket.org:ewelinawilkosz/cli-test.git", "CIRCLE_SHA1": "2492011ef04a9da09d35be706cf6a4c5bc6f1e69"}, + envVars: map[string]string{"CIRCLE_REPOSITORY_URL": "git@bitbucket.org:kosli-dev/cli-test.git", "CIRCLE_SHA1": "fd54040fc90e7e83f7b152619bfa18917b72c34f"}, }, - want: "https://bitbucket.org/ewelinawilkosz/cli-test/commits/2492011ef04a9da09d35be706cf6a4c5bc6f1e69", + want: "https://bitbucket.org/kosli-dev/cli-test/commits/fd54040fc90e7e83f7b152619bfa18917b72c34f", }, { name: "Lookup commit-url for CircleCI with a repo that is not from bitbucket returns correct url (with '/commit/')", diff --git a/cmd/kosli/reportEvidenceArtifactPRBitbucket_test.go b/cmd/kosli/reportEvidenceArtifactPRBitbucket_test.go index c51dc8eec..a5d829eba 100644 --- a/cmd/kosli/reportEvidenceArtifactPRBitbucket_test.go +++ b/cmd/kosli/reportEvidenceArtifactPRBitbucket_test.go @@ -39,14 +39,14 @@ func (suite *ArtifactEvidencePRBitbucketCommandTestSuite) TestArtifactEvidencePR { name: "report Bitbucket PR evidence works with new flags (fingerprint, name ...)", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments, goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nbitbucket pull request evidence is reported to artifact: .*", }, { wantError: true, name: "report Bitbucket PR evidence fails when --org is missing", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69 --api-token foo --host bar`, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f --api-token foo --host bar`, goldenRegex: "Error: --org is not set\n" + "Usage: kosli report evidence artifact pullrequest bitbucket \\[IMAGE-NAME | FILE-PATH | DIR-PATH\\] \\[flags\\]\n", }, @@ -54,35 +54,28 @@ func (suite *ArtifactEvidencePRBitbucketCommandTestSuite) TestArtifactEvidencePR wantError: true, name: "report Bitbucket PR evidence fails when --name is missing", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --flow ` + suite.flowName + ` - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"name\" not set\n", }, - { - wantError: true, - name: "report Bitbucket PR evidence fails when --bitbucket-username is missing", - cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` - --build-url http://www.example.com --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, - goldenRegex: "Error: required flag\\(s\\) \"bitbucket-username\" not set\n", - }, { wantError: true, name: "report Bitbucket PR evidence fails when --repository is missing", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"repository\" not set\n", }, { wantError: true, name: "report Bitbucket PR evidence fails when --commit is missing", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"commit\" not set\n", }, { wantError: true, name: "report Bitbucket PR evidence fails when neither --fingerprint nor --artifact-type are set", cmd: `report evidence artifact pullrequest bitbucket artifactNameArg --name bb-pr --flow ` + suite.flowName + ` - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments, goldenRegex: "Error: either --artifact-type or --fingerprint must be specified\n" + "Usage: kosli report evidence artifact pullrequest bitbucket \\[IMAGE-NAME | FILE-PATH | DIR-PATH\\] \\[flags\\]\n", }, @@ -90,14 +83,14 @@ func (suite *ArtifactEvidencePRBitbucketCommandTestSuite) TestArtifactEvidencePR wantError: true, name: "report Bitbucket PR evidence fails when commit does not exist", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 73d7fee2f31ade8e1a9c456c324255212c3123ab` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit 73d7fee2f31ade8e1a9c456c324255212c3123ab` + suite.defaultKosliArguments, goldenRegex: "Error: map\\[error:map\\[message:Resource not found\\] type:error\\]\n", }, { name: "report Bitbucket PR evidence works when --assert is used and commit has a PR", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` --assert - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments, goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nbitbucket pull request evidence is reported to artifact: .*\n", }, { @@ -105,27 +98,27 @@ func (suite *ArtifactEvidencePRBitbucketCommandTestSuite) TestArtifactEvidencePR name: "report Bitbucket PR evidence fails when --assert is used and commit has no PRs", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` --assert - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit 3dce097040987c4693d2e4be817474d9d0063c93` + suite.defaultKosliArguments, goldenRegex: "found 0 pull request\\(s\\) for commit: .*\nbitbucket pull request evidence is reported to artifact: .*\nError: assert failed: no pull request found for the given commit: .*\n", }, { name: "report Bitbucket PR evidence does not fail when commit has no PRs", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit 3dce097040987c4693d2e4be817474d9d0063c93` + suite.defaultKosliArguments, goldenRegex: "found 0 pull request\\(s\\) for commit: .*\nbitbucket pull request evidence is reported to artifact: .*\n", }, { wantError: true, name: "report Bitbucket PR evidence fails when the artifact does not exist in the server", cmd: `report evidence artifact pullrequest bitbucket testdata/file1 --artifact-type file --name bb-pr --flow ` + suite.flowName + ` - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments, goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nError: Artifact with fingerprint '7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9' does not exist in flow 'bitbucket-pr' belonging to organization 'docs-cmd-test-user'. \n", }, { wantError: true, name: "report Bitbucket PR evidence fails when --artifact-type is unsupported", cmd: `report evidence artifact pullrequest bitbucket testdata/file1 --artifact-type unsupported --name bb-pr --flow ` + suite.flowName + ` - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments, goldenRegex: "Error: unsupported is not a supported artifact type\n", }, { @@ -133,7 +126,7 @@ func (suite *ArtifactEvidencePRBitbucketCommandTestSuite) TestArtifactEvidencePR name: "report Bitbucket PR evidence fails when --user-data is not found", cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + ` --user-data non-existing.json - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments, goldenRegex: "Error: open non-existing.json: no such file or directory\n", }, } diff --git a/cmd/kosli/reportEvidenceCommitPRBitbucket_test.go b/cmd/kosli/reportEvidenceCommitPRBitbucket_test.go index c089b3684..64f5c028b 100644 --- a/cmd/kosli/reportEvidenceCommitPRBitbucket_test.go +++ b/cmd/kosli/reportEvidenceCommitPRBitbucket_test.go @@ -36,14 +36,14 @@ func (suite *CommitEvidencePRBitbucketCommandTestSuite) TestCommitEvidencePRBitb { name: "report Bitbucket PR evidence works", cmd: `report evidence commit pullrequest bitbucket --name bb-pr --flows ` + suite.flowNames + ` - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, - goldenRegex: "found 1 pull request\\(s\\) for commit: 2492011ef04a9da09d35be706cf6a4c5bc6f1e69\nbitbucket pull request evidence is reported to commit: 2492011ef04a9da09d35be706cf6a4c5bc6f1e69\n", + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments, + goldenRegex: "found 1 pull request\\(s\\) for commit: fd54040fc90e7e83f7b152619bfa18917b72c34f\nbitbucket pull request evidence is reported to commit: fd54040fc90e7e83f7b152619bfa18917b72c34f\n", }, { wantError: true, name: "report Bitbucket PR evidence fails when --org is missing", cmd: `report evidence commit pullrequest bitbucket --name bb-pr --flows ` + suite.flowNames + ` - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69 --api-token foo --host bar`, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f --api-token foo --host bar`, goldenRegex: "Error: --org is not set\n" + "Usage: kosli report evidence commit pullrequest bitbucket \\[flags\\]\n", }, @@ -51,35 +51,28 @@ func (suite *CommitEvidencePRBitbucketCommandTestSuite) TestCommitEvidencePRBitb wantError: true, name: "report Bitbucket PR evidence fails when --name is missing", cmd: `report evidence commit pullrequest bitbucket --flows ` + suite.flowNames + ` - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"name\" not set\n", }, - { - wantError: true, - name: "report Bitbucket PR evidence fails when --bitbucket-username is missing", - cmd: `report evidence commit pullrequest bitbucket --name bb-pr --flows ` + suite.flowNames + ` - --build-url http://www.example.com --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, - goldenRegex: "Error: required flag\\(s\\) \"bitbucket-username\" not set\n", - }, { wantError: true, name: "report Bitbucket PR evidence fails when --repository is missing", cmd: `report evidence commit pullrequest bitbucket --name bb-pr --flows ` + suite.flowNames + ` - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"repository\" not set\n", }, { wantError: true, name: "report Bitbucket PR evidence fails when --commit is missing", cmd: `report evidence commit pullrequest bitbucket --name bb-pr --flows ` + suite.flowNames + ` - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test` + suite.defaultKosliArguments, goldenRegex: "Error: required flag\\(s\\) \"commit\" not set\n", }, { wantError: true, name: "report Bitbucket PR evidence fails when commit does not exist", cmd: `report evidence commit pullrequest bitbucket --name bb-pr --flows ` + suite.flowNames + ` - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 73d7fee2f31ade8e1a9c456c324255212c3123ab` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit 73d7fee2f31ade8e1a9c456c324255212c3123ab` + suite.defaultKosliArguments, goldenRegex: "Error: map\\[error:map\\[message:Resource not found\\] type:error\\]\n", }, { @@ -87,22 +80,22 @@ func (suite *CommitEvidencePRBitbucketCommandTestSuite) TestCommitEvidencePRBitb name: "report Bitbucket PR evidence fails when --assert is used and commit has no PRs", cmd: `report evidence commit pullrequest bitbucket --name bb-pr --flows ` + suite.flowNames + ` --assert - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit 3dce097040987c4693d2e4be817474d9d0063c93` + suite.defaultKosliArguments, goldenRegex: "found 0 pull request\\(s\\) for commit: .*\nbitbucket pull request evidence is reported to commit: .*\nError: assert failed: no pull request found for the given commit: .*\n", }, { name: "report Bitbucket PR evidence does not fail when commit has no PRs", cmd: `report evidence commit pullrequest bitbucket --name bb-pr --flows ` + suite.flowNames + ` - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c` + suite.defaultKosliArguments, - goldenRegex: "found 0 pull request\\(s\\) for commit: cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c\n" + - "bitbucket pull request evidence is reported to commit: cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c\n", + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit 3dce097040987c4693d2e4be817474d9d0063c93` + suite.defaultKosliArguments, + goldenRegex: "found 0 pull request\\(s\\) for commit: 3dce097040987c4693d2e4be817474d9d0063c93\n" + + "bitbucket pull request evidence is reported to commit: 3dce097040987c4693d2e4be817474d9d0063c93\n", }, { wantError: true, name: "report Bitbucket PR evidence fails when --user-data is not found", cmd: `report evidence commit pullrequest bitbucket --name bb-pr --flows ` + suite.flowNames + ` --user-data non-existing.json - --build-url http://www.example.com --bitbucket-username ewelinawilkosz --bitbucket-workspace ewelinawilkosz --repository cli-test --commit 2492011ef04a9da09d35be706cf6a4c5bc6f1e69` + suite.defaultKosliArguments, + --build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments, goldenRegex: "Error: open non-existing.json: no such file or directory\n", }, } diff --git a/internal/gitview/gitView_test.go b/internal/gitview/gitView_test.go index 841bb4173..5cc7aa4f3 100644 --- a/internal/gitview/gitView_test.go +++ b/internal/gitview/gitView_test.go @@ -294,15 +294,15 @@ func (suite *GitViewTestSuite) TestGetCommitURL() { }, { name: "gitlab", - repoURL: "https://gitlab.com/ewelinawilkosz/merkely-gitlab-demo", + repoURL: "https://gitlab.com/kosli/merkely-gitlab-demo", commitHash: "089615f84caedd6280689da694e71052cbdfb84d", - want: "https://gitlab.com/ewelinawilkosz/merkely-gitlab-demo/-/commit/089615f84caedd6280689da694e71052cbdfb84d", + want: "https://gitlab.com/kosli/merkely-gitlab-demo/-/commit/089615f84caedd6280689da694e71052cbdfb84d", }, { name: "bitbucket", - repoURL: "https://bitbucket.org/ewelinawilkosz/cli-test", + repoURL: "https://bitbucket.org/kosli-dev/cli-test", commitHash: "089615f84caedd6280689da694e71052cbdfb84d", - want: "https://bitbucket.org/ewelinawilkosz/cli-test/commits/089615f84caedd6280689da694e71052cbdfb84d", + want: "https://bitbucket.org/kosli-dev/cli-test/commits/089615f84caedd6280689da694e71052cbdfb84d", }, { name: "azure", diff --git a/secrets/gh-repo-kosli-bitbucket-password.txt b/secrets/gh-repo-kosli-bitbucket-password.txt index 3004a1f1b..5dad67425 100644 --- a/secrets/gh-repo-kosli-bitbucket-password.txt +++ b/secrets/gh-repo-kosli-bitbucket-password.txt @@ -1,11 +1,24 @@ secret-name: KOSLI_BITBUCKET_PASSWORD -secret-expire: 2025-01-01 -secret-updated: -secret-updated-by: +secret-expire: 2025-10-21 +secret-updated: 2024-10-21 +secret-updated-by: tore secret-type: gh-repo is-secret: true secret-usage: Used to test Bitbucket integration. -The tests are currently setup to work for the -bitbucket-org ewelinawilkosz +The KOSLI_BITBUCKET_PASSWORD must match the user stored in +KOSLI_BITBUCKET_USERNAME update-instructions: +Go to https://bitbucket.org/account/settings/app-passwords/ +Press +Label: cli-testing +Permissons: + Repositories: Read + Pull requests: Read +Press + +You should test that your username and password works by running + +curl -u YOUR_USERNAME:YOUR_PASSWORD https://api.bitbucket.org/2.0/repositories/kosli-dev/cli-test/commit/fd54040fc90e7e83f7b152619bfa18917b72c34f/pullrequests; echo +The result should look like this: +{"type": "paginated_pullrequests", "values": [{"type": "pullrequest", "id": 1, "title": "test-file.txt edited online with Bitbucket", "links": {"self": {"href": "https://api.bitbucket.org/2.0/repositories/kosli-dev/cli-test/pullrequests/1"}, "html": {"href": "https://bitbucket.org/kosli-dev/cli-test/pull-requests/1"}}}], "page": 1, "pagelen": 50} diff --git a/secrets/gh-repo-kosli-bitbucket-username.txt b/secrets/gh-repo-kosli-bitbucket-username.txt new file mode 100644 index 000000000..75a632b47 --- /dev/null +++ b/secrets/gh-repo-kosli-bitbucket-username.txt @@ -0,0 +1,14 @@ +secret-name: KOSLI_BITBUCKET_USERNAME +secret-expire: never +secret-updated: 2024-10-21 +secret-updated-by: tore +secret-type: gh-repo +is-secret: true +secret-usage: Used to test Bitbucket integration. +The PASSWORD must match the user stored in +KOSLI_BITBUCKET_PASSWORD + +update-instructions: +Go to https://bitbucket.org/account/settings/ +Under it should say +Username: diff --git a/secrets/gh-repo-kosli-gitlab-token.txt b/secrets/gh-repo-kosli-gitlab-token.txt index 6629f50b7..a4a23064c 100644 --- a/secrets/gh-repo-kosli-gitlab-token.txt +++ b/secrets/gh-repo-kosli-gitlab-token.txt @@ -5,8 +5,6 @@ secret-updated-by: secret-type: gh-repo is-secret: true secret-usage: Used to test Gitlab integration. -The tests are currently setup to work for the -gitlab-org ewelinawilkosz update-instructions: Go to https://gitlab.com/