本站源代码
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

161 lines
5.6KB

  1. // Copyright 2018 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. // TeamDiscussion represents a GitHub dicussion in a team.
  11. type TeamDiscussion struct {
  12. Author *User `json:"author,omitempty"`
  13. Body *string `json:"body,omitempty"`
  14. BodyHTML *string `json:"body_html,omitempty"`
  15. BodyVersion *string `json:"body_version,omitempty"`
  16. CommentsCount *int `json:"comments_count,omitempty"`
  17. CommentsURL *string `json:"comments_url,omitempty"`
  18. CreatedAt *Timestamp `json:"created_at,omitempty"`
  19. LastEditedAt *Timestamp `json:"last_edited_at,omitempty"`
  20. HTMLURL *string `json:"html_url,omitempty"`
  21. NodeID *string `json:"node_id,omitempty"`
  22. Number *int `json:"number,omitempty"`
  23. Pinned *bool `json:"pinned,omitempty"`
  24. Private *bool `json:"private,omitempty"`
  25. TeamURL *string `json:"team_url,omitempty"`
  26. Title *string `json:"title,omitempty"`
  27. UpdatedAt *Timestamp `json:"updated_at,omitempty"`
  28. URL *string `json:"url,omitempty"`
  29. Reactions *Reactions `json:"reactions,omitempty"`
  30. }
  31. func (d TeamDiscussion) String() string {
  32. return Stringify(d)
  33. }
  34. // DiscussionListOptions specifies optional parameters to the
  35. // TeamServices.ListDiscussions method.
  36. type DiscussionListOptions struct {
  37. // Sorts the discussion by the date they were created.
  38. // Accepted values are asc and desc. Default is desc.
  39. Direction string `url:"direction,omitempty"`
  40. }
  41. // ListDiscussions lists all discussions on team's page.
  42. // Authenticated user must grant read:discussion scope.
  43. //
  44. // GitHub API docs: https://developer.github.com/v3/teams/discussions/#list-discussions
  45. func (s *TeamsService) ListDiscussions(ctx context.Context, teamID int64, options *DiscussionListOptions) ([]*TeamDiscussion, *Response, error) {
  46. u := fmt.Sprintf("teams/%v/discussions", teamID)
  47. u, err := addOptions(u, options)
  48. if err != nil {
  49. return nil, nil, err
  50. }
  51. req, err := s.client.NewRequest("GET", u, nil)
  52. if err != nil {
  53. return nil, nil, err
  54. }
  55. // TODO: remove custom Accept header when this API fully launches.
  56. req.Header.Set("Accept", mediaTypeTeamDiscussionsPreview)
  57. var teamDiscussions []*TeamDiscussion
  58. resp, err := s.client.Do(ctx, req, &teamDiscussions)
  59. if err != nil {
  60. return nil, resp, err
  61. }
  62. return teamDiscussions, resp, nil
  63. }
  64. // GetDiscussion gets a specific discussion on a team's page.
  65. // Authenticated user must grant read:discussion scope.
  66. //
  67. // GitHub API docs: https://developer.github.com/v3/teams/discussions/#get-a-single-discussion
  68. func (s *TeamsService) GetDiscussion(ctx context.Context, teamID int64, discussionNumber int) (*TeamDiscussion, *Response, error) {
  69. u := fmt.Sprintf("teams/%v/discussions/%v", teamID, discussionNumber)
  70. req, err := s.client.NewRequest("GET", u, nil)
  71. if err != nil {
  72. return nil, nil, err
  73. }
  74. // TODO: remove custom Accept header when this API fully launches.
  75. req.Header.Set("Accept", mediaTypeTeamDiscussionsPreview)
  76. teamDiscussion := &TeamDiscussion{}
  77. resp, err := s.client.Do(ctx, req, teamDiscussion)
  78. if err != nil {
  79. return nil, resp, err
  80. }
  81. return teamDiscussion, resp, nil
  82. }
  83. // CreateDiscussion creates a new discussion post on a team's page.
  84. // Authenticated user must grant write:discussion scope.
  85. //
  86. // GitHub API docs: https://developer.github.com/v3/teams/discussions/#create-a-discussion
  87. func (s *TeamsService) CreateDiscussion(ctx context.Context, teamID int64, discussion TeamDiscussion) (*TeamDiscussion, *Response, error) {
  88. u := fmt.Sprintf("teams/%v/discussions", teamID)
  89. req, err := s.client.NewRequest("POST", u, discussion)
  90. if err != nil {
  91. return nil, nil, err
  92. }
  93. // TODO: remove custom Accept header when this API fully launches.
  94. req.Header.Set("Accept", mediaTypeTeamDiscussionsPreview)
  95. teamDiscussion := &TeamDiscussion{}
  96. resp, err := s.client.Do(ctx, req, teamDiscussion)
  97. if err != nil {
  98. return nil, resp, err
  99. }
  100. return teamDiscussion, resp, nil
  101. }
  102. // EditDiscussion edits the title and body text of a discussion post.
  103. // Authenticated user must grant write:discussion scope.
  104. // User is allowed to change Title and Body of a discussion only.
  105. //
  106. // GitHub API docs: https://developer.github.com/v3/teams/discussions/#edit-a-discussion
  107. func (s *TeamsService) EditDiscussion(ctx context.Context, teamID int64, discussionNumber int, discussion TeamDiscussion) (*TeamDiscussion, *Response, error) {
  108. u := fmt.Sprintf("teams/%v/discussions/%v", teamID, discussionNumber)
  109. req, err := s.client.NewRequest("PATCH", u, discussion)
  110. if err != nil {
  111. return nil, nil, err
  112. }
  113. // TODO: remove custom Accept header when this API fully launches.
  114. req.Header.Set("Accept", mediaTypeTeamDiscussionsPreview)
  115. teamDiscussion := &TeamDiscussion{}
  116. resp, err := s.client.Do(ctx, req, teamDiscussion)
  117. if err != nil {
  118. return nil, resp, err
  119. }
  120. return teamDiscussion, resp, nil
  121. }
  122. // DeleteDiscussion deletes a discussion from team's page.
  123. // Authenticated user must grant write:discussion scope.
  124. //
  125. // GitHub API docs: https://developer.github.com/v3/teams/discussions/#delete-a-discussion
  126. func (s *TeamsService) DeleteDiscussion(ctx context.Context, teamID int64, discussionNumber int) (*Response, error) {
  127. u := fmt.Sprintf("teams/%v/discussions/%v", teamID, discussionNumber)
  128. req, err := s.client.NewRequest("DELETE", u, nil)
  129. if err != nil {
  130. return nil, err
  131. }
  132. // TODO: remove custom Accept header when this API fully launches.
  133. req.Header.Set("Accept", mediaTypeTeamDiscussionsPreview)
  134. return s.client.Do(ctx, req, nil)
  135. }
上海开阖软件有限公司 沪ICP备12045867号-1