Skip to content
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

Add missing AbandonChange, RebaseChange, RestoreChange and RevertChange #41

Merged
merged 8 commits into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ first. For more complete details see

## Versions

### 0.5.1

* Added the `AbandonChange`, `RebaseChange`, `RestoreChange` and
`RevertChange` functions.

### 0.5.0

**WARNING**: This release includes breaking changes.
Expand Down
112 changes: 104 additions & 8 deletions changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@ type GitPersonInfo struct {
TZ int `json:"tz"`
}

// NotifyInfo entity contains detailed information about who should be
// notified about an update
type NotifyInfo struct {
Accounts []AccountInfo `json:"accounts"`
}

// AbandonInput entity contains information for abandoning a change.
type AbandonInput struct {
Message string `json:"message,omitempty"`
Message string `json:"message,omitempty"`
Notify string `json:"notify"`
NotifyDetails []NotifyInfo `json:"notify_details"`
}

// ApprovalInfo entity contains information about an approval from a user for a label on a change.
Expand Down Expand Up @@ -706,10 +714,98 @@ func (s *ChangesService) SubmitChange(changeID string, input *SubmitInput) (*Cha
return v, resp, err
}

/*
Missing Change Endpoints
Abandon Change
Restore Change
Rebase Change
Revert Change
*/
// AbandonChange abandons a change.
//
// The request body does not need to include a AbandonInput entity if no review
// comment is added.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#abandon-change
func (s *ChangesService) AbandonChange(changeID string, input *AbandonInput) (*ChangeInfo, *Response, error) {
u := fmt.Sprintf("changes/%s/abandon", changeID)

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

v := new(ChangeInfo)

resp, err := s.client.Do(req, v)
if resp.StatusCode == http.StatusConflict {
body, _ := ioutil.ReadAll(resp.Body)
err = errors.New(string(body[:]))
}
return v, resp, err
}

// RebaseChange rebases a change.
//
// Optionally, the parent revision can be changed to another patch set through
// the RebaseInput entity.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#rebase-change
func (s *ChangesService) RebaseChange(changeID string, input *RebaseInput) (*ChangeInfo, *Response, error) {
u := fmt.Sprintf("changes/%s/rebase", changeID)

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

v := new(ChangeInfo)

resp, err := s.client.Do(req, v)
if resp.StatusCode == http.StatusConflict {
body, _ := ioutil.ReadAll(resp.Body)
err = errors.New(string(body[:]))
}
return v, resp, err
}

// RestoreChange restores a change.
//
// The request body does not need to include a RestoreInput entity if no review
// comment is added.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#restore-change
func (s *ChangesService) RestoreChange(changeID string, input *RestoreInput) (*ChangeInfo, *Response, error) {
u := fmt.Sprintf("changes/%s/restore", changeID)

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

v := new(ChangeInfo)

resp, err := s.client.Do(req, v)
if resp.StatusCode == http.StatusConflict {
body, _ := ioutil.ReadAll(resp.Body)
err = errors.New(string(body[:]))
}
return v, resp, err
}

// RevertChange reverts a change.
//
// The request body does not need to include a RevertInput entity if no
// review comment is added.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#revert-change
func (s *ChangesService) RevertChange(changeID string, input *RevertInput) (*ChangeInfo, *Response, error) {
u := fmt.Sprintf("changes/%s/revert", changeID)

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

v := new(ChangeInfo)

resp, err := s.client.Do(req, v)
if resp.StatusCode == http.StatusConflict {
body, _ := ioutil.ReadAll(resp.Body)
err = errors.New(string(body[:]))
}
return v, resp, err
}