Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f0f9530
Implement optional flag and loop to poll SonarQube and wait for scan …
FayeSGW Jun 10, 2025
308ada3
Add missing argument to NewSonarConfig
FayeSGW Jun 10, 2025
f29001b
Add 'IN_PROGRESS' status to sleep loop
FayeSGW Jun 11, 2025
385c266
Add more thorough error message to attest sonar command
FayeSGW Jun 11, 2025
d4dfd60
Change --allow-wait flag to take number of seconds to wait as parameter
FayeSGW Jun 13, 2025
063f211
Clean up leftover comment
FayeSGW Jun 13, 2025
ea13f4e
Add more details on new flag to attest sonar description
FayeSGW Jun 16, 2025
092feaf
Change --allow-wait flag to --max-retries
FayeSGW Jun 24, 2025
3ca6048
Change --allow-wait flag in example commands for docs
FayeSGW Jun 24, 2025
c502b01
Fix typo
FayeSGW Jun 24, 2025
4c2d22a
Start implementing GraphQL for Github PRs
FayeSGW Jul 1, 2025
5510cbd
Update variable names for PR structs to match API
FayeSGW Jul 2, 2025
c4e0cad
Update PR struct to work with both old and new versions of PR attesta…
FayeSGW Jul 3, 2025
837984b
Fix payload for non-github PR attestations and tidy up comments
FayeSGW Jul 3, 2025
d8dade9
Merge branch 'main' into pr-attestation-enhaancement
FayeSGW Jul 3, 2025
72fcbaa
Fix payload issues for non-Github-attest commands
FayeSGW Jul 4, 2025
8a7d3fb
Update report evidence command payloads
FayeSGW Jul 4, 2025
1415dd7
Get git provider for reporting commit evidence properly
FayeSGW Jul 4, 2025
d7cf3f8
add author_username to github pr attestation commits
sami-alajrami Jul 4, 2025
856bf36
Merge branch 'main' into pr-attestation-enhaancement
sami-alajrami Jul 4, 2025
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
2 changes: 1 addition & 1 deletion cmd/kosli/assertPRAzure.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func newAssertPullRequestAzureCmd(out io.Writer) *cobra.Command {
}

func (o *assertPullRequestAzureOptions) run(args []string) error {
pullRequestsEvidence, err := o.azureConfig.PREvidenceForCommit(o.commit)
pullRequestsEvidence, err := o.azureConfig.PREvidenceForCommitV2(o.commit)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/assertPRBitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func newAssertPullRequestBitbucketCmd(out io.Writer) *cobra.Command {
}

func (o *assertPullRequestBitbucketOptions) run(args []string) error {
pullRequestsEvidence, err := o.bbConfig.PREvidenceForCommit(o.commit)
pullRequestsEvidence, err := o.bbConfig.PREvidenceForCommitV2(o.commit)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/assertPRGithub.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func newAssertPullRequestGithubCmd(out io.Writer) *cobra.Command {
}

func (o *assertPullRequestGithubOptions) run(args []string) error {
pullRequestsEvidence, err := o.githubConfig.PREvidenceForCommit(o.commit)
pullRequestsEvidence, err := o.githubConfig.PREvidenceForCommitV2(o.commit)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/assertPRGithub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (suite *AssertPRGithubCommandTestSuite) TestAssertPRGithubCmd() {
name: "assert Github PR evidence fails when commit does not exist",
cmd: `assert pullrequest github --github-org kosli-dev --repository cli
--commit 19aab7f063147614451c88969602a10afba123ab` + suite.defaultKosliArguments,
golden: "Error: GET https://api.github.com/repos/kosli-dev/cli/commits/19aab7f063147614451c88969602a10afba123ab/pulls: 422 No commit found for SHA: 19aab7f063147614451c88969602a10afba123ab []\n",
golden: "Error: assert failed: found no pull request(s) in Github for commit: 19aab7f063147614451c88969602a10afba123ab\n",
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/assertPRGitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func newAssertPullRequestGitlabCmd(out io.Writer) *cobra.Command {
}

func (o *assertPullRequestGitlabOptions) run(args []string) error {
pullRequestsEvidence, err := o.gitlabConfig.PREvidenceForCommit(o.commit)
pullRequestsEvidence, err := o.gitlabConfig.PREvidenceForCommitV2(o.commit)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/kosli/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,6 @@ var liveCliMap = map[string]string{
"kosli list flows": "kosli list flows --output=json",
"kosli get flow": "kosli get flow dashboard-ci --output=json",
//"kosli list trails": "kosli list trails dashboard-ci --output=json", // Produces too much output
"kosli get trail": "kosli get trail dashboard-ci 1159a6f1193150681b8484545150334e89de6c1c --output=json",
"kosli get attestation": "kosli get attestation snyk-container-scan --flow=differ-ci --fingerprint=0cbbe3a6e73e733e8ca4b8813738d68e824badad0508ff20842832b5143b48c0 --output=json",
"kosli get trail": "kosli get trail dashboard-ci 1159a6f1193150681b8484545150334e89de6c1c --output=json",
"kosli get attestation": "kosli get attestation snyk-container-scan --flow=differ-ci --fingerprint=0cbbe3a6e73e733e8ca4b8813738d68e824badad0508ff20842832b5143b48c0 --output=json",
}
31 changes: 23 additions & 8 deletions cmd/kosli/pullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,19 @@ func (o *pullRequestArtifactOptions) run(out io.Writer, args []string) error {
}
}

label := ""
o.payload.GitProvider, label = getGitProviderAndLabel(o.retriever)

url := fmt.Sprintf("%s/api/v2/evidence/%s/artifact/%s/pull_request", global.Host, global.Org, o.flowName)
pullRequestsEvidence, err := o.getRetriever().PREvidenceForCommit(o.commit)

// TODO: after the PR payload is enhanced for all git providers they will all use the same method
var pullRequestsEvidence []*types.PREvidence
if o.payload.GitProvider == "github" {
pullRequestsEvidence, err = o.getRetriever().PREvidenceForCommitV1(o.commit)
} else {
pullRequestsEvidence, err = o.getRetriever().PREvidenceForCommitV2(o.commit)
}

if err != nil {
return err
}
Expand All @@ -60,9 +71,6 @@ func (o *pullRequestArtifactOptions) run(out io.Writer, args []string) error {
return err
}

label := ""
o.payload.GitProvider, label = getGitProviderAndLabel(o.retriever)

// PR evidence does not have files to upload
form, cleanupNeeded, evidencePath, err := newEvidenceForm(o.payload, []string{})
// if we created a tar package, remove it after uploading it
Expand Down Expand Up @@ -119,7 +127,7 @@ func (o *attestPROptions) run(args []string) error {
return err
}

pullRequestsEvidence, err := o.getRetriever().PREvidenceForCommit(o.payload.Commit.Sha1)
pullRequestsEvidence, err := o.getRetriever().PREvidenceForCommitV2(o.payload.Commit.Sha1)
if err != nil {
return err
}
Expand Down Expand Up @@ -175,14 +183,21 @@ func (o *pullRequestCommitOptions) run(args []string) error {
return err
}

pullRequestsEvidence, err := o.getRetriever().PREvidenceForCommit(o.payload.CommitSHA)
label := ""
o.payload.GitProvider, label = getGitProviderAndLabel(o.retriever)

// TODO: after the PR payload is enhanced for all git providers they will all use the same method
var pullRequestsEvidence []*types.PREvidence
if o.payload.GitProvider == "github" {
pullRequestsEvidence, err = o.getRetriever().PREvidenceForCommitV1(o.payload.CommitSHA)
} else {
pullRequestsEvidence, err = o.getRetriever().PREvidenceForCommitV2(o.payload.CommitSHA)
}
if err != nil {
return err
}

o.payload.PullRequests = pullRequestsEvidence
label := ""
o.payload.GitProvider, label = getGitProviderAndLabel(o.retriever)

// PR evidence does not have files to upload
form, cleanupNeeded, evidencePath, err := newEvidenceForm(o.payload, []string{})
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ require (
github.com/owenrumney/go-sarif/v2 v2.3.3
github.com/pkg/errors v0.9.1
github.com/rjeczalik/notify v0.9.3
github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466
github.com/spf13/cobra v1.9.1
github.com/spf13/pflag v1.0.6
github.com/spf13/viper v1.20.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,8 @@ github.com/sagikazarmark/locafero v0.9.0/go.mod h1:UBUyz37V+EdMS3hDF3QWIiVr/2dPr
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 h1:17JxqqJY66GmZVHkmAsGEkcIu0oCe3AM420QDgGwZx0=
github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466/go.mod h1:9dIRpgIY7hVhoqfe0/FcYp0bpInZaT7dc3BYOprrIUE=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
Expand Down
11 changes: 9 additions & 2 deletions internal/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/kosli-dev/cli/internal/types"
"github.com/kosli-dev/cli/internal/utils"
"github.com/microsoft/azure-devops-go-api/azuredevops"
"github.com/microsoft/azure-devops-go-api/azuredevops/git"
)
Expand Down Expand Up @@ -54,7 +55,8 @@ func NewAzureClientFromToken(ctx context.Context, azToken, orgURL string) (git.C
return gitClient, nil
}

func (c *AzureConfig) PREvidenceForCommit(commit string) ([]*types.PREvidence, error) {
// This is the old implementation, it will be removed after the PR payload is enhanced for Azure
func (c *AzureConfig) PREvidenceForCommitV2(commit string) ([]*types.PREvidence, error) {
pullRequestsEvidence := []*types.PREvidence{}
prs, err := c.PullRequestsForCommit(commit)
if err != nil {
Expand All @@ -70,6 +72,11 @@ func (c *AzureConfig) PREvidenceForCommit(commit string) ([]*types.PREvidence, e
return pullRequestsEvidence, nil
}

// This is the new implementation, it will be used for Azure
func (c *AzureConfig) PREvidenceForCommitV1(commit string) ([]*types.PREvidence, error) {
return []*types.PREvidence{}, nil
}

func (c *AzureConfig) newPRAzureEvidence(pr git.GitPullRequest) (*types.PREvidence, error) {
prID := strconv.Itoa(*pr.PullRequestId)
url, err := url.JoinPath(c.OrgURL, c.Project, "_git", c.Repository, "pullrequest", prID)
Expand All @@ -85,7 +92,7 @@ func (c *AzureConfig) newPRAzureEvidence(pr git.GitPullRequest) (*types.PREviden
if err != nil {
return evidence, err
}
evidence.Approvers = approvers
evidence.Approvers = utils.ConvertStringListToInterfaceList(approvers)
return evidence, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/azure/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (suite *AzureTestSuite) TestPREvidenceForCommit() {
testHelpers.SkipIfEnvVarUnset(suite.Suite.T(), []string{"KOSLI_AZURE_TOKEN"})
t.config.Token = os.Getenv("KOSLI_AZURE_TOKEN")
}
prs, err := t.config.PREvidenceForCommit(t.commit)
prs, err := t.config.PREvidenceForCommitV2(t.commit)
if t.result.wantError {
require.Errorf(suite.Suite.T(), err, "expected an error but got: %s", err)
} else {
Expand Down
11 changes: 9 additions & 2 deletions internal/bitbucket/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/kosli-dev/cli/internal/logger"
"github.com/kosli-dev/cli/internal/requests"
"github.com/kosli-dev/cli/internal/types"
"github.com/kosli-dev/cli/internal/utils"
)

type Config struct {
Expand All @@ -21,10 +22,16 @@ type Config struct {
Assert bool
}

func (c *Config) PREvidenceForCommit(commit string) ([]*types.PREvidence, error) {
// This is the old implementation, it will be removed after the PR payload is enhanced for Bitbucket
func (c *Config) PREvidenceForCommitV2(commit string) ([]*types.PREvidence, error) {
return c.getPullRequestsFromBitbucketApi(commit)
}

// This is the new implementation, it will be used for Bitbucket
func (c *Config) PREvidenceForCommitV1(commit string) ([]*types.PREvidence, error) {
return []*types.PREvidence{}, nil
}

func (c *Config) getPullRequestsFromBitbucketApi(commit string) ([]*types.PREvidence, error) {
pullRequestsEvidence := []*types.PREvidence{}

Expand Down Expand Up @@ -122,7 +129,7 @@ func (c *Config) getPullRequestDetailsFromBitbucket(prApiUrl, prHtmlLink, commit
} else {
c.Logger.Debug("no approvers found")
}
evidence.Approvers = approvers
evidence.Approvers = utils.ConvertStringListToInterfaceList(approvers)
// prID := int(responseData["id"].(float64))
// evidence.LastCommit, evidence.LastCommitter, err = getBitbucketPRLastCommit(workspace, repository, username, password, prID)
// if err != nil {
Expand Down
Loading