@@ -2,6 +2,7 @@ package main
22
33import (
44 "fmt"
5+ "os"
56 "regexp"
67 "strings"
78
@@ -22,6 +23,7 @@ type URLInfo struct {
2223type CommonAttestationPayload struct {
2324 ArtifactFingerprint string `json:"artifact_fingerprint,omitempty"`
2425 Commit * gitview.BasicCommitInfo `json:"git_commit_info,omitempty"`
26+ GitRepoInfo * gitview.GitRepoInfo `json:"repo_info,omitempty"`
2527 AttestationName string `json:"attestation_name"`
2628 TargetArtifacts []string `json:"target_artifacts,omitempty"`
2729 ExternalURLs map [string ]* URLInfo `json:"external_urls,omitempty"`
@@ -79,6 +81,11 @@ func (o *CommonAttestationOptions) run(args []string, payload *CommonAttestation
7981 payload .Commit = & commitInfo .BasicCommitInfo
8082 }
8183
84+ payload .GitRepoInfo , err = getGitRepoInfoFromEnvironment ()
85+ if err != nil {
86+ logger .Warn ("failed to get git repo info. %s" , err .Error ())
87+ }
88+
8289 payload .UserData , err = LoadJsonData (o .userDataFilePath )
8390 if err != nil {
8491 return fmt .Errorf ("failed to load user data. %s" , err )
@@ -174,3 +181,70 @@ func wrapAttestationError(err error) error {
174181 }
175182 return err
176183}
184+
185+ func getGitRepoInfoFromEnvironment () (* gitview.GitRepoInfo , error ) {
186+ ci := WhichCI ()
187+ switch ci {
188+ case github :
189+ return getGitRepoInfoFromGitHub (), nil
190+ case gitlab :
191+ return getGitRepoInfoFromGitLab (), nil
192+ case bitbucket :
193+ return getGitRepoInfoFromBitbucket (), nil
194+ case azureDevops :
195+ return getGitRepoInfoFromAzureDevops (), nil
196+ case circleci :
197+ return getGitRepoInfoFromCircleci (), nil
198+ case codeBuild :
199+ return getGitRepoInfoFromCodeBuild (), nil
200+ case unknown :
201+ return nil , nil
202+ }
203+ return nil , fmt .Errorf ("unsupported CI: %s" , ci )
204+ }
205+
206+ func getGitRepoInfoFromGitHub () * gitview.GitRepoInfo {
207+ return & gitview.GitRepoInfo {
208+ URL : fmt .Sprintf ("%s/%s" , os .Getenv ("GITHUB_SERVER_URL" ), os .Getenv ("GITHUB_REPOSITORY" )),
209+ Name : os .Getenv ("GITHUB_REPOSITORY" ),
210+ ID : os .Getenv ("GITHUB_REPOSITORY_ID" ),
211+ }
212+ }
213+
214+ func getGitRepoInfoFromGitLab () * gitview.GitRepoInfo {
215+ return & gitview.GitRepoInfo {
216+ URL : os .Getenv ("CI_PROJECT_URL" ),
217+ Name : os .Getenv ("CI_PROJECT_PATH" ),
218+ ID : os .Getenv ("CI_PROJECT_ID" ),
219+ Description : os .Getenv ("CI_PROJECT_DESCRIPTION" ),
220+ }
221+ }
222+
223+ func getGitRepoInfoFromBitbucket () * gitview.GitRepoInfo {
224+ return & gitview.GitRepoInfo {
225+ URL : os .Getenv ("BITBUCKET_GIT_HTTP_ORIGIN" ),
226+ Name : os .Getenv ("BITBUCKET_REPO_FULL_NAME" ),
227+ ID : os .Getenv ("BITBUCKET_REPO_UUID" ),
228+ }
229+ }
230+
231+ func getGitRepoInfoFromAzureDevops () * gitview.GitRepoInfo {
232+ return & gitview.GitRepoInfo {
233+ URL : os .Getenv ("BUILD_REPOSITORY_URI" ),
234+ Name : os .Getenv ("BUILD_REPOSITORY_NAME" ),
235+ ID : os .Getenv ("BUILD_REPOSITORY_ID" ),
236+ }
237+ }
238+
239+ func getGitRepoInfoFromCircleci () * gitview.GitRepoInfo {
240+ return & gitview.GitRepoInfo {
241+ URL : os .Getenv ("CIRCLE_REPOSITORY_URL" ),
242+ Name : os .Getenv ("CIRCLE_PROJECT_REPONAME" ),
243+ }
244+ }
245+
246+ func getGitRepoInfoFromCodeBuild () * gitview.GitRepoInfo {
247+ return & gitview.GitRepoInfo {
248+ URL : os .Getenv ("CODEBUILD_SOURCE_REPO_URL" ),
249+ }
250+ }
0 commit comments