Skip to content

Commit

Permalink
Never alone: Started on sending pull request author to kosli in pull …
Browse files Browse the repository at this point in the history
…request attestation
  • Loading branch information
ToreMerkely committed Aug 12, 2024
1 parent d77f0dc commit 4776982
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
46 changes: 35 additions & 11 deletions bin/never_alone_report_commit_and_pr_to_kosli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,27 @@ function get_commit_and_pull_request
echo ${compliant}
}


function report_kosli_attest_pull_request
{
local commit_sha=$1; shift
local commit_pull_request_flow=$1; shift
local trail_name=$1; shift
local short_commit_sha=${commit_sha:0:7}

/work/r1/cli/kosli attest pullrequest github \
--name=commit_${short_commit_sha} \
--assert \
--commit=${commit_sha} \
--flow=${commit_pull_request_flow} \
--trail=${trail_name} \
--repository=https://github.com/kosli-dev/cli \
--github-token ${GITHUB_TOKEN} \
--github-org kosli-dev --debug --dry-run

}


function get_commit_and_pr_data_and_report_to_kosli
{
local base_commit=$1; shift
Expand All @@ -131,20 +152,23 @@ function get_commit_and_pr_data_and_report_to_kosli
local trail_name=$1; shift
local commits compliant

base_commit=b3c6cf0422e484b327e393f58af1ee089b1e98d2

commits=($(gh api repos/:owner/:repo/compare/${base_commit}...${proposed_commit} -q '.commits[].sha')) \
|| die "Failed to get list of commits between '${base_commit}' and '${proposed_commit}' with: gh api"
for commit_sha in "${commits[@]}"; do
local short_commit_sha=${commit_sha:0:7}
local file_name="commit_pr_${short_commit_sha}.json"
compliant=$(get_commit_and_pull_request ${commit_sha} ${file_name})
kosli attest generic \
--name=commit_${short_commit_sha} \
--compliant=${compliant} \
--commit=${commit_sha} \
--attachments=${file_name} \
--flow=${commit_pull_request_flow} \
--trail=${trail_name}
rm ${file_name}
report_kosli_attest_pull_request ${commit_sha} ${commit_pull_request_flow} ${trail_name}
# local short_commit_sha=${commit_sha:0:7}
# local file_name="commit_pr_${short_commit_sha}.json"
# compliant=$(get_commit_and_pull_request ${commit_sha} ${file_name})
# kosli attest generic \
# --name=commit_${short_commit_sha} \
# --compliant=${compliant} \
# --commit=${commit_sha} \
# --attachments=${file_name} \
# --flow=${commit_pull_request_flow} \
# --trail=${trail_name}
# rm ${file_name}
done
}

Expand Down
3 changes: 3 additions & 0 deletions internal/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ 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(),
},
}
approvers, err := c.GetPullRequestApprovers(pr.GetNumber())
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type PREvidence struct {
URL string `json:"url"`
State string `json:"state"`
Approvers []string `json:"approvers"`
Author PRAuthor `json:"author"`
// LastCommit string `json:"lastCommit"`
// LastCommitter string `json:"lastCommitter"`
// SelfApproved bool `json:"selfApproved"`
Expand All @@ -13,3 +14,7 @@ type PREvidence struct {
type PRRetriever interface {
PREvidenceForCommit(string) ([]*PREvidence, error)
}

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

0 comments on commit 4776982

Please sign in to comment.