github.com/OnkarRuikar/reviewdog@v0.0.0-20230802094019-bc1001e3b2e5/service/bitbucket/api_client.go (about)

     1  package bitbucket
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/reviewdog/reviewdog"
     8  )
     9  
    10  // ReportRequest is an object that represent parameters used to create/update report
    11  type ReportRequest struct {
    12  	Owner      string
    13  	Repository string
    14  	Commit     string
    15  	ReportID   string
    16  	Type       string
    17  	Title      string
    18  	Reporter   string
    19  	Result     string
    20  	Details    string
    21  	LogoURL    string
    22  }
    23  
    24  // AnnotationsRequest is an object that represent parameters used to create/update annotations
    25  type AnnotationsRequest struct {
    26  	Owner      string
    27  	Repository string
    28  	Commit     string
    29  	ReportID   string
    30  	Comments   []*reviewdog.Comment
    31  }
    32  
    33  // APIClient is client for Bitbucket Code Insights API
    34  type APIClient interface {
    35  
    36  	// CreateOrUpdateReport creates or updates specified report
    37  	CreateOrUpdateReport(ctx context.Context, req *ReportRequest) error
    38  
    39  	// CreateOrUpdateAnnotations creates or updates annotations
    40  	CreateOrUpdateAnnotations(ctx context.Context, req *AnnotationsRequest) error
    41  }
    42  
    43  // UnexpectedResponseError is triggered when we have unexpected response from Code Insights API
    44  type UnexpectedResponseError struct {
    45  	Code int
    46  	Body []byte
    47  }
    48  
    49  func (e UnexpectedResponseError) Error() string {
    50  	msg := fmt.Sprintf("received unexpected %d code from Bitbucket API", e.Code)
    51  
    52  	if len(e.Body) > 0 {
    53  		msg += " with message:\n" + string(e.Body)
    54  	}
    55  
    56  	return msg
    57  }