issues_assignees.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2013 The go-github AUTHORS. All rights reserved.
  2. //
  3. // Use of this source code is governed by a BSD-style
  4. // license that can be found in the LICENSE file.
  5. package github
  6. import (
  7. "context"
  8. "fmt"
  9. )
  10. // ListAssignees fetches all available assignees (owners and collaborators) to
  11. // which issues may be assigned.
  12. //
  13. // GitHub API docs: https://developer.github.com/v3/issues/assignees/#list-assignees
  14. func (s *IssuesService) ListAssignees(ctx context.Context, owner, repo string, opt *ListOptions) ([]*User, *Response, error) {
  15. u := fmt.Sprintf("repos/%v/%v/assignees", owner, repo)
  16. u, err := addOptions(u, opt)
  17. if err != nil {
  18. return nil, nil, err
  19. }
  20. req, err := s.client.NewRequest("GET", u, nil)
  21. if err != nil {
  22. return nil, nil, err
  23. }
  24. var assignees []*User
  25. resp, err := s.client.Do(ctx, req, &assignees)
  26. if err != nil {
  27. return nil, resp, err
  28. }
  29. return assignees, resp, nil
  30. }
  31. // IsAssignee checks if a user is an assignee for the specified repository.
  32. //
  33. // GitHub API docs: https://developer.github.com/v3/issues/assignees/#check-assignee
  34. func (s *IssuesService) IsAssignee(ctx context.Context, owner, repo, user string) (bool, *Response, error) {
  35. u := fmt.Sprintf("repos/%v/%v/assignees/%v", owner, repo, user)
  36. req, err := s.client.NewRequest("GET", u, nil)
  37. if err != nil {
  38. return false, nil, err
  39. }
  40. resp, err := s.client.Do(ctx, req, nil)
  41. assignee, err := parseBoolResponse(err)
  42. return assignee, resp, err
  43. }
  44. // AddAssignees adds the provided GitHub users as assignees to the issue.
  45. //
  46. // GitHub API docs: https://developer.github.com/v3/issues/assignees/#add-assignees-to-an-issue
  47. func (s *IssuesService) AddAssignees(ctx context.Context, owner, repo string, number int, assignees []string) (*Issue, *Response, error) {
  48. users := &struct {
  49. Assignees []string `json:"assignees,omitempty"`
  50. }{Assignees: assignees}
  51. u := fmt.Sprintf("repos/%v/%v/issues/%v/assignees", owner, repo, number)
  52. req, err := s.client.NewRequest("POST", u, users)
  53. if err != nil {
  54. return nil, nil, err
  55. }
  56. issue := &Issue{}
  57. resp, err := s.client.Do(ctx, req, issue)
  58. return issue, resp, err
  59. }
  60. // RemoveAssignees removes the provided GitHub users as assignees from the issue.
  61. //
  62. // GitHub API docs: https://developer.github.com/v3/issues/assignees/#remove-assignees-from-an-issue
  63. func (s *IssuesService) RemoveAssignees(ctx context.Context, owner, repo string, number int, assignees []string) (*Issue, *Response, error) {
  64. users := &struct {
  65. Assignees []string `json:"assignees,omitempty"`
  66. }{Assignees: assignees}
  67. u := fmt.Sprintf("repos/%v/%v/issues/%v/assignees", owner, repo, number)
  68. req, err := s.client.NewRequest("DELETE", u, users)
  69. if err != nil {
  70. return nil, nil, err
  71. }
  72. issue := &Issue{}
  73. resp, err := s.client.Do(ctx, req, issue)
  74. return issue, resp, err
  75. }