Gitlab-snippets
A Simple Gitlab Snippets API library
Usage:
Initialize
const GitlabSnippets = require('gitlab-snippets')
let snippets = false
try {
snippets = new GitlabSnippets({
'hostname': <host_name>,
'port': <port>,
'headers': {
'private-token': <private_token>
}
})
} catch (e) {
console.log(e);
}
Get current options
console.log(snippets.getOpts())
Get list of snippets
snippets.list()
.then(
snippetObjsArray => console.log(snippetObjsArray),
err => console.error(err)
)
Get a snippet by id
snippets.get(<snippet_id>)
.then(
snippetContent => console.log(snippetContent),
err => console.error(err)
)
Create a new snippet
snippets.create({
title: 'This is a test snippet',
content: 'Hello from gitlab-snippets',
file_name: 'test.txt',
description: 'Hello World Snippet',
visibility: 'private'
}).then(
snippetObj => console.log(snippetObj),
err => console.error(err)
)
Update a snippet
snippets.update({
title: 'This is a test snippet update',
content: 'Hello from gitlab-snippets updated',
file_name: 'test-updated.txt',
description: 'Hello World Snippet updated',
visibility: 'public'
}, <snippet_id>).then(
snippetObj => console.log(snippetObj),
err => console.error(err)
)
Delete a snippet
snippets.delete(<snippet_id>)
.then(
success => console.log(success),
err => console.error(err)
)