Skip to content

Commit

Permalink
batch annotations send
Browse files Browse the repository at this point in the history
  • Loading branch information
taraspos committed Oct 5, 2020
1 parent 4c4d5ca commit af9b22f
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions service/bitbucket/annotator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
// avatar from https://github.com/apps/reviewdog
logoURL = "https://avatars1.githubusercontent.com/in/12131"
reporter = "reviewdog"
// max amount of annotations in one batch call
annotationsBatchSize = 100
)

// ReportAnnotator is a comment service for Bitbucket Code Insights reports.
Expand Down Expand Up @@ -92,13 +94,22 @@ func (r *ReportAnnotator) Flush(ctx context.Context) error {
return err
}

// add annotations to the report
_, resp, err := r.cli.ReportsApi.BulkCreateOrUpdateAnnotations(
ctx, r.owner, r.repo, r.sha, reportID,
).Body(annotations).Execute()
// send annotations in batches, because of the api max payload size limit
for start, annCount := 0, len(annotations); start < annCount; start += annotationsBatchSize {
end := start + annotationsBatchSize

if err := checkAPIError(err, resp, http.StatusOK); err != nil {
return fmt.Errorf("bitbucket.BulkCreateOrUpdateAnnotations: %s", err)
if end > annCount {
end = annCount
}

// add annotations to the report
_, resp, err := r.cli.ReportsApi.BulkCreateOrUpdateAnnotations(
ctx, r.owner, r.repo, r.sha, reportID,
).Body(annotations[start:end]).Execute()

if err := checkAPIError(err, resp, http.StatusOK); err != nil {
return fmt.Errorf("bitbucket.BulkCreateOrUpdateAnnotations: %s", err)
}
}
}

Expand Down

0 comments on commit af9b22f

Please sign in to comment.