Skip to content

Commit

Permalink
fix(codeqlExecuteScan): improved logging (#4817)
Browse files Browse the repository at this point in the history
  • Loading branch information
daskuznetsova authored Feb 5, 2024
1 parent b9ea3e9 commit 668b371
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cmd/codeqlExecuteScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func initGitInfo(config *codeqlExecuteScanOptions) (codeql.RepoInfo, error) {
}
}
if len(config.TargetGithubRepoURL) > 0 {
log.Entry().Infof("Checking target GitHub repo URL: %s", config.TargetGithubRepoURL)
if strings.Contains(repoInfo.ServerUrl, "github") {
log.Entry().Errorf("TargetGithubRepoURL should not be set as the source repo is on github.")
return repoInfo, errors.New("TargetGithubRepoURL should not be set as the source repo is on github.")
Expand All @@ -163,6 +164,7 @@ func initGitInfo(config *codeqlExecuteScanOptions) (codeql.RepoInfo, error) {
return repoInfo, err
}
if len(config.TargetGithubBranchName) > 0 {
log.Entry().Infof("Target GitHub branch name: %s", config.TargetGithubBranchName)
repoInfo.Ref = config.TargetGithubBranchName
if len(strings.Split(config.TargetGithubBranchName, "/")) < 3 {
repoInfo.Ref = "refs/heads/" + config.TargetGithubBranchName
Expand Down Expand Up @@ -342,6 +344,7 @@ func runCodeqlExecuteScan(config *codeqlExecuteScanOptions, telemetryData *telem
repoCodeqlScanUrl := fmt.Sprintf("%s/security/code-scanning?query=is:open+ref:%s", repoUrl, repoInfo.Ref)

if len(config.TargetGithubRepoURL) > 0 {
log.Entry().Infof("DB sources for %s will be uploaded to target GitHub repo: %s", config.Repository, repoUrl)
hasToken, token := getToken(config)
if !hasToken {
return reports, errors.New("failed running upload db sources to GitHub as githubToken was not specified")
Expand All @@ -362,13 +365,15 @@ func runCodeqlExecuteScan(config *codeqlExecuteScanOptions, telemetryData *telem
return reports, errors.Wrap(err, "failed uploading db sources from non-GitHub SCM to GitHub")
}
repoInfo.CommitId = targetCommitId
log.Entry().Info("DB sources were successfully uploaded to target GitHub repo")
}

var scanResults []codeql.CodeqlFindings

if !config.UploadResults {
log.Entry().Warn("The sarif results will not be uploaded to the repository and compliance report will not be generated as uploadResults is set to false.")
} else {
log.Entry().Infof("The sarif results will be uploaded to the repository %s", repoUrl)
hasToken, token := getToken(config)
if !hasToken {
return reports, errors.New("failed running upload-results as githubToken was not specified")
Expand Down
4 changes: 2 additions & 2 deletions cmd/codeqlExecuteScan_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions resources/metadata/codeqlExecuteScan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ spec:
default: 30
- name: targetGithubRepoURL
type: string
descriptoin: "Target github repo url. Only relevant, if project uses a combination of Piper and non-GitHub SCM."
description: "Target github repo url. Only relevant, if project uses a combination of Piper and non-GitHub SCM."
scope:
- PARAMETERS
- STAGES
- STEPS
- name: targetGithubBranchName
type: string
descriptoin: "Target github branch name. Only relevant, if project uses a combination of Piper and non-GitHub SCM."
description: "Target github branch name. Only relevant, if project uses a combination of Piper and non-GitHub SCM."
scope:
- PARAMETERS
- STAGES
Expand Down

0 comments on commit 668b371

Please sign in to comment.