mirror of https://gitlab.com/gitlab-org/cli.git
feat(api): Add api wrappers for creating snippets
This adds two simple API wrappers for creating snippets for the user and inside the project. This should help us start work with creating a snippets command. Issue #872
This commit is contained in:
parent
93ff2e4c07
commit
5429bb7f9d
|
@ -0,0 +1,37 @@
|
|||
package api
|
||||
|
||||
import "github.com/xanzy/go-gitlab"
|
||||
|
||||
// CreateSnippet for the user inside the users snippets
|
||||
var CreateSnippet = func(
|
||||
client *gitlab.Client,
|
||||
projectID interface{},
|
||||
opts *gitlab.CreateSnippetOptions,
|
||||
) (*gitlab.Snippet, error) {
|
||||
if client == nil {
|
||||
client = apiClient.Lab()
|
||||
}
|
||||
|
||||
snipet, _, err := client.Snippets.CreateSnippet(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return snipet, err
|
||||
}
|
||||
|
||||
// CreateProjectSnippet inside the project
|
||||
var CreateProjectSnippet = func(
|
||||
client *gitlab.Client,
|
||||
projectID interface{},
|
||||
opts *gitlab.CreateProjectSnippetOptions,
|
||||
) (*gitlab.Snippet, error) {
|
||||
if client == nil {
|
||||
client = apiClient.Lab()
|
||||
}
|
||||
|
||||
snipet, _, err := client.ProjectSnippets.CreateSnippet(projectID, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return snipet, err
|
||||
}
|
Loading…
Reference in New Issue