1.0.0 • Published 6 years ago
ganjiang-gitlab-test v1.0.0
Ganjiang-GitLab
Debug the output
set the DEBUG = gitlab:*
by export DEBUG = gitlab:*
, ganjiang will log out debug info
create gitlab client
const GitLab = require('ganjiang-gitlab')
const gitlab = new GitLab({
host: '127.0.0.1', // gitlab host
token: 'xxxxx', // access token
version: 'v3',
groupId: 123456 //usually a number
})
Get all projects in group
parameters
- archived (optional) - if passed, limit by archived status
- order_by (optional) - Return requests ordered by id, name, path, created_at, updated_at or last_activity_at fields. Default is created_at
- sort (optional) - Return requests sorted in asc or desc order. Default is desc
- search (optional) - Return list of authorized projects according to a search criteria
- ci_enabled_first - Return projects ordered by ci_enabled flag. Projects with enabled GitLab CI go first
const projects = await gitlab.getAllProjects() //must set groudId in gitlab client
console.log(projects) // show the following data
Get projects
parameters
id
(required) - TheID or NAMESPACE/PROJECT_NAME
of a project, id usually anumber
const projects = await gitlab.getProjects({id: 123})
console.log(projects) // show the following data
Create project
parameters
name
(required) - new project name- path (optional) - custom repository name for new project. By default generated based on name
- namespace_id (optional) - namespace for the new project (defaults to user)
- description (optional) - short project description
- issues_enabled (optional)
- merge_requests_enabled (optional)
- builds_enabled (optional)
- wiki_enabled (optional)
- snippets_enabled (optional)
- public (optional) - if true same as setting visibility_level = 20
- visibility_level (optional)
- import_url (optional)
const projects = await gitlab.createProjects({name: 'new project'})
console.log(projects) // show the following data
Edit project
parameters
id
(required) - The ID of a project- name (optional) - project name
- path (optional) - custom repository name for new project. By default generated based on name
- description (optional) - short project description
- default_branch (optional)
- issues_enabled (optional)
- merge_requests_enabled (optional)
- builds_enabled (optional)
- wiki_enabled (optional)
- snippets_enabled (optional)
- public (optional) - if true same as setting visibility_level = 20
- visibility_level (optional)
const projects = await gitlab.editProjects({id: 123})
console.log(projects) // show the following data
delete project
parameters
id
(required) - The ID of a project
const projects = await gitlab.deleteProjects({id: 123})
console.log(projects) // show the following data
get File
parameters
projectId
(required) - The ID of a projectfile_path
(required) - Full path to new file. Ex. lib/class.jsref
(required) - The name of branch, tag or commit
const data = await gitlab.getFile({
projectId: 123,
file_path: 'app/test1.js',
ref: 'master',
})
console.log(data) // show the following data, data.content should be base64 decode
create File
parameters
projectId
(required) - The ID of a projectfile_path
(required) - Full path to new file. Ex. lib/class.jsbranch_name
(required) - The name of branch- encoding (optional) - 'text' or 'base64'. Text is default.
content
(required) - File contentcommit_message
(required) - Commit message
const data = await gitlab.createFile({
projectId: 123,
file_path: 'app/test1.js',
branch_name: 'master',
content:`const test = 'This is another test file!'`,
commit_message: 'create file'
})
console.log(data) // show the following data
update File
parameters
projectId
(required) - The ID of a projectfile_path
(required) - Full path to new file. Ex. lib/class.jsbranch_name
(required) - The name of branch- encoding (optional) - 'text' or 'base64'. Text is default.
content
(required) - File contentcommit_message
(required) - Commit message
const data = await gitlab.updateFile({
projectId: 123,
file_path: 'app/test1.js',
branch_name: 'master',
content:`const test = 'This is another test file!'`,
commit_message: 'update file'
})
console.log(data) // show the following data
delete File
parameters
projectId
(required) - The ID of a projectfile_path
(required) - Full path to new file. Ex. lib/class.jsbranch_name
(required) - The name of branchcommit_message
(required) - Commit message
const data = await gitlab.deleteFile({
projectId: 123,
file_path: 'app/test1.js',
branch_name: 'master',
commit_message: 'delete file'
})
console.log(data) // show the following data, data.content should be base64 decode
Run Tests
- set your
access token
in test folderutils.js
, and run
npm test
1.0.0
6 years ago