Skip to content

Commit

Permalink
Merge branch 'main' into docs-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
sami-alajrami committed Jan 8, 2024
2 parents 0347846 + 8fe0b06 commit b32c5c1
Show file tree
Hide file tree
Showing 52 changed files with 698 additions and 702 deletions.
1 change: 0 additions & 1 deletion .dccache

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/auto-approve.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v40
uses: tj-actions/changed-files@v41

- name: Check non critical
id: non-critical
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ on:

env:
IMAGE: ghcr.io/kosli-dev/cli
KOSLI_CLI_VERSION: "2.6.5"
KOSLI_CLI_VERSION: "2.6.18"
# KOSLI_DRY_RUN: "True"
# Ordinarily we declare KOSLI_ORG and KOSLI_FLOW here but
# this interferes with the CLI integration tests
Expand All @@ -48,7 +48,7 @@ jobs:

- uses: actions/setup-go@v3
with:
go-version: '1.21.1'
go-version: '1.21.5'

# Set up QEMU emulator to allow building multi-arch images
- name: Set up QEMU
Expand Down Expand Up @@ -124,7 +124,7 @@ jobs:
# or you can signup for free at https://snyk.io/login
SNYK_TOKEN: ${{ secrets.snyk_token }}
run:
snyk test --json-file-output=snyk-code.json
snyk test --json-file-output=snyk-code.json --prune-repeated-subdependencies


- name: Report Snyk CODE scan results evidence to Kosli
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
slack_channel: ${{ secrets.MERKELY_SLACK_CI_FAILURES_CHANNEL }}
ghcr_user: ${{ secrets.GHCR_USER }}
ghcr_token: ${{ secrets.GHCR_TOKEN }}
kosli_api_token: ${{ secrets.KOSLI_API_TOKEN }}
kosli_api_token: ${{ secrets.KOSLI_API_TOKEN_PROD }}
snyk_token: ${{ secrets.SNYK_TOKEN }}

upload-kosli-reporter-package-staging:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'v*'

env:
GO_VERSION: 1.21.1
GO_VERSION: 1.21.5

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
slack_channel: ${{ secrets.MERKELY_SLACK_CI_FAILURES_CHANNEL }}
ghcr_user: ${{ secrets.GHCR_USER }}
ghcr_token: ${{ secrets.GHCR_TOKEN }}
kosli_api_token: ${{ secrets.KOSLI_API_TOKEN }}
kosli_api_token: ${{ secrets.KOSLI_API_TOKEN_PROD }}
snyk_token: ${{ secrets.SNYK_TOKEN }}

goreleaser:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:

- uses: actions/setup-go@v3
with:
go-version: '1.20.2'
go-version: '1.21.5'

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upload-reporter-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

- uses: actions/setup-go@v3
with:
go-version: '1.20.2'
go-version: '1.21.5'

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1-node16
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax=docker/dockerfile:1

ARG GO_VERSION="1.21.1"
ARG ALPINE_VERSION="3.18"
ARG GO_VERSION="1.21.5"
ARG ALPINE_VERSION="3.19"


### Go Builder ###
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ cli-docs: build
@export DOCS=true && ./kosli docs --dir docs.kosli.com/content/client_reference

legacy-ref-docs:
@./hack/generate-old-versions-docs.sh "v2.*" "v0.*"
@./hack/generate-old-versions-docs.sh "v2.*"

licenses:
@rm -rf licenses || true
Expand Down
8 changes: 6 additions & 2 deletions cmd/kosli/assertPRAzure.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"io"

azUtils "github.com/kosli-dev/cli/internal/azure"
Expand All @@ -12,7 +13,7 @@ type assertPullRequestAzureOptions struct {
commit string
}

const assertPRAzureShortDesc = `Assert a Azure DevOps pull request for a git commit exists. `
const assertPRAzureShortDesc = `Assert an Azure DevOps pull request for a git commit exists. `

const assertPRAzureLongDesc = assertPRAzureShortDesc + `
The command exits with non-zero exit code
Expand Down Expand Up @@ -58,10 +59,13 @@ func newAssertPullRequestAzureCmd(out io.Writer) *cobra.Command {
}

func (o *assertPullRequestAzureOptions) run(args []string) error {
pullRequestsEvidence, err := getPullRequestsEvidence(o.azureConfig, o.commit, true)
pullRequestsEvidence, err := o.azureConfig.PREvidenceForCommit(o.commit)
if err != nil {
return err
}
if len(pullRequestsEvidence) == 0 {
return fmt.Errorf("assert failed: found no pull request(s) in Azure DevOps for commit: %s", o.commit)
}
logger.Info("found [%d] pull request(s) in Azure DevOps for commit: %s", len(pullRequestsEvidence), o.commit)
return nil
}
4 changes: 2 additions & 2 deletions cmd/kosli/assertPRAzure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ func (suite *AssertPRAzureCommandTestSuite) TestAssertPRAzureCmd() {
name: "assert Azure PR evidence fails when commit has no PRs in Azure",
cmd: `assert pullrequest azure --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli
--commit 58d8aad96e0dcd11ada3dc6650d23909eed336ed` + suite.defaultKosliArguments,
golden: "Error: no pull requests found for the given commit: 58d8aad96e0dcd11ada3dc6650d23909eed336ed\n",
golden: "Error: assert failed: found no pull request(s) in Azure DevOps for commit: 58d8aad96e0dcd11ada3dc6650d23909eed336ed\n",
},
{
wantError: true,
name: "assert Azure PR evidence fails when commit does not exist",
cmd: `assert pullrequest azure --azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli
--commit c4fa4c2ce6bef984abc93be9258a85f9137ff1c9` + suite.defaultKosliArguments,
golden: "Error: no pull requests found for the given commit: c4fa4c2ce6bef984abc93be9258a85f9137ff1c9\n",
golden: "Error: assert failed: found no pull request(s) in Azure DevOps for commit: c4fa4c2ce6bef984abc93be9258a85f9137ff1c9\n",
},
}

Expand Down
6 changes: 5 additions & 1 deletion cmd/kosli/assertPRBitbucket.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"io"

bbUtils "github.com/kosli-dev/cli/internal/bitbucket"
Expand Down Expand Up @@ -59,10 +60,13 @@ func newAssertPullRequestBitbucketCmd(out io.Writer) *cobra.Command {
}

func (o *assertPullRequestBitbucketOptions) run(args []string) error {
pullRequestsEvidence, err := getPullRequestsEvidence(o.bbConfig, o.commit, true)
pullRequestsEvidence, err := o.bbConfig.PREvidenceForCommit(o.commit)
if err != nil {
return err
}
if len(pullRequestsEvidence) == 0 {
return fmt.Errorf("assert failed: found no pull request(s) in Bitbucket for commit: %s", o.commit)
}
logger.Info("found [%d] pull request(s) in Bitbucket for commit: %s", len(pullRequestsEvidence), o.commit)
return nil
}
2 changes: 1 addition & 1 deletion cmd/kosli/assertPRBitbucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (suite *AssertPRBitbucketCommandTestSuite) TestAssertPRBitbucketCmd() {
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: no pull requests found for the given commit: cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c\n",
golden: "Error: assert failed: found no pull request(s) in Bitbucket for commit: cb6ec5fcbb25b1ebe4859d35ab7995ab973f894c\n",
},
{
wantError: true,
Expand Down
6 changes: 5 additions & 1 deletion cmd/kosli/assertPRGithub.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"io"

ghUtils "github.com/kosli-dev/cli/internal/github"
Expand Down Expand Up @@ -57,10 +58,13 @@ func newAssertPullRequestGithubCmd(out io.Writer) *cobra.Command {
}

func (o *assertPullRequestGithubOptions) run(args []string) error {
pullRequestsEvidence, err := getPullRequestsEvidence(o.githubConfig, o.commit, true)
pullRequestsEvidence, err := o.githubConfig.PREvidenceForCommit(o.commit)
if err != nil {
return err
}
if len(pullRequestsEvidence) == 0 {
return fmt.Errorf("assert failed: found no pull request(s) in Github for commit: %s", o.commit)
}
logger.Info("found [%d] pull request(s) in Github for commit: %s", len(pullRequestsEvidence), o.commit)
return nil
}
2 changes: 1 addition & 1 deletion cmd/kosli/assertPRGithub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (suite *AssertPRGithubCommandTestSuite) TestAssertPRGithubCmd() {
name: "assert Github PR evidence fails when commit has no PRs in github",
cmd: `assert pullrequest github --github-org kosli-dev --repository cli
--commit 19aab7f063147614451c88969602a10afbabb43d` + suite.defaultKosliArguments,
golden: "Error: no pull requests found for the given commit: 19aab7f063147614451c88969602a10afbabb43d\n",
golden: "Error: assert failed: found no pull request(s) in Github for commit: 19aab7f063147614451c88969602a10afbabb43d\n",
},
{
wantError: true,
Expand Down
8 changes: 6 additions & 2 deletions cmd/kosli/assertPRGitlab.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"io"

gitlabUtils "github.com/kosli-dev/cli/internal/gitlab"
Expand Down Expand Up @@ -57,10 +58,13 @@ func newAssertPullRequestGitlabCmd(out io.Writer) *cobra.Command {
}

func (o *assertPullRequestGitlabOptions) run(args []string) error {
pullRequestsEvidence, err := getPullRequestsEvidence(o.gitlabConfig, o.commit, true)
pullRequestsEvidence, err := o.gitlabConfig.PREvidenceForCommit(o.commit)
if err != nil {
return err
}
logger.Info("found [%d] pull request(s) in Gitlab for commit: %s", len(pullRequestsEvidence), o.commit)
if len(pullRequestsEvidence) == 0 {
return fmt.Errorf("assert failed: found no merge request(s) in Gitlab for commit: %s", o.commit)
}
logger.Info("found [%d] merge request(s) in Gitlab for commit: %s", len(pullRequestsEvidence), o.commit)
return nil
}
8 changes: 4 additions & 4 deletions cmd/kosli/assertPRGitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ func (suite *AssertPRGitlabCommandTestSuite) TestAssertPRGitlabCmd() {
name: "assert Gitlab PR evidence passes when commit has a PR in gitlab",
cmd: `assert mergerequest gitlab --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo
--commit e6510880aecdc05d79104d937e1adb572bd91911` + suite.defaultKosliArguments,
golden: "found [1] pull request(s) in Gitlab for commit: e6510880aecdc05d79104d937e1adb572bd91911\n",
golden: "found [1] merge request(s) in Gitlab for commit: e6510880aecdc05d79104d937e1adb572bd91911\n",
},
{
name: "assert Gitlab PR evidence with aliases 1",
cmd: `assert mr gl --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo
--commit e6510880aecdc05d79104d937e1adb572bd91911` + suite.defaultKosliArguments,
golden: "found [1] pull request(s) in Gitlab for commit: e6510880aecdc05d79104d937e1adb572bd91911\n",
golden: "found [1] merge request(s) in Gitlab for commit: e6510880aecdc05d79104d937e1adb572bd91911\n",
},
{
name: "assert Gitlab PR evidence with aliases 2",
cmd: `assert pullrequest gitlab --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo
--commit e6510880aecdc05d79104d937e1adb572bd91911` + suite.defaultKosliArguments,
golden: "found [1] pull request(s) in Gitlab for commit: e6510880aecdc05d79104d937e1adb572bd91911\n",
golden: "found [1] merge request(s) in Gitlab for commit: e6510880aecdc05d79104d937e1adb572bd91911\n",
},
{
wantError: true,
name: "assert Gitlab PR evidence fails when commit has no PRs in gitlab",
cmd: `assert mergerequest gitlab --gitlab-org ewelinawilkosz --repository merkely-gitlab-demo
--commit 2ec23dda01fc85e3f94a2b5ea8cb8cf7e79c4ed6` + suite.defaultKosliArguments,
golden: "Error: no merge requests found for the given commit: 2ec23dda01fc85e3f94a2b5ea8cb8cf7e79c4ed6\n",
golden: "Error: assert failed: found no merge request(s) in Gitlab for commit: 2ec23dda01fc85e3f94a2b5ea8cb8cf7e79c4ed6\n",
},
{
wantError: true,
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/assertStatus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type AssertStatusCommandTestSuite struct {
suite.Suite
}

func (suite *AssertStatusCommandTestSuite) TestAssertPRGitlabCmd() {
func (suite *AssertStatusCommandTestSuite) TestAssertStatusCmd() {
tests := []cmdTestCase{
{
name: "assert status works",
Expand Down
7 changes: 3 additions & 4 deletions cmd/kosli/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ const attestDesc = `All Kosli attest commands.`

func newAttestCmd(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "attest",
Short: attestDesc,
Long: attestDesc,
Hidden: true,
Use: "attest",
Short: attestDesc,
Long: attestDesc,
}

// Add subcommands
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/attestArtifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type AttestArtifactPayload struct {
BuildUrl string `json:"build_url"`
CommitUrl string `json:"commit_url"`
RepoUrl string `json:"repo_url"`
Name string `json:"step_name"`
Name string `json:"template_reference_name"`
TrailName string `json:"trail_name"`
}

Expand Down
15 changes: 8 additions & 7 deletions cmd/kosli/attestJira.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,6 @@ func (o *attestJiraOptions) run(args []string) error {
logger.Debug("Checked for Jira issue references in Git commit %s on branch %s commit message:\n%s", commitInfo.Sha1, commitInfo.Branch, commitInfo.Message)
logger.Debug("the following Jira references are found in commit message or branch name: %v", issueIDs)

if len(issueIDs) == 0 && o.assert {
return fmt.Errorf("no Jira references are found in commit message or branch name")
}

issueLog := ""
issueFoundCount := 0
for _, issueID := range issueIDs {
Expand All @@ -229,9 +225,6 @@ func (o *attestJiraOptions) run(args []string) error {
}
issueLog += fmt.Sprintf("\n\t%s: %s", result.IssueID, issueExistLog)
}
if issueFoundCount != len(issueIDs) && o.assert {
return fmt.Errorf("missing Jira issues from references found in commit message or branch name%s", issueLog)
}

form, cleanupNeeded, evidencePath, err := prepareAttestationForm(o.payload, o.evidencePaths)
if err != nil {
Expand All @@ -253,5 +246,13 @@ func (o *attestJiraOptions) run(args []string) error {
if err == nil && !global.DryRun {
logger.Info("jira attestation '%s' is reported to trail: %s", o.payload.AttestationName, o.trailName)
}

if len(issueIDs) == 0 && o.assert {
return fmt.Errorf("no Jira references are found in commit message or branch name")
}

if issueFoundCount != len(issueIDs) && o.assert {
return fmt.Errorf("missing Jira issues from references found in commit message or branch name%s", issueLog)
}
return err
}
14 changes: 7 additions & 7 deletions cmd/kosli/attestPRAzure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,43 +67,43 @@ func (suite *AttestAzurePRCommandTestSuite) TestAttestAzurePRCmd() {
name: "attesting against an artifact that does not exist fails",
cmd: fmt.Sprintf(`attest pullrequest azure --fingerprint 1234e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name foo
--azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit HEAD %s`, suite.defaultKosliArguments),
goldenRegex: "no pull requests found for given commit: .*\nError: Artifact with fingerprint '1234e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9' does not exist in flow 'attest-azure-pr' belonging to organization 'docs-cmd-test-user'\n",
goldenRegex: "found 0 pull request\\(s\\) for commit: .*\nError: Artifact with fingerprint '1234e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9' does not exist in flow 'attest-azure-pr' belonging to organization 'docs-cmd-test-user'\n",
},
{
name: "can attest azure pr against an artifact using artifact name and --artifact-type",
cmd: fmt.Sprintf(`attest pullrequest azure testdata/file1 --artifact-type file --name foo
--azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit HEAD %s`, suite.defaultKosliArguments),
goldenRegex: "no pull requests found for given commit: .*\nazure pull request attestation 'foo' is reported to trail: test-123\n",
goldenRegex: "found 0 pull request\\(s\\) for commit: .*\nazure pull request attestation 'foo' is reported to trail: test-123\n",
},
{
name: "can attest azure pr against an artifact using artifact name and --artifact-type when --name does not exist in the trail template",
cmd: fmt.Sprintf(`attest pullrequest azure testdata/file1 --artifact-type file --name bar
--azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit HEAD %s`, suite.defaultKosliArguments),
goldenRegex: "no pull requests found for given commit: .*\nazure pull request attestation 'bar' is reported to trail: test-123\n",
goldenRegex: "found 0 pull request\\(s\\) for commit: .*\nazure pull request attestation 'bar' is reported to trail: test-123\n",
},
{
name: "can attest azure pr against an artifact using --fingerprint",
cmd: fmt.Sprintf(`attest pullrequest azure --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name foo
--azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit HEAD %s`, suite.defaultKosliArguments),
goldenRegex: "no pull requests found for given commit: .*\nazure pull request attestation 'foo' is reported to trail: test-123\n",
goldenRegex: "found 0 pull request\\(s\\) for commit: .*\nazure pull request attestation 'foo' is reported to trail: test-123\n",
},
{
name: "can attest azure pr against a trail",
cmd: fmt.Sprintf(`attest pullrequest azure --name bar
--azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit HEAD %s`, suite.defaultKosliArguments),
goldenRegex: "no pull requests found for given commit: .*\nazure pull request attestation 'bar' is reported to trail: test-123\n",
goldenRegex: "found 0 pull request\\(s\\) for commit: .*\nazure pull request attestation 'bar' is reported to trail: test-123\n",
},
{
name: "can attest azure pr against a trail when name is not found in the trail template",
cmd: fmt.Sprintf(`attest pullrequest azure --name additional
--azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit HEAD %s`, suite.defaultKosliArguments),
goldenRegex: "no pull requests found for given commit: .*\nazure pull request attestation 'additional' is reported to trail: test-123\n",
goldenRegex: "found 0 pull request\\(s\\) for commit: .*\nazure pull request attestation 'additional' is reported to trail: test-123\n",
},
{
name: "can attest azure pr against an artifact it is created using dot syntax in --name",
cmd: fmt.Sprintf(`attest pullrequest azure --name cli.foo
--azure-org-url https://dev.azure.com/kosli --project kosli-azure --repository cli --commit HEAD %s`, suite.defaultKosliArguments),
goldenRegex: "no pull requests found for given commit: .*\nazure pull request attestation 'foo' is reported to trail: test-123\n",
goldenRegex: "found 0 pull request\\(s\\) for commit: .*\nazure pull request attestation 'foo' is reported to trail: test-123\n",
},
}

Expand Down
Loading

0 comments on commit b32c5c1

Please sign in to comment.