forked from profclems/glab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request profclems#950 from zemzale/feat-snippets-api
feat(api): Add api wrappers for creating snippets
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |