mirror of https://gitlab.com/gitlab-org/cli.git
138 lines
3.4 KiB
Go
138 lines
3.4 KiB
Go
// This is a silly wrapper for go-gitlab but helps maintain consistency
|
|
package api
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/xanzy/go-gitlab"
|
|
)
|
|
|
|
var ListIssueNotes = func(client *gitlab.Client, projectID interface{}, issueID int, opts *gitlab.ListIssueNotesOptions) ([]*gitlab.Note, error) {
|
|
if client == nil {
|
|
client = apiClient.Lab()
|
|
}
|
|
if opts.PerPage == 0 {
|
|
opts.PerPage = DefaultListLimit
|
|
}
|
|
notes, _, err := client.Notes.ListIssueNotes(projectID, issueID, opts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return notes, nil
|
|
}
|
|
|
|
var UpdateIssue = func(client *gitlab.Client, projectID interface{}, issueID int, opts *gitlab.UpdateIssueOptions) (*gitlab.Issue, error) {
|
|
if client == nil {
|
|
client = apiClient.Lab()
|
|
}
|
|
issue, _, err := client.Issues.UpdateIssue(projectID, issueID, opts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return issue, nil
|
|
}
|
|
|
|
var GetIssue = func(client *gitlab.Client, projectID interface{}, issueID int) (*gitlab.Issue, error) {
|
|
if client == nil {
|
|
client = apiClient.Lab()
|
|
}
|
|
issue, _, err := client.Issues.GetIssue(projectID, issueID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return issue, nil
|
|
}
|
|
|
|
var ListIssues = func(client *gitlab.Client, projectID interface{}, opts *gitlab.ListProjectIssuesOptions) ([]*gitlab.Issue, error) {
|
|
if client == nil {
|
|
client = apiClient.Lab()
|
|
}
|
|
if opts.PerPage == 0 {
|
|
opts.PerPage = DefaultListLimit
|
|
}
|
|
issues, _, err := client.Issues.ListProjectIssues(projectID, opts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return issues, nil
|
|
}
|
|
|
|
var CreateIssue = func(client *gitlab.Client, projectID interface{}, opts *gitlab.CreateIssueOptions) (*gitlab.Issue, error) {
|
|
if client == nil {
|
|
client = apiClient.Lab()
|
|
}
|
|
issue, _, err := client.Issues.CreateIssue(projectID, opts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return issue, nil
|
|
}
|
|
|
|
var DeleteIssue = func(client *gitlab.Client, projectID interface{}, issueID int) error {
|
|
if client == nil {
|
|
client = apiClient.Lab()
|
|
}
|
|
|
|
_, err := client.Issues.DeleteIssue(projectID, issueID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
var CreateIssueNote = func(client *gitlab.Client, projectID interface{}, mrID int, opts *gitlab.CreateIssueNoteOptions) (*gitlab.Note, error) {
|
|
if client == nil {
|
|
client = apiClient.Lab()
|
|
}
|
|
|
|
note, _, err := client.Notes.CreateIssueNote(projectID, mrID, opts)
|
|
if err != nil {
|
|
return note, err
|
|
}
|
|
|
|
return note, nil
|
|
}
|
|
|
|
var SubscribeToIssue = func(client *gitlab.Client, projectID interface{}, issueID int, opts gitlab.RequestOptionFunc) (*gitlab.Issue, error) {
|
|
if client == nil {
|
|
client = apiClient.Lab()
|
|
}
|
|
|
|
issue, resp, err := client.Issues.SubscribeToIssue(projectID, issueID, opts)
|
|
if err != nil {
|
|
if resp != nil {
|
|
// If the user is already subscribed to the issue, the status code 304 is returned.
|
|
if resp.StatusCode == 304 {
|
|
return nil, errors.New("you are already subscribed to this issue")
|
|
}
|
|
}
|
|
return issue, err
|
|
}
|
|
|
|
return issue, nil
|
|
}
|
|
|
|
var UnsubscribeFromIssue = func(client *gitlab.Client, projectID interface{}, issueID int, opts gitlab.RequestOptionFunc) (*gitlab.Issue, error) {
|
|
if client == nil {
|
|
client = apiClient.Lab()
|
|
}
|
|
|
|
issue, resp, err := client.Issues.UnsubscribeFromIssue(projectID, issueID, opts)
|
|
if err != nil {
|
|
if resp != nil {
|
|
// If the user is not subscribed to the issue, the status code 304 is returned.
|
|
if resp.StatusCode == 304 {
|
|
return nil, errors.New("you are not subscribed to this issue")
|
|
}
|
|
}
|
|
return issue, err
|
|
}
|
|
|
|
return issue, nil
|
|
}
|