Skip to content

Commit

Permalink
Change author to string, do not send compliant or reason for non comp…
Browse files Browse the repository at this point in the history
…liance
  • Loading branch information
ToreMerkely committed Aug 26, 2024
1 parent 63e00a2 commit e30d058
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 38 deletions.
50 changes: 25 additions & 25 deletions cmd/kosli/pullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ func (o *pullRequestArtifactOptions) run(out io.Writer, args []string) error {

type PRAttestationPayload struct {
*CommonAttestationPayload
GitProvider string `json:"git_provider"`
PullRequests []*types.PREvidence `json:"pull_requests"`
ReasonForNonCompliance string `json:"reason_for_non_compliance,omitempty"`
RequireApproverNotAuthor bool `json:"require_approver_not_author"`
GitProvider string `json:"git_provider"`
PullRequests []*types.PREvidence `json:"pull_requests"`
// ReasonForNonCompliance string `json:"reason_for_non_compliance,omitempty"`
RequireApproverNotAuthor bool `json:"require_approver_not_author"`
}

type attestPROptions struct {
Expand Down Expand Up @@ -128,27 +128,27 @@ func (o *attestPROptions) run(args []string) error {

o.payload.PullRequests = pullRequestsEvidence

if o.payload.RequireApproverNotAuthor {
var compliant = false
if len(pullRequestsEvidence) == 0 {
o.payload.ReasonForNonCompliance = "No pull-request"
} else {
approvers := pullRequestsEvidence[0].Approvers
if len(approvers) == 0 {
o.payload.PullRequests[0].ReasonsForNonCompliance = []string{"No approver"}
} else {
for _, approver := range approvers {
if approver != pullRequestsEvidence[0].Author.Login {
compliant = true
}
}
if !compliant {
o.payload.PullRequests[0].ReasonsForNonCompliance = []string{"Approver is the author"}
}
}
o.payload.PullRequests[0].Compliant = &compliant
}
}
// if o.payload.RequireApproverNotAuthor {
// var compliant = false
// if len(pullRequestsEvidence) == 0 {
// o.payload.ReasonForNonCompliance = "No pull-request"
// } else {
// approvers := pullRequestsEvidence[0].Approvers
// if len(approvers) == 0 {
// o.payload.PullRequests[0].ReasonsForNonCompliance = []string{"No approver"}
// } else {
// for _, approver := range approvers {
// if approver != pullRequestsEvidence[0].Author {
// compliant = true
// }
// }
// if !compliant {
// o.payload.PullRequests[0].ReasonsForNonCompliance = []string{"Approver is the author"}
// }
// }
// o.payload.PullRequests[0].Compliant = &compliant
// }
// }

label := ""
o.payload.GitProvider, label = getGitProviderAndLabel(o.retriever)
Expand Down
4 changes: 1 addition & 3 deletions internal/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ func (c *GithubConfig) newPRGithubEvidence(pr *gh.PullRequest) (*types.PREvidenc
URL: pr.GetHTMLURL(),
MergeCommit: pr.GetMergeCommitSHA(),
State: pr.GetState(),
Author: types.PRAuthor{
Login: pr.GetUser().GetLogin(),
},
Author: pr.GetUser().GetLogin(),
}
approvers, err := c.GetPullRequestApprovers(pr.GetNumber())
if err != nil {
Expand Down
20 changes: 10 additions & 10 deletions internal/types/types.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package types

type PREvidence struct {
MergeCommit string `json:"merge_commit"`
URL string `json:"url"`
State string `json:"state"`
Approvers []string `json:"approvers"`
Author PRAuthor `json:"author"`
Compliant *bool `json:"is_compliant,omitempty"`
ReasonsForNonCompliance []string `json:"reasons_for_non_compliance,omitempty"`
MergeCommit string `json:"merge_commit"`
URL string `json:"url"`
State string `json:"state"`
Approvers []string `json:"approvers"`
Author string `json:"author"`
// Compliant *bool `json:"is_compliant,omitempty"`
// ReasonsForNonCompliance []string `json:"reasons_for_non_compliance,omitempty"`
// LastCommit string `json:"lastCommit"`
// LastCommitter string `json:"lastCommitter"`
// SelfApproved bool `json:"selfApproved"`
Expand All @@ -17,6 +17,6 @@ type PRRetriever interface {
PREvidenceForCommit(string) ([]*PREvidence, error)
}

type PRAuthor struct {
Login string `json:"login"`
}
// type PRAuthor struct {
// Login string `json:"login"`
// }

0 comments on commit e30d058

Please sign in to comment.