Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitbucket Cloud fixes #1344

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### :bug: Fixes
- [#967](https://github.com/reviewdog/reviewdog/pull/967) Fix parsing long lines in diffs #967
- [#1344](https://github.com/reviewdog/reviewdog/pull/1344) Bitbucket Cloud Fixes
- ...

### :rotating_light: Breaking changes
Expand Down
18 changes: 18 additions & 0 deletions service/bitbucket/cloud_api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ func NewCloudAPIClientWithConfigurations(client *http.Client, server bbapi.Serve

// CreateOrUpdateReport creates or updates specified report
func (c *CloudAPIClient) CreateOrUpdateReport(ctx context.Context, req *ReportRequest) error {
// We need to drop report and delete all annotations created previously
err := c.deleteReport(ctx, req)
if err != nil {
return err
}

_, resp, err := c.cli.
ReportsApi.CreateOrUpdateReport(ctx, req.Owner, req.Repository, req.Commit, req.ReportID).
Body(c.helper.BuildReport(req)).
Expand All @@ -112,6 +118,18 @@ func (c *CloudAPIClient) CreateOrUpdateAnnotations(ctx context.Context, req *Ann
return nil
}

func (c *CloudAPIClient) deleteReport(ctx context.Context, report *ReportRequest) error {
resp, err := c.cli.ReportsApi.
DeleteReport(ctx, report.Owner, report.Repository, report.Commit, report.ReportID).
Execute()

if err := c.checkAPIError(err, resp, http.StatusNoContent); err != nil {
return fmt.Errorf("failed to delete code insights report: %w", err)
}

return nil
}

func (c *CloudAPIClient) checkAPIError(err error, resp *http.Response, expectedCode int) error {
if err != nil {
return fmt.Errorf("bitbucket Cloud API error: %w", err)
Expand Down
6 changes: 5 additions & 1 deletion service/bitbucket/cloud_api_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ func (c *CloudAPIHelper) buildAnnotation(comment *reviewdog.Comment) bbapi.Repor
data := bbapi.NewReportAnnotation()
data.SetExternalId(externalIDFromDiagnostic(comment.Result.Diagnostic))
data.SetAnnotationType(annotationTypeCodeSmell)
data.SetSummary(comment.Result.Diagnostic.GetMessage())
summary := comment.Result.Diagnostic.GetMessage()
if len(summary) > MAX_SUMMARY_LENGTH {
summary = summary[:MAX_SUMMARY_LENGTH]
}
data.SetSummary(summary)
data.SetDetails(fmt.Sprintf(`[%s] %s`, comment.ToolName, comment.Result.Diagnostic.GetMessage()))
data.SetLine(comment.Result.Diagnostic.GetLocation().GetRange().GetStart().GetLine())
data.SetPath(comment.Result.Diagnostic.GetLocation().GetPath())
Expand Down
3 changes: 2 additions & 1 deletion service/bitbucket/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package bitbucket
import "time"

const (
httpTimeout = time.Second * 10
httpTimeout = time.Second * 10
MAX_SUMMARY_LENGTH = 450

reportTypeBug = "BUG"
// reportTypeSecurity = "SECURITY"
Expand Down