gitlab-sdk-nodejs
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,14 +0,14 @@ | ||
const Gitlab = require('../gitlab') | ||
const Client = require('./common/client') | ||
const Client = new Gitlab({ | ||
serverUrl: 'https://gitlab.com', | ||
productId: 'frontend%2Fhome', | ||
token: '' | ||
}) | ||
async function main() { | ||
async function fetchProject() { | ||
const response = await Client.fetchProject() | ||
console.log(response); | ||
console.log(response) | ||
} | ||
main() | ||
async function fetchProjectVariables() { | ||
const response = await Client.fetchProjectVariables() | ||
console.log(response) | ||
} | ||
fetchProject() | ||
fetchProjectVariables() |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const node_fetch_1 = require("node-fetch"); | ||
// import fetch from "node-fetch"; | ||
const axios_1 = require("axios"); | ||
class Client { | ||
@@ -14,9 +15,11 @@ constructor(options) { | ||
async request(action, req, options = {}) { | ||
const method = options.method || 'GET'; | ||
options = { | ||
headers: this.headers, | ||
method: options.method || 'GET', | ||
body: JSON.stringify(req), | ||
method, | ||
data: req, | ||
params: method === 'GET' ? req : null | ||
}; | ||
const response = await node_fetch_1.default(`${this.serverUrl}/api/v4/${action}`, options); | ||
return await response.json(); | ||
let response = await axios_1.default(`${this.serverUrl}/api/v4/${action}`, options); | ||
return response.data; | ||
} | ||
@@ -52,13 +55,52 @@ fetchProject() { | ||
} | ||
deleteBranch(id) { | ||
return this.request(`/projects/${this.productId}/repository/branches/${id}`, null, { | ||
createBranch(req) { | ||
return this.request(`/projects/${this.productId}/repository/branches`, req, { | ||
method: 'post' | ||
}); | ||
} | ||
fetchBranches() { | ||
return this.request(`/projects/${this.productId}/repository/branches`); | ||
} | ||
fetchBranch(branch) { | ||
return this.request(`/projects/${this.productId}/repository/branches/${branch}`); | ||
} | ||
deleteBranch(branch) { | ||
return this.request(`/projects/${this.productId}/repository/branches/${branch}`, null, { | ||
method: 'delete' | ||
}); | ||
} | ||
deleteTag(id) { | ||
return this.request(`/projects/${this.productId}/protected_tags/${id}`, null, { | ||
deleteMergedBranches() { | ||
return this.request(`/projects/${this.productId}/repository/merged_branches`, null, { | ||
method: 'delete' | ||
}); | ||
} | ||
fetchPipelines(req) { | ||
return this.request(`/projects/${this.productId}/pipelines`, req); | ||
} | ||
fetchPipeline(pipeline_id) { | ||
return this.request(`/projects/${this.productId}/pipelines/${pipeline_id}`); | ||
} | ||
fetchPipelineJobs(pipeline_id) { | ||
return this.request(`/projects/${this.productId}/pipelines/${pipeline_id}/jobs`); | ||
} | ||
fetchProjectJobs() { | ||
return this.request(`/projects/${this.productId}/jobs`); | ||
} | ||
fetchTags() { | ||
return this.request(`/projects/${this.productId}/repository/tags`); | ||
} | ||
fetchTag(tag_name) { | ||
return this.request(`/projects/${this.productId}/repository/tags/${tag_name}`); | ||
} | ||
createTag(req) { | ||
return this.request(`/projects/${this.productId}/repository/tags`, req, { | ||
method: 'post' | ||
}); | ||
} | ||
deleteTag(tag_name) { | ||
return this.request(`/projects/${this.productId}/repository/tags/${tag_name}`, null, { | ||
method: 'delete' | ||
}); | ||
} | ||
} | ||
module.exports = Client; |
{ | ||
"name": "gitlab-sdk-nodejs", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Gitlab API NODEJS SDK", | ||
@@ -21,5 +21,5 @@ "main": "gitlab/index.js", | ||
"dependencies": { | ||
"axios": "^0.21.0", | ||
"babel-eslint": "^10.0.2", | ||
"https-proxy-agent": "^2.2.1", | ||
"node-fetch": "^2.2.0", | ||
"tslib": "1.13.0" | ||
@@ -37,3 +37,2 @@ }, | ||
"@types/node": "^14.0.26", | ||
"@types/node-fetch": "^2.5.7", | ||
"@typescript-eslint/eslint-plugin": "^2.34.0", | ||
@@ -40,0 +39,0 @@ "@typescript-eslint/parser": "^2.34.0", |
@@ -20,2 +20,4 @@ # Gitlab SDK NodeJS | ||
main() | ||
``` | ||
``` | ||
https://docs.gitlab.com/ee/api/README.html |
@@ -1,2 +0,3 @@ | ||
import fetch from "node-fetch"; | ||
// import fetch from "node-fetch"; | ||
import axios from "axios" | ||
@@ -18,9 +19,11 @@ class Client { | ||
async request(action: string, req?: any, options: any = {}) { | ||
const method = options.method || 'GET' | ||
options = { | ||
headers: this.headers, | ||
method: options.method || 'GET', | ||
body: JSON.stringify(req), | ||
method, | ||
data: req, | ||
params: method === 'GET' ? req : null | ||
} | ||
const response = await fetch(`${this.serverUrl}/api/v4/${action}`, options) | ||
return await response.json(); | ||
let response = await axios(`${this.serverUrl}/api/v4/${action}`, options) | ||
return response.data | ||
} | ||
@@ -31,3 +34,2 @@ | ||
} | ||
@@ -66,4 +68,18 @@ fetchProjectVariables(){ | ||
deleteBranch(id: string) { | ||
return this.request(`/projects/${this.productId}/repository/branches/${id}`, null, { | ||
createBranch(req: any) { | ||
return this.request(`/projects/${this.productId}/repository/branches`, req, { | ||
method: 'post' | ||
}) | ||
} | ||
fetchBranches() { | ||
return this.request(`/projects/${this.productId}/repository/branches`) | ||
} | ||
fetchBranch(branch: string) { | ||
return this.request(`/projects/${this.productId}/repository/branches/${branch}`) | ||
} | ||
deleteBranch(branch: string) { | ||
return this.request(`/projects/${this.productId}/repository/branches/${branch}`, null, { | ||
method: 'delete' | ||
@@ -73,9 +89,45 @@ }) | ||
deleteTag(id: String) { | ||
return this.request(`/projects/${this.productId}/protected_tags/${id}`, null, { | ||
deleteMergedBranches() { | ||
return this.request(`/projects/${this.productId}/repository/merged_branches`, null, { | ||
method: 'delete' | ||
}) | ||
} | ||
fetchPipelines(req: any) { | ||
return this.request(`/projects/${this.productId}/pipelines`, req) | ||
} | ||
fetchPipeline(pipeline_id: string | number) { | ||
return this.request(`/projects/${this.productId}/pipelines/${pipeline_id}`) | ||
} | ||
fetchPipelineJobs(pipeline_id: string | number) { | ||
return this.request(`/projects/${this.productId}/pipelines/${pipeline_id}/jobs`) | ||
} | ||
fetchProjectJobs() { | ||
return this.request(`/projects/${this.productId}/jobs`) | ||
} | ||
fetchTags() { | ||
return this.request(`/projects/${this.productId}/repository/tags`) | ||
} | ||
fetchTag(tag_name: string) { | ||
return this.request(`/projects/${this.productId}/repository/tags/${tag_name}`) | ||
} | ||
createTag(req: any) { | ||
return this.request(`/projects/${this.productId}/repository/tags`, req, { | ||
method: 'post' | ||
}) | ||
} | ||
deleteTag(tag_name: String) { | ||
return this.request(`/projects/${this.productId}/repository/tags/${tag_name}`, null, { | ||
method: 'delete' | ||
}) | ||
} | ||
} | ||
module.exports = Client |
13763
7
12
358
22
+ Addedaxios@^0.21.0
+ Addedaxios@0.21.4(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
- Removednode-fetch@^2.2.0
- Removednode-fetch@2.7.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)