Skip to content

Improve the SubmitRecord structure #168

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

Open
wants to merge 6 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/coverage.txt
/coverage.txt

.idea/
55 changes: 50 additions & 5 deletions changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"io"
"net/http"
"strconv"
"strings"
)

// RevisionKind describes the change kind.
Expand Down Expand Up @@ -57,12 +59,39 @@ type AbandonInput struct {
Notify string `json:"notify,omitempty"`
NotifyDetails []NotifyInfo `json:"notify_details,omitempty"`
}
type IntStr string

// UnmarshalJSON implements the json.Unmarshaler interface for IntStr
func (i *IntStr) UnmarshalJSON(data []byte) error {
str := string(data)
str = strings.Trim(str, "\"")
val, err := strconv.Atoi(strings.Trim(str, "/"))
if err != nil {
return err
}
*i = IntStr(fmt.Sprintf("%d", val))
return nil
}

func (i IntStr) Int() int {
v, err := strconv.Atoi(string(i))
if err != nil {
return 0
}
return v
}

func (i IntStr) String() string {
return string(i)
}

// ApprovalInfo entity contains information about an approval from a user for a label on a change.
type ApprovalInfo struct {
AccountInfo
Value int `json:"value,omitempty"`
Date string `json:"date,omitempty"`
Value IntStr `json:"value,omitempty"`
OldValue IntStr `json:"oldValue,omitempty"`
Description string `json:"description,omitempty"`
Date string `json:"date,omitempty"`
}

// CommitMessageInput entity contains information for changing the commit message of a change.
Expand Down Expand Up @@ -223,17 +252,32 @@ type TopicInput struct {
Topic string `json:"topic,omitempty"`
}

// SubmitRecord entity describes results from a submit_rule.
type SubmitRecord struct {
Status string `json:"status"`
type SubmitRecordInfoLabel struct {
Label string `json:"label,omitempty"`
Status string `json:"status,omitempty"`
AppliedBy AccountInfo `json:"applied_by,omitempty"`
}

// SubmitRecordInfo entity describes results from a submit_rule.
type SubmitRecordInfo struct {
RuleName string `json:"rule_name,omitempty"`
Status string `json:"status,omitempty"`
Labels []SubmitRecordInfoLabel `json:"labels,omitempty"`
Ok map[string]map[string]AccountInfo `json:"ok,omitempty"`
Reject map[string]map[string]AccountInfo `json:"reject,omitempty"`
Need map[string]interface{} `json:"need,omitempty"`
May map[string]map[string]AccountInfo `json:"may,omitempty"`
Impossible map[string]interface{} `json:"impossible,omitempty"`
Requirements []RequirementInfo `json:"requirements,omitempty"`
ErrorMessage string `json:"error_message,omitempty"`
}

type RequirementInfo struct {
Status string `json:"status"`
FallbackText string `json:"fallback_text"`
Type string `json:"type"`
}

// SubmitInput entity contains information for submitting a change.
type SubmitInput struct {
OnBehalfOf string `json:"on_behalf_of,omitempty"`
Expand Down Expand Up @@ -472,6 +516,7 @@ type ChangeInfo struct {
CherryPickOfPatchSet int `json:"cherry_pick_of_patch_set,omitempty"`
ContainsGitConflicts bool `json:"contains_git_conflicts,omitempty"`
BaseChange string `json:"base_change,omitempty"`
SubmitRecords []SubmitRecordInfo `json:"submit_records,omitempty"`
}

// LabelInfo entity contains information about a label on a change, always corresponding to the current patch set.
Expand Down
6 changes: 3 additions & 3 deletions changes_revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,18 +482,18 @@ func (s *ChangesService) TestSubmitType(ctx context.Context, changeID, revisionI
// Request body may be either the Prolog code as text/plain or a RuleInput object.
// The query parameter filters may be set to SKIP to bypass parent project filters while testing a project-specific rule.
//
// The response is a list of SubmitRecord entries describing the permutations that satisfy the tested submit rule.
// The response is a list of SubmitRecordInfo entries describing the permutations that satisfy the tested submit rule.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#test-submit-rule
func (s *ChangesService) TestSubmitRule(ctx context.Context, changeID, revisionID string, input *RuleInput) (*[]SubmitRecord, *Response, error) {
func (s *ChangesService) TestSubmitRule(ctx context.Context, changeID, revisionID string, input *RuleInput) (*[]SubmitRecordInfo, *Response, error) {
u := fmt.Sprintf("changes/%s/revisions/%s/test.submit_rule", changeID, revisionID)

req, err := s.client.NewRequest(ctx, "POST", u, input)
if err != nil {
return nil, nil, err
}

v := new([]SubmitRecord)
v := new([]SubmitRecordInfo)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
Expand Down
44 changes: 22 additions & 22 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,28 @@ type RefUpdate struct {
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/cmd-stream-events.html#events
type EventInfo struct {
Type string `json:"type"`
Change ChangeInfo `json:"change,omitempty"`
ChangeKey ChangeInfo `json:"changeKey,omitempty"`
PatchSet PatchSet `json:"patchSet,omitempty"`
EventCreatedOn int `json:"eventCreatedOn,omitempty"`
Reason string `json:"reason,omitempty"`
Abandoner AccountInfo `json:"abandoner,omitempty"`
Restorer AccountInfo `json:"restorer,omitempty"`
Submitter AccountInfo `json:"submitter,omitempty"`
Author AccountInfo `json:"author,omitempty"`
Uploader AccountInfo `json:"uploader,omitempty"`
Approvals []AccountInfo `json:"approvals,omitempty"`
Comment string `json:"comment,omitempty"`
Editor AccountInfo `json:"editor,omitempty"`
Added []string `json:"added,omitempty"`
Removed []string `json:"removed,omitempty"`
Hashtags []string `json:"hashtags,omitempty"`
RefUpdate RefUpdate `json:"refUpdate,omitempty"`
Project ProjectInfo `json:"project,omitempty"`
Reviewer AccountInfo `json:"reviewer,omitempty"`
OldTopic string `json:"oldTopic,omitempty"`
Changer AccountInfo `json:"changer,omitempty"`
Type string `json:"type"`
Change ChangeInfo `json:"change,omitempty"`
ChangeKey ChangeInfo `json:"changeKey,omitempty"`
PatchSet PatchSet `json:"patchSet,omitempty"`
EventCreatedOn int `json:"eventCreatedOn,omitempty"`
Reason string `json:"reason,omitempty"`
Abandoner AccountInfo `json:"abandoner,omitempty"`
Restorer AccountInfo `json:"restorer,omitempty"`
Submitter AccountInfo `json:"submitter,omitempty"`
Author AccountInfo `json:"author,omitempty"`
Uploader AccountInfo `json:"uploader,omitempty"`
Approvals []ApprovalInfo `json:"approvals,omitempty"`
Comment string `json:"comment,omitempty"`
Editor AccountInfo `json:"editor,omitempty"`
Added []string `json:"added,omitempty"`
Removed []string `json:"removed,omitempty"`
Hashtags []string `json:"hashtags,omitempty"`
RefUpdate RefUpdate `json:"refUpdate,omitempty"`
Project ProjectInfo `json:"project,omitempty"`
Reviewer AccountInfo `json:"reviewer,omitempty"`
OldTopic string `json:"oldTopic,omitempty"`
Changer AccountInfo `json:"changer,omitempty"`
}

// EventsLogService contains functions for querying the API provided
Expand Down