diff --git a/.gitignore b/.gitignore index 4c7d39e..787a7fd 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -/coverage.txt \ No newline at end of file +/coverage.txt + +.idea/ \ No newline at end of file diff --git a/changes.go b/changes.go index 9d2bea7..f32c332 100644 --- a/changes.go +++ b/changes.go @@ -6,6 +6,8 @@ import ( "fmt" "io" "net/http" + "strconv" + "strings" ) // RevisionKind describes the change kind. @@ -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. @@ -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"` @@ -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. diff --git a/changes_revision.go b/changes_revision.go index 719e1bb..c4f5427 100644 --- a/changes_revision.go +++ b/changes_revision.go @@ -482,10 +482,10 @@ 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) @@ -493,7 +493,7 @@ func (s *ChangesService) TestSubmitRule(ctx context.Context, changeID, revisionI return nil, nil, err } - v := new([]SubmitRecord) + v := new([]SubmitRecordInfo) resp, err := s.client.Do(req, v) if err != nil { return nil, resp, err diff --git a/events.go b/events.go index 73280e7..69d2fda 100644 --- a/events.go +++ b/events.go @@ -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