Browse Source

go-github: add support for issue locking / unlocking

Fixes #279.

Change-Id: I55ffdadfe5970d664ac94048e8bc2b8f5d935903
Glenn Lewis 10 years ago
committed by Will Norris
parent
commit
ac77c93f2b
3 changed files with 67 additions and 0 deletions
  1. +3
    -0
      github/github.go
  2. +32
    -0
      github/issues.go
  3. +32
    -0
      github/issues_test.go

+ 3
- 0
github/github.go View File

@ -56,6 +56,9 @@ const (
// https://developer.github.com/changes/2015-11-11-protected-branches-api/
mediaTypeProtectedBranchesPreview = "application/vnd.github.loki-preview+json"
// https://developer.github.com/changes/2016-02-11-issue-locking-api/
mediaTypeIssueLockingPreview = "application/vnd.github.the-key-preview+json"
)
// A Client manages communication with the GitHub API.


+ 32
- 0
github/issues.go View File

@ -260,3 +260,35 @@ func (s *IssuesService) Edit(owner string, repo string, number int, issue *Issue
return i, resp, err
}
// Lock an issue's conversation.
//
// GitHub API docs: https://developer.github.com/v3/issues/#lock-an-issue
func (s *IssuesService) Lock(owner string, repo string, number int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/lock", owner, repo, number)
req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, err
}
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeIssueLockingPreview)
return s.client.Do(req, nil)
}
// Unlock an issue's conversation.
//
// GitHub API docs: https://developer.github.com/v3/issues/#unlock-an-issue
func (s *IssuesService) Unlock(owner string, repo string, number int) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/issues/%d/lock", owner, repo, number)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeIssueLockingPreview)
return s.client.Do(req, nil)
}

+ 32
- 0
github/issues_test.go View File

@ -240,3 +240,35 @@ func TestIssuesService_Edit_invalidOwner(t *testing.T) {
_, _, err := client.Issues.Edit("%", "r", 1, nil)
testURLParseError(t, err)
}
func TestIssuesService_Lock(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/issues/1/lock", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testHeader(t, r, "Accept", mediaTypeIssueLockingPreview)
w.WriteHeader(http.StatusNoContent)
})
if _, err := client.Issues.Lock("o", "r", 1); err != nil {
t.Errorf("Issues.Lock returned error: %v", err)
}
}
func TestIssuesService_Unlock(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/issues/1/lock", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
testHeader(t, r, "Accept", mediaTypeIssueLockingPreview)
w.WriteHeader(http.StatusNoContent)
})
if _, err := client.Issues.Unlock("o", "r", 1); err != nil {
t.Errorf("Issues.Unlock returned error: %v", err)
}
}

Loading…
Cancel
Save