Skip to content

Commit

Permalink
Fix issue with new branch-name and pull-request-id flags (#246)
Browse files Browse the repository at this point in the history
* Fix issue with new branch-name and pull-request-id flags

* Add better error message for incorrect sonar API token
  • Loading branch information
FayeSGW authored Jun 14, 2024
1 parent 8cd962a commit b87464f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions cmd/kosli/attestSonar.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type SonarAttestationPayload struct {
SonarResults *sonar.SonarResults `json:"sonar_results"`
}

// It is also possible to provide a branch or PR number, but not necessary - how do we handle this here?
type attestSonarOptions struct {
*CommonAttestationOptions
projectKey string
Expand Down Expand Up @@ -119,8 +118,8 @@ func newAttestSonarCmd(out io.Writer) *cobra.Command {
addAttestationFlags(cmd, o.CommonAttestationOptions, o.payload.CommonAttestationPayload, ci)
cmd.Flags().StringVar(&o.projectKey, "sonar-project-key", "", "SonarCloud project key")
cmd.Flags().StringVar(&o.apiToken, "sonar-api-token", "", "SonarCloud API token")
cmd.Flags().StringVar(&o.apiToken, "branch-name", "", "CI Branch Name")
cmd.Flags().StringVar(&o.apiToken, "pull-request-id", "", "Pull Request ID")
cmd.Flags().StringVar(&o.branchName, "branch-name", "", "CI Branch Name")
cmd.Flags().StringVar(&o.pullRequestID, "pull-request-id", "", "Pull Request ID")

err := RequireFlags(cmd, []string{"flow", "trail", "name", "sonar-project-key", "sonar-api-token"})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/sonar/sonar.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ func (sc *SonarConfig) GetSonarResults() (*SonarResults, error) {
sonarResult := &SonarResults{Component: Component{}}
err = json.NewDecoder(response.Body).Decode(sonarResult)
if err != nil {
return nil, err
return nil, fmt.Errorf("No data retrieved from Sonarcloud - check your API token is correct")
}

//With incorrect project key or API token we receive no data
if sonarResult.Component.Key == "" {
return nil, fmt.Errorf("No data retrieved from Sonarcloud - check your project key and API token are correct")
return nil, fmt.Errorf("No data retrieved from Sonarcloud - check your project key and branch or pull request id are correct")
}

return sonarResult, nil
Expand Down

0 comments on commit b87464f

Please sign in to comment.