Skip to content

Commit

Permalink
add list effective default reviewers endpoint (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
craftamap authored Jul 13, 2023
1 parent 9013ecc commit f51660a
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ type DefaultReviewer struct {
Links map[string]map[string]string
}


type DefaultReviewers struct {
Page int
Pagelen int
Expand All @@ -208,6 +209,20 @@ type DefaultReviewers struct {
Next string
DefaultReviewers []DefaultReviewer
}
type EffectiveDefaultReviewer struct {
User DefaultReviewer
Type string
ReviewerType string `mapstructure:"reviewer_type"`
}

type EffectiveDefaultReviewers struct {
Page int
Pagelen int
MaxDepth int
Size int
Next string
EffectiveDefaultReviewers []EffectiveDefaultReviewer
}

type Group struct {
AccountPrivilege string `mapstructure:"account_privilege"`
Expand Down Expand Up @@ -626,6 +641,16 @@ func (r *Repository) DeleteDefaultReviewer(rdro *RepositoryDefaultReviewerOption
return r.c.execute("DELETE", urlStr, "")
}

func (r *Repository) ListEffectiveDefaultReviewers(ro *RepositoryOptions) (*EffectiveDefaultReviewers, error) {
urlStr := r.c.requestUrl("/repositories/%s/%s/effective-default-reviewers", ro.Owner, ro.RepoSlug)

res, err := r.c.executePaginated("GET", urlStr, "", nil)
if err != nil {
return nil, err
}
return decodeEffectiveDefaultReviewers(res)
}

func (r *Repository) GetPipelineConfig(rpo *RepositoryPipelineOptions) (*Pipeline, error) {
urlStr := r.c.requestUrl("/repositories/%s/%s/pipelines_config", rpo.Owner, rpo.RepoSlug)
response, err := r.c.execute("GET", urlStr, "")
Expand Down Expand Up @@ -1761,6 +1786,53 @@ func decodeDefaultReviewers(response interface{}) (*DefaultReviewers, error) {
return &defaultReviewerVariables, nil
}


func decodeEffectiveDefaultReviewers(response interface{}) (*EffectiveDefaultReviewers, error) {
responseMap := response.(map[string]interface{})
values := responseMap["values"].([]interface{})
var variables []EffectiveDefaultReviewer
for _, variable := range values {
var defaultReviewerVariable EffectiveDefaultReviewer
err := mapstructure.Decode(variable, &defaultReviewerVariable)
if err == nil {
variables = append(variables, defaultReviewerVariable)
}
}

page, ok := responseMap["page"].(float64)
if !ok {
page = 0
}

pagelen, ok := responseMap["pagelen"].(float64)
if !ok {
pagelen = 0
}
max_depth, ok := responseMap["max_depth"].(float64)
if !ok {
max_depth = 0
}
size, ok := responseMap["size"].(float64)
if !ok {
size = 0
}

next, ok := responseMap["next"].(string)
if !ok {
next = ""
}

defaultReviewerVariables := EffectiveDefaultReviewers{
Page: int(page),
Pagelen: int(pagelen),
MaxDepth: int(max_depth),
Size: int(size),
Next: next,
EffectiveDefaultReviewers: variables,
}
return &defaultReviewerVariables, nil
}

func decodeGroupPermissions(response interface{}) (*GroupPermission, error) {
var groupPermission GroupPermission
err := mapstructure.Decode(response, &groupPermission)
Expand Down

0 comments on commit f51660a

Please sign in to comment.