...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package gitlab
18
19 import (
20 "fmt"
21 "net/http"
22 "time"
23 )
24
25
26
27
28
29 type TodosService struct {
30 client *Client
31 }
32
33
34
35
36 type Todo struct {
37 ID int `json:"id"`
38 Project *BasicProject `json:"project"`
39 Author *BasicUser `json:"author"`
40 ActionName TodoAction `json:"action_name"`
41 TargetType TodoTargetType `json:"target_type"`
42 Target *TodoTarget `json:"target"`
43 TargetURL string `json:"target_url"`
44 Body string `json:"body"`
45 State string `json:"state"`
46 CreatedAt *time.Time `json:"created_at"`
47 }
48
49 func (t Todo) String() string {
50 return Stringify(t)
51 }
52
53
54 type TodoTarget struct {
55 Assignees []*BasicUser `json:"assignees"`
56 Assignee *BasicUser `json:"assignee"`
57 Author *BasicUser `json:"author"`
58 CreatedAt *time.Time `json:"created_at"`
59 Description string `json:"description"`
60 Downvotes int `json:"downvotes"`
61 ID interface{} `json:"id"`
62 IID int `json:"iid"`
63 Labels []string `json:"labels"`
64 Milestone *Milestone `json:"milestone"`
65 ProjectID int `json:"project_id"`
66 State string `json:"state"`
67 Subscribed bool `json:"subscribed"`
68 TaskCompletionStatus *TasksCompletionStatus `json:"task_completion_status"`
69 Title string `json:"title"`
70 UpdatedAt *time.Time `json:"updated_at"`
71 Upvotes int `json:"upvotes"`
72 UserNotesCount int `json:"user_notes_count"`
73 WebURL string `json:"web_url"`
74
75
76 Confidential bool `json:"confidential"`
77 DueDate string `json:"due_date"`
78 HasTasks bool `json:"has_tasks"`
79 Links *IssueLinks `json:"_links"`
80 MovedToID int `json:"moved_to_id"`
81 TimeStats *TimeStats `json:"time_stats"`
82 Weight int `json:"weight"`
83
84
85 ApprovalsBeforeMerge int `json:"approvals_before_merge"`
86 ForceRemoveSourceBranch bool `json:"force_remove_source_branch"`
87 MergeCommitSHA string `json:"merge_commit_sha"`
88 MergeWhenPipelineSucceeds bool `json:"merge_when_pipeline_succeeds"`
89 MergeStatus string `json:"merge_status"`
90 Reference string `json:"reference"`
91 Reviewers []*BasicUser `json:"reviewers"`
92 SHA string `json:"sha"`
93 ShouldRemoveSourceBranch bool `json:"should_remove_source_branch"`
94 SourceBranch string `json:"source_branch"`
95 SourceProjectID int `json:"source_project_id"`
96 Squash bool `json:"squash"`
97 TargetBranch string `json:"target_branch"`
98 TargetProjectID int `json:"target_project_id"`
99 WorkInProgress bool `json:"work_in_progress"`
100
101
102 FileName string `json:"filename"`
103 ImageURL string `json:"image_url"`
104 }
105
106
107
108
109 type ListTodosOptions struct {
110 ListOptions
111 Action *TodoAction `url:"action,omitempty" json:"action,omitempty"`
112 AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"`
113 ProjectID *int `url:"project_id,omitempty" json:"project_id,omitempty"`
114 State *string `url:"state,omitempty" json:"state,omitempty"`
115 Type *string `url:"type,omitempty" json:"type,omitempty"`
116 }
117
118
119
120
121
122
123 func (s *TodosService) ListTodos(opt *ListTodosOptions, options ...RequestOptionFunc) ([]*Todo, *Response, error) {
124 req, err := s.client.NewRequest(http.MethodGet, "todos", opt, options)
125 if err != nil {
126 return nil, nil, err
127 }
128
129 var t []*Todo
130 resp, err := s.client.Do(req, &t)
131 if err != nil {
132 return nil, resp, err
133 }
134
135 return t, resp, nil
136 }
137
138
139
140
141 func (s *TodosService) MarkTodoAsDone(id int, options ...RequestOptionFunc) (*Response, error) {
142 u := fmt.Sprintf("todos/%d/mark_as_done", id)
143
144 req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
145 if err != nil {
146 return nil, err
147 }
148
149 return s.client.Do(req, nil)
150 }
151
152
153
154
155 func (s *TodosService) MarkAllTodosAsDone(options ...RequestOptionFunc) (*Response, error) {
156 req, err := s.client.NewRequest(http.MethodPost, "todos/mark_as_done", nil, options)
157 if err != nil {
158 return nil, err
159 }
160
161 return s.client.Do(req, nil)
162 }
163
View as plain text