...

Source file src/github.com/xanzy/go-gitlab/notes.go

Documentation: github.com/xanzy/go-gitlab

     1  //
     2  // Copyright 2021, Sander van Harmelen
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package gitlab
    18  
    19  import (
    20  	"fmt"
    21  	"net/http"
    22  	"time"
    23  )
    24  
    25  // NotesService handles communication with the notes related methods
    26  // of the GitLab API.
    27  //
    28  // GitLab API docs: https://docs.gitlab.com/ee/api/notes.html
    29  type NotesService struct {
    30  	client *Client
    31  }
    32  
    33  // Note represents a GitLab note.
    34  //
    35  // GitLab API docs: https://docs.gitlab.com/ee/api/notes.html
    36  type Note struct {
    37  	ID         int           `json:"id"`
    38  	Type       NoteTypeValue `json:"type"`
    39  	Body       string        `json:"body"`
    40  	Attachment string        `json:"attachment"`
    41  	Title      string        `json:"title"`
    42  	FileName   string        `json:"file_name"`
    43  	Author     struct {
    44  		ID        int    `json:"id"`
    45  		Username  string `json:"username"`
    46  		Email     string `json:"email"`
    47  		Name      string `json:"name"`
    48  		State     string `json:"state"`
    49  		AvatarURL string `json:"avatar_url"`
    50  		WebURL    string `json:"web_url"`
    51  	} `json:"author"`
    52  	System       bool          `json:"system"`
    53  	CreatedAt    *time.Time    `json:"created_at"`
    54  	UpdatedAt    *time.Time    `json:"updated_at"`
    55  	ExpiresAt    *time.Time    `json:"expires_at"`
    56  	CommitID     string        `json:"commit_id"`
    57  	Position     *NotePosition `json:"position"`
    58  	NoteableID   int           `json:"noteable_id"`
    59  	NoteableType string        `json:"noteable_type"`
    60  	ProjectID    int           `json:"project_id"`
    61  	NoteableIID  int           `json:"noteable_iid"`
    62  	Resolvable   bool          `json:"resolvable"`
    63  	Resolved     bool          `json:"resolved"`
    64  	ResolvedAt   *time.Time    `json:"resolved_at"`
    65  	ResolvedBy   struct {
    66  		ID        int    `json:"id"`
    67  		Username  string `json:"username"`
    68  		Email     string `json:"email"`
    69  		Name      string `json:"name"`
    70  		State     string `json:"state"`
    71  		AvatarURL string `json:"avatar_url"`
    72  		WebURL    string `json:"web_url"`
    73  	} `json:"resolved_by"`
    74  	Confidential bool `json:"confidential"`
    75  	Internal     bool `json:"internal"`
    76  }
    77  
    78  // NotePosition represents the position attributes of a note.
    79  type NotePosition struct {
    80  	BaseSHA      string     `json:"base_sha"`
    81  	StartSHA     string     `json:"start_sha"`
    82  	HeadSHA      string     `json:"head_sha"`
    83  	PositionType string     `json:"position_type"`
    84  	NewPath      string     `json:"new_path,omitempty"`
    85  	NewLine      int        `json:"new_line,omitempty"`
    86  	OldPath      string     `json:"old_path,omitempty"`
    87  	OldLine      int        `json:"old_line,omitempty"`
    88  	LineRange    *LineRange `json:"line_range,omitempty"`
    89  }
    90  
    91  // LineRange represents the range of a note.
    92  type LineRange struct {
    93  	StartRange *LinePosition `json:"start"`
    94  	EndRange   *LinePosition `json:"end"`
    95  }
    96  
    97  // LinePosition represents a position in a line range.
    98  type LinePosition struct {
    99  	LineCode string `json:"line_code"`
   100  	Type     string `json:"type"`
   101  	OldLine  int    `json:"old_line"`
   102  	NewLine  int    `json:"new_line"`
   103  }
   104  
   105  func (n Note) String() string {
   106  	return Stringify(n)
   107  }
   108  
   109  // ListIssueNotesOptions represents the available ListIssueNotes() options.
   110  //
   111  // GitLab API docs:
   112  // https://docs.gitlab.com/ee/api/notes.html#list-project-issue-notes
   113  type ListIssueNotesOptions struct {
   114  	ListOptions
   115  	OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
   116  	Sort    *string `url:"sort,omitempty" json:"sort,omitempty"`
   117  }
   118  
   119  // ListIssueNotes gets a list of all notes for a single issue.
   120  //
   121  // GitLab API docs:
   122  // https://docs.gitlab.com/ee/api/notes.html#list-project-issue-notes
   123  func (s *NotesService) ListIssueNotes(pid interface{}, issue int, opt *ListIssueNotesOptions, options ...RequestOptionFunc) ([]*Note, *Response, error) {
   124  	project, err := parseID(pid)
   125  	if err != nil {
   126  		return nil, nil, err
   127  	}
   128  	u := fmt.Sprintf("projects/%s/issues/%d/notes", PathEscape(project), issue)
   129  
   130  	req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
   131  	if err != nil {
   132  		return nil, nil, err
   133  	}
   134  
   135  	var n []*Note
   136  	resp, err := s.client.Do(req, &n)
   137  	if err != nil {
   138  		return nil, resp, err
   139  	}
   140  
   141  	return n, resp, nil
   142  }
   143  
   144  // GetIssueNote returns a single note for a specific project issue.
   145  //
   146  // GitLab API docs:
   147  // https://docs.gitlab.com/ee/api/notes.html#get-single-issue-note
   148  func (s *NotesService) GetIssueNote(pid interface{}, issue, note int, options ...RequestOptionFunc) (*Note, *Response, error) {
   149  	project, err := parseID(pid)
   150  	if err != nil {
   151  		return nil, nil, err
   152  	}
   153  	u := fmt.Sprintf("projects/%s/issues/%d/notes/%d", PathEscape(project), issue, note)
   154  
   155  	req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
   156  	if err != nil {
   157  		return nil, nil, err
   158  	}
   159  
   160  	n := new(Note)
   161  	resp, err := s.client.Do(req, n)
   162  	if err != nil {
   163  		return nil, resp, err
   164  	}
   165  
   166  	return n, resp, nil
   167  }
   168  
   169  // CreateIssueNoteOptions represents the available CreateIssueNote()
   170  // options.
   171  //
   172  // GitLab API docs:
   173  // https://docs.gitlab.com/ee/api/notes.html#create-new-issue-note
   174  type CreateIssueNoteOptions struct {
   175  	Body      *string    `url:"body,omitempty" json:"body,omitempty"`
   176  	CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
   177  }
   178  
   179  // CreateIssueNote creates a new note to a single project issue.
   180  //
   181  // GitLab API docs:
   182  // https://docs.gitlab.com/ee/api/notes.html#create-new-issue-note
   183  func (s *NotesService) CreateIssueNote(pid interface{}, issue int, opt *CreateIssueNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
   184  	project, err := parseID(pid)
   185  	if err != nil {
   186  		return nil, nil, err
   187  	}
   188  	u := fmt.Sprintf("projects/%s/issues/%d/notes", PathEscape(project), issue)
   189  
   190  	req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
   191  	if err != nil {
   192  		return nil, nil, err
   193  	}
   194  
   195  	n := new(Note)
   196  	resp, err := s.client.Do(req, n)
   197  	if err != nil {
   198  		return nil, resp, err
   199  	}
   200  
   201  	return n, resp, nil
   202  }
   203  
   204  // UpdateIssueNoteOptions represents the available UpdateIssueNote()
   205  // options.
   206  //
   207  // GitLab API docs:
   208  // https://docs.gitlab.com/ee/api/notes.html#modify-existing-issue-note
   209  type UpdateIssueNoteOptions struct {
   210  	Body *string `url:"body,omitempty" json:"body,omitempty"`
   211  }
   212  
   213  // UpdateIssueNote modifies existing note of an issue.
   214  //
   215  // GitLab API docs:
   216  // https://docs.gitlab.com/ee/api/notes.html#modify-existing-issue-note
   217  func (s *NotesService) UpdateIssueNote(pid interface{}, issue, note int, opt *UpdateIssueNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
   218  	project, err := parseID(pid)
   219  	if err != nil {
   220  		return nil, nil, err
   221  	}
   222  	u := fmt.Sprintf("projects/%s/issues/%d/notes/%d", PathEscape(project), issue, note)
   223  
   224  	req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
   225  	if err != nil {
   226  		return nil, nil, err
   227  	}
   228  
   229  	n := new(Note)
   230  	resp, err := s.client.Do(req, n)
   231  	if err != nil {
   232  		return nil, resp, err
   233  	}
   234  
   235  	return n, resp, nil
   236  }
   237  
   238  // DeleteIssueNote deletes an existing note of an issue.
   239  //
   240  // GitLab API docs:
   241  // https://docs.gitlab.com/ee/api/notes.html#delete-an-issue-note
   242  func (s *NotesService) DeleteIssueNote(pid interface{}, issue, note int, options ...RequestOptionFunc) (*Response, error) {
   243  	project, err := parseID(pid)
   244  	if err != nil {
   245  		return nil, err
   246  	}
   247  	u := fmt.Sprintf("projects/%s/issues/%d/notes/%d", PathEscape(project), issue, note)
   248  
   249  	req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
   250  	if err != nil {
   251  		return nil, err
   252  	}
   253  
   254  	return s.client.Do(req, nil)
   255  }
   256  
   257  // ListSnippetNotesOptions represents the available ListSnippetNotes() options.
   258  //
   259  // GitLab API docs:
   260  // https://docs.gitlab.com/ee/api/notes.html#list-all-snippet-notes
   261  type ListSnippetNotesOptions struct {
   262  	ListOptions
   263  	OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
   264  	Sort    *string `url:"sort,omitempty" json:"sort,omitempty"`
   265  }
   266  
   267  // ListSnippetNotes gets a list of all notes for a single snippet. Snippet
   268  // notes are comments users can post to a snippet.
   269  //
   270  // GitLab API docs:
   271  // https://docs.gitlab.com/ee/api/notes.html#list-all-snippet-notes
   272  func (s *NotesService) ListSnippetNotes(pid interface{}, snippet int, opt *ListSnippetNotesOptions, options ...RequestOptionFunc) ([]*Note, *Response, error) {
   273  	project, err := parseID(pid)
   274  	if err != nil {
   275  		return nil, nil, err
   276  	}
   277  	u := fmt.Sprintf("projects/%s/snippets/%d/notes", PathEscape(project), snippet)
   278  
   279  	req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
   280  	if err != nil {
   281  		return nil, nil, err
   282  	}
   283  
   284  	var n []*Note
   285  	resp, err := s.client.Do(req, &n)
   286  	if err != nil {
   287  		return nil, resp, err
   288  	}
   289  
   290  	return n, resp, nil
   291  }
   292  
   293  // GetSnippetNote returns a single note for a given snippet.
   294  //
   295  // GitLab API docs:
   296  // https://docs.gitlab.com/ee/api/notes.html#get-single-snippet-note
   297  func (s *NotesService) GetSnippetNote(pid interface{}, snippet, note int, options ...RequestOptionFunc) (*Note, *Response, error) {
   298  	project, err := parseID(pid)
   299  	if err != nil {
   300  		return nil, nil, err
   301  	}
   302  	u := fmt.Sprintf("projects/%s/snippets/%d/notes/%d", PathEscape(project), snippet, note)
   303  
   304  	req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
   305  	if err != nil {
   306  		return nil, nil, err
   307  	}
   308  
   309  	n := new(Note)
   310  	resp, err := s.client.Do(req, n)
   311  	if err != nil {
   312  		return nil, resp, err
   313  	}
   314  
   315  	return n, resp, nil
   316  }
   317  
   318  // CreateSnippetNoteOptions represents the available CreateSnippetNote()
   319  // options.
   320  //
   321  // GitLab API docs:
   322  // https://docs.gitlab.com/ee/api/notes.html#create-new-snippet-note
   323  type CreateSnippetNoteOptions struct {
   324  	Body *string `url:"body,omitempty" json:"body,omitempty"`
   325  }
   326  
   327  // CreateSnippetNote creates a new note for a single snippet. Snippet notes are
   328  // comments users can post to a snippet.
   329  //
   330  // GitLab API docs:
   331  // https://docs.gitlab.com/ee/api/notes.html#create-new-snippet-note
   332  func (s *NotesService) CreateSnippetNote(pid interface{}, snippet int, opt *CreateSnippetNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
   333  	project, err := parseID(pid)
   334  	if err != nil {
   335  		return nil, nil, err
   336  	}
   337  	u := fmt.Sprintf("projects/%s/snippets/%d/notes", PathEscape(project), snippet)
   338  
   339  	req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
   340  	if err != nil {
   341  		return nil, nil, err
   342  	}
   343  
   344  	n := new(Note)
   345  	resp, err := s.client.Do(req, n)
   346  	if err != nil {
   347  		return nil, resp, err
   348  	}
   349  
   350  	return n, resp, nil
   351  }
   352  
   353  // UpdateSnippetNoteOptions represents the available UpdateSnippetNote()
   354  // options.
   355  //
   356  // GitLab API docs:
   357  // https://docs.gitlab.com/ee/api/notes.html#modify-existing-snippet-note
   358  type UpdateSnippetNoteOptions struct {
   359  	Body *string `url:"body,omitempty" json:"body,omitempty"`
   360  }
   361  
   362  // UpdateSnippetNote modifies existing note of a snippet.
   363  //
   364  // GitLab API docs:
   365  // https://docs.gitlab.com/ee/api/notes.html#modify-existing-snippet-note
   366  func (s *NotesService) UpdateSnippetNote(pid interface{}, snippet, note int, opt *UpdateSnippetNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
   367  	project, err := parseID(pid)
   368  	if err != nil {
   369  		return nil, nil, err
   370  	}
   371  	u := fmt.Sprintf("projects/%s/snippets/%d/notes/%d", PathEscape(project), snippet, note)
   372  
   373  	req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
   374  	if err != nil {
   375  		return nil, nil, err
   376  	}
   377  
   378  	n := new(Note)
   379  	resp, err := s.client.Do(req, n)
   380  	if err != nil {
   381  		return nil, resp, err
   382  	}
   383  
   384  	return n, resp, nil
   385  }
   386  
   387  // DeleteSnippetNote deletes an existing note of a snippet.
   388  //
   389  // GitLab API docs:
   390  // https://docs.gitlab.com/ee/api/notes.html#delete-a-snippet-note
   391  func (s *NotesService) DeleteSnippetNote(pid interface{}, snippet, note int, options ...RequestOptionFunc) (*Response, error) {
   392  	project, err := parseID(pid)
   393  	if err != nil {
   394  		return nil, err
   395  	}
   396  	u := fmt.Sprintf("projects/%s/snippets/%d/notes/%d", PathEscape(project), snippet, note)
   397  
   398  	req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
   399  	if err != nil {
   400  		return nil, err
   401  	}
   402  
   403  	return s.client.Do(req, nil)
   404  }
   405  
   406  // ListMergeRequestNotesOptions represents the available ListMergeRequestNotes()
   407  // options.
   408  //
   409  // GitLab API docs:
   410  // https://docs.gitlab.com/ee/api/notes.html#list-all-merge-request-notes
   411  type ListMergeRequestNotesOptions struct {
   412  	ListOptions
   413  	OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
   414  	Sort    *string `url:"sort,omitempty" json:"sort,omitempty"`
   415  }
   416  
   417  // ListMergeRequestNotes gets a list of all notes for a single merge request.
   418  //
   419  // GitLab API docs:
   420  // https://docs.gitlab.com/ee/api/notes.html#list-all-merge-request-notes
   421  func (s *NotesService) ListMergeRequestNotes(pid interface{}, mergeRequest int, opt *ListMergeRequestNotesOptions, options ...RequestOptionFunc) ([]*Note, *Response, error) {
   422  	project, err := parseID(pid)
   423  	if err != nil {
   424  		return nil, nil, err
   425  	}
   426  	u := fmt.Sprintf("projects/%s/merge_requests/%d/notes", PathEscape(project), mergeRequest)
   427  
   428  	req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
   429  	if err != nil {
   430  		return nil, nil, err
   431  	}
   432  
   433  	var n []*Note
   434  	resp, err := s.client.Do(req, &n)
   435  	if err != nil {
   436  		return nil, resp, err
   437  	}
   438  
   439  	return n, resp, nil
   440  }
   441  
   442  // GetMergeRequestNote returns a single note for a given merge request.
   443  //
   444  // GitLab API docs:
   445  // https://docs.gitlab.com/ee/api/notes.html#get-single-merge-request-note
   446  func (s *NotesService) GetMergeRequestNote(pid interface{}, mergeRequest, note int, options ...RequestOptionFunc) (*Note, *Response, error) {
   447  	project, err := parseID(pid)
   448  	if err != nil {
   449  		return nil, nil, err
   450  	}
   451  	u := fmt.Sprintf("projects/%s/merge_requests/%d/notes/%d", PathEscape(project), mergeRequest, note)
   452  
   453  	req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
   454  	if err != nil {
   455  		return nil, nil, err
   456  	}
   457  
   458  	n := new(Note)
   459  	resp, err := s.client.Do(req, n)
   460  	if err != nil {
   461  		return nil, resp, err
   462  	}
   463  
   464  	return n, resp, nil
   465  }
   466  
   467  // CreateMergeRequestNoteOptions represents the available
   468  // CreateMergeRequestNote() options.
   469  //
   470  // GitLab API docs:
   471  // https://docs.gitlab.com/ee/api/notes.html#create-new-merge-request-note
   472  type CreateMergeRequestNoteOptions struct {
   473  	Body *string `url:"body,omitempty" json:"body,omitempty"`
   474  }
   475  
   476  // CreateMergeRequestNote creates a new note for a single merge request.
   477  //
   478  // GitLab API docs:
   479  // https://docs.gitlab.com/ee/api/notes.html#create-new-merge-request-note
   480  func (s *NotesService) CreateMergeRequestNote(pid interface{}, mergeRequest int, opt *CreateMergeRequestNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
   481  	project, err := parseID(pid)
   482  	if err != nil {
   483  		return nil, nil, err
   484  	}
   485  	u := fmt.Sprintf("projects/%s/merge_requests/%d/notes", PathEscape(project), mergeRequest)
   486  
   487  	req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
   488  	if err != nil {
   489  		return nil, nil, err
   490  	}
   491  
   492  	n := new(Note)
   493  	resp, err := s.client.Do(req, n)
   494  	if err != nil {
   495  		return nil, resp, err
   496  	}
   497  
   498  	return n, resp, nil
   499  }
   500  
   501  // UpdateMergeRequestNoteOptions represents the available
   502  // UpdateMergeRequestNote() options.
   503  //
   504  // GitLab API docs:
   505  // https://docs.gitlab.com/ee/api/notes.html#modify-existing-merge-request-note
   506  type UpdateMergeRequestNoteOptions struct {
   507  	Body *string `url:"body,omitempty" json:"body,omitempty"`
   508  }
   509  
   510  // UpdateMergeRequestNote modifies existing note of a merge request.
   511  //
   512  // GitLab API docs:
   513  // https://docs.gitlab.com/ee/api/notes.html#modify-existing-merge-request-note
   514  func (s *NotesService) UpdateMergeRequestNote(pid interface{}, mergeRequest, note int, opt *UpdateMergeRequestNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
   515  	project, err := parseID(pid)
   516  	if err != nil {
   517  		return nil, nil, err
   518  	}
   519  	u := fmt.Sprintf(
   520  		"projects/%s/merge_requests/%d/notes/%d", PathEscape(project), mergeRequest, note)
   521  	req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
   522  	if err != nil {
   523  		return nil, nil, err
   524  	}
   525  
   526  	n := new(Note)
   527  	resp, err := s.client.Do(req, n)
   528  	if err != nil {
   529  		return nil, resp, err
   530  	}
   531  
   532  	return n, resp, nil
   533  }
   534  
   535  // DeleteMergeRequestNote deletes an existing note of a merge request.
   536  //
   537  // GitLab API docs:
   538  // https://docs.gitlab.com/ee/api/notes.html#delete-a-merge-request-note
   539  func (s *NotesService) DeleteMergeRequestNote(pid interface{}, mergeRequest, note int, options ...RequestOptionFunc) (*Response, error) {
   540  	project, err := parseID(pid)
   541  	if err != nil {
   542  		return nil, err
   543  	}
   544  	u := fmt.Sprintf(
   545  		"projects/%s/merge_requests/%d/notes/%d", PathEscape(project), mergeRequest, note)
   546  
   547  	req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
   548  	if err != nil {
   549  		return nil, err
   550  	}
   551  
   552  	return s.client.Do(req, nil)
   553  }
   554  
   555  // ListEpicNotesOptions represents the available ListEpicNotes() options.
   556  //
   557  // GitLab API docs:
   558  // https://docs.gitlab.com/ee/api/notes.html#list-all-epic-notes
   559  type ListEpicNotesOptions struct {
   560  	ListOptions
   561  	OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
   562  	Sort    *string `url:"sort,omitempty" json:"sort,omitempty"`
   563  }
   564  
   565  // ListEpicNotes gets a list of all notes for a single epic.
   566  //
   567  // GitLab API docs:
   568  // https://docs.gitlab.com/ee/api/notes.html#list-all-epic-notes
   569  func (s *NotesService) ListEpicNotes(gid interface{}, epic int, opt *ListEpicNotesOptions, options ...RequestOptionFunc) ([]*Note, *Response, error) {
   570  	group, err := parseID(gid)
   571  	if err != nil {
   572  		return nil, nil, err
   573  	}
   574  	u := fmt.Sprintf("groups/%s/epics/%d/notes", PathEscape(group), epic)
   575  
   576  	req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
   577  	if err != nil {
   578  		return nil, nil, err
   579  	}
   580  
   581  	var n []*Note
   582  	resp, err := s.client.Do(req, &n)
   583  	if err != nil {
   584  		return nil, resp, err
   585  	}
   586  
   587  	return n, resp, nil
   588  }
   589  
   590  // GetEpicNote returns a single note for an epic.
   591  //
   592  // GitLab API docs:
   593  // https://docs.gitlab.com/ee/api/notes.html#get-single-epic-note
   594  func (s *NotesService) GetEpicNote(gid interface{}, epic, note int, options ...RequestOptionFunc) (*Note, *Response, error) {
   595  	group, err := parseID(gid)
   596  	if err != nil {
   597  		return nil, nil, err
   598  	}
   599  	u := fmt.Sprintf("groups/%s/epics/%d/notes/%d", PathEscape(group), epic, note)
   600  
   601  	req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
   602  	if err != nil {
   603  		return nil, nil, err
   604  	}
   605  
   606  	n := new(Note)
   607  	resp, err := s.client.Do(req, n)
   608  	if err != nil {
   609  		return nil, resp, err
   610  	}
   611  
   612  	return n, resp, nil
   613  }
   614  
   615  // CreateEpicNoteOptions represents the available CreateEpicNote() options.
   616  //
   617  // GitLab API docs:
   618  // https://docs.gitlab.com/ee/api/notes.html#create-new-epic-note
   619  type CreateEpicNoteOptions struct {
   620  	Body *string `url:"body,omitempty" json:"body,omitempty"`
   621  }
   622  
   623  // CreateEpicNote creates a new note for a single merge request.
   624  //
   625  // GitLab API docs:
   626  // https://docs.gitlab.com/ee/api/notes.html#create-new-epic-note
   627  func (s *NotesService) CreateEpicNote(gid interface{}, epic int, opt *CreateEpicNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
   628  	group, err := parseID(gid)
   629  	if err != nil {
   630  		return nil, nil, err
   631  	}
   632  	u := fmt.Sprintf("groups/%s/epics/%d/notes", PathEscape(group), epic)
   633  
   634  	req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
   635  	if err != nil {
   636  		return nil, nil, err
   637  	}
   638  
   639  	n := new(Note)
   640  	resp, err := s.client.Do(req, n)
   641  	if err != nil {
   642  		return nil, resp, err
   643  	}
   644  
   645  	return n, resp, nil
   646  }
   647  
   648  // UpdateEpicNoteOptions represents the available UpdateEpicNote() options.
   649  //
   650  // GitLab API docs:
   651  // https://docs.gitlab.com/ee/api/notes.html#modify-existing-epic-note
   652  type UpdateEpicNoteOptions struct {
   653  	Body *string `url:"body,omitempty" json:"body,omitempty"`
   654  }
   655  
   656  // UpdateEpicNote modifies existing note of an epic.
   657  //
   658  // https://docs.gitlab.com/ee/api/notes.html#modify-existing-epic-note
   659  func (s *NotesService) UpdateEpicNote(gid interface{}, epic, note int, opt *UpdateEpicNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
   660  	group, err := parseID(gid)
   661  	if err != nil {
   662  		return nil, nil, err
   663  	}
   664  	u := fmt.Sprintf("groups/%s/epics/%d/notes/%d", PathEscape(group), epic, note)
   665  
   666  	req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
   667  	if err != nil {
   668  		return nil, nil, err
   669  	}
   670  
   671  	n := new(Note)
   672  	resp, err := s.client.Do(req, n)
   673  	if err != nil {
   674  		return nil, resp, err
   675  	}
   676  
   677  	return n, resp, nil
   678  }
   679  
   680  // DeleteEpicNote deletes an existing note of a merge request.
   681  //
   682  // https://docs.gitlab.com/ee/api/notes.html#delete-an-epic-note
   683  func (s *NotesService) DeleteEpicNote(gid interface{}, epic, note int, options ...RequestOptionFunc) (*Response, error) {
   684  	group, err := parseID(gid)
   685  	if err != nil {
   686  		return nil, err
   687  	}
   688  	u := fmt.Sprintf("groups/%s/epics/%d/notes/%d", PathEscape(group), epic, note)
   689  
   690  	req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
   691  	if err != nil {
   692  		return nil, err
   693  	}
   694  
   695  	return s.client.Do(req, nil)
   696  }
   697  

View as plain text