Skip to content

Commit

Permalink
Merge pull request profclems#950 from zemzale/feat-snippets-api
Browse files Browse the repository at this point in the history
feat(api): Add api wrappers for creating snippets
  • Loading branch information
zemzale authored Feb 10, 2022
2 parents 93ff2e4 + 5429bb7 commit 6e92e27
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions api/snippets.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 6e92e27

Please sign in to comment.