Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More β†’
Socket
Sign inDemoInstall
Socket

gitlab-restapi

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gitlab-restapi - npm Package Compare versions

Comparing version 1.1.11 to 1.1.14

nyc.config.js

14

package.json
{
"name": "gitlab-restapi",
"version": "1.1.11",
"version": "1.1.14",
"description": "Integration with GitLab REST API",
"main": "index.js",
"types": "src/types/index.d.ts",
"repository": {

@@ -21,10 +22,13 @@ "type": "git",

"license": "Apache License Version 2.0, January 2004",
"dependencies": {
},
"devDependencies": {
"dotenv": "^16.3.1",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"typescript": "^5.2.2"
},
"scripts": {
"test": "npm run test:classes",
"test:classes": "node tests/classes.js"
"test": "npm run test:mocha",
"test:mocha": "mocha tests/**/*.js",
"test:report": "nyc --reporter=html --reporter=text mocha tests/**/*.js"
}
}

@@ -6,2 +6,3 @@ # Integration with GitLab REST API

[![Downloads/month](https://img.shields.io/npm/dm/gitlab-restapi.svg)](http://www.npmtrends.com/gitlab-restapi)
[![Vulnerabilities](https://snyk.io/test/npm/gitlab-restapi/badge.svg)](https://snyk.io/test/npm/gitlab-restapi)

@@ -8,0 +9,0 @@ The module allows you to perform the list of methods described in the GitLab service documentation in the section

@@ -1,2 +0,2 @@

/*
/**
* =========================================================

@@ -18,3 +18,3 @@ * πŸ‡ΊπŸ‡¦ πŸ‡ΊπŸ‡¦ πŸ‡ΊπŸ‡¦ πŸ‡ΊπŸ‡¦ πŸ‡ΊπŸ‡¦ πŸ‡ΊπŸ‡¦ πŸ‡ΊπŸ‡¦ GitLab API πŸ‡ΊπŸ‡¦ πŸ‡ΊπŸ‡¦ πŸ‡ΊπŸ‡¦ πŸ‡ΊπŸ‡¦ πŸ‡ΊπŸ‡¦ πŸ‡ΊπŸ‡¦ πŸ‡ΊπŸ‡¦

/**
* @type {any}
* @type {object|string|number|null|Date}
*/

@@ -24,11 +24,18 @@ value;

/**
* @param {string} key
* @param {any} value
* @param {string} k
* @param {object|string|number|null|Date} v
*/
constructor(key, value) {
this.key = key;
this.value = value;
constructor(k, v) {
/* istanbul ignore next */
this.key = k;
/* istanbul ignore next */
this.value = v;
}
/* istanbul ignore next */
get() {
return {[this.key]: this.value};
}
}
module.exports = AbstractKeyValue
module.exports = AbstractKeyValue;

@@ -12,3 +12,6 @@ /*

class AbstractList extends Array {
constructor(v) {
/**
* @param {Array|null} v
*/
constructor(v = null) {
if (v instanceof Array) super(...v); else super();

@@ -15,0 +18,0 @@ }

@@ -31,4 +31,4 @@ /*

/**
* @param {any} obj
* @return {any[]}
* @param {object} obj
* @return {string[]}
*/

@@ -57,2 +57,3 @@ getOwnPropertyOf = (obj) => {

* @param {any} source
* @return {void}
*/

@@ -59,0 +60,0 @@ copyProperties(source) {

@@ -25,4 +25,4 @@ /*

getOwnPropertyNames(){
return Object.getOwnPropertyNames(this).filter(it=> this[it] instanceof APICore)
getOwnPropertyNames() {
return Object.getOwnPropertyNames(this).filter(it => this[it] instanceof APICore)
}

@@ -62,3 +62,3 @@

class: Response,
url: (job_id) => `projects/${this.projectId}/jobs/${job_id}/trace`
url: (job_id) => 'projects/' + this.projectId + '/jobs/' + job_id + 'trace'
}),

@@ -65,0 +65,0 @@ trace: new Method({

@@ -24,3 +24,3 @@ /*

/**
* @type {[Method]}
* @type {Object}
*/

@@ -35,3 +35,3 @@ #methods = {};

* @deprecated
* @return {Method[]}
* @return {Object}
*/

@@ -103,4 +103,10 @@ get uri() {

const response = await this.request[spec.method](..._args);
if (response.ok) return new Class(await response.json());
else {
if (response.ok) {
const _t = await response.text();
try {
return new Class(JSON.parse(_t));
} catch (e) {
return _t;
}
} else {
const e = await response.json();

@@ -113,3 +119,2 @@ console.warn('WARNING:', JSON.stringify({...e, url}))

}
return null;
}

@@ -116,0 +121,0 @@ })

@@ -64,3 +64,3 @@ /*

* @param {object} opts
* @return {Promise<{ok}|*|null>}
* @return {Promise<Object|HttpResponse|null>}
*/

@@ -67,0 +67,0 @@ async #request(url, opts) {

@@ -15,2 +15,6 @@ /*

class DynamicResponse {
/**
* @typedef {import('../types/DynamicResponse').Classes}
* @return {Object}
*/
static class(className) {

@@ -23,2 +27,3 @@ const Classes = ({className}) => this.pipeline(

}
static getSingletonName = (v) => {

@@ -61,3 +66,3 @@ v = v.capitalize();

* pipeline
* @param {function} methods
* @param {function[]} methods
* @returns {function(*): *}

@@ -64,0 +69,0 @@ */

@@ -48,10 +48,4 @@ /*

static Serializer = Serializer;
static version = {
get node(){
const [major, minor, patch] = process.versions.node.split('.').map(Number)
return {major, minor, patch}
}
}
}
module.exports = GitLab;

@@ -1,2 +0,1 @@

const https = require('https')
const AbstractProperties = require("./AbstractProperties");

@@ -27,4 +26,4 @@ const Serializer = require("./Serializer");

* @param {string|object} v
* @param {{statusCode:number,status:number}|https.IncomingMessage} res
* @return {HttpResponse|https.IncomingMessage}
* @param {{statusCode?:number,status?:number,rawHeaders?:string[]}|Object} res
* @return {HttpResponse|Object}
*/

@@ -44,3 +43,3 @@ static response(v, res) {

/**
* @param {{statusCode:number,status:number}|https.IncomingMessage} res
* @param {{statusCode?:number,status?:number,rawHeaders?:string[]}|Object} res
* @return {boolean}

@@ -55,3 +54,3 @@ */

if (res.headers) return res.headers;
let rv = {}
let rv = {}
let rawHeaders = res.rawHeaders || (res.res || {}).rawHeaders;

@@ -58,0 +57,0 @@ if (res && rawHeaders && rawHeaders instanceof Array) {

@@ -17,3 +17,3 @@ /*

/**
* @type {AbstractList<AbstractKeyValue>}
* @type {AbstractList|Array<any>}
*/

@@ -20,0 +20,0 @@ job_variables_attributes = new AbstractList();

@@ -26,6 +26,8 @@ /*

/**
* @param {object:{}} props
* @param {object:{method:string,class:object,url:Object|Function}} props
*/
constructor(props) {
for (let key of Object.keys(props)) if (this.hasOwnProperty(key)) this[key] = props[key];
for (let key of Object.keys(props))
/* istanbul ignore next */
if (this.hasOwnProperty(key)) this[key] = props[key];
}

@@ -32,0 +34,0 @@ }

@@ -24,2 +24,5 @@ /*

/**
* @param {Object} params
*/
constructor(params) {

@@ -26,0 +29,0 @@ super()

@@ -87,5 +87,6 @@ /*

* @param {Object} ClassType
* @param {boolean} ownPropertyOnly
* @return {object}
*/
static deserialize(serializedJsonString, ClassType = null) {
static deserialize(serializedJsonString, ClassType = null, ownPropertyOnly = true) {
const json = typeof serializedJsonString === 'string' ? JSON.parse(serializedJsonString) : serializedJsonString;

@@ -101,8 +102,9 @@ if (!ClassType && !json.serialized) throw new Error(' πŸ‡ΊπŸ‡¦ A ClassType argument (deserialize(serializedJsonString, ClassType) ' +

}
const copy = (s, t, k) => t[k] = s[k];
for (let key of Object.keys(json))
if (ClassType && object.hasOwnProperty(key)) object[key] = json[key];
else if (!ClassType && key !== 'serialized') object[key] = json[key];
if ((ClassType && (object.hasOwnProperty(key) || !ownPropertyOnly)) ||
(!ClassType && key !== 'serialized')) copy(json, object, key);
/* istanbul ignore next */
return this.normalize(object);
}
}

@@ -109,0 +111,0 @@

@@ -10,2 +10,2 @@ /*

*/
module.exports = require('./GitLab')
module.exports = require('./GitLab/')

@@ -18,6 +18,33 @@ /*

const DynamicResponse = require("../src/GitLab/DynamicResponse");
const GitLab = require("../src");
const GitLab = require("../src/");
const HttpResponse = require("../src/GitLab/HttpResponse");
const JobVariablesAttributes = require("../src/GitLab/JobVariablesAttributes");
(async () => {
const ap = new AbstractProperties()
await describe('AbstractProperties class', () => {
it('properties list len', () => assert.equal(ap.getOwnPropertyOf(ap).length > 8, true))
it('string result of formatDate', () => assert.equal(typeof ap.formatDate(new Date()), 'string'))
it('Array result of getOwnPropertyOf', () => assert.equal(ap.getOwnPropertyOf(ap) instanceof Array, true))
})
const resp = new Response({test: 'true', date: new Date()})
await describe('Serializer class', () => {
const seril = GitLab.Serializer.serialize(resp)
it('Serialized typeof string', () => assert.strictEqual(typeof seril, 'string'))
const deser = GitLab.Serializer.deserialize(seril, Response, false)
it('deserialized instanceof Response', () => assert.strictEqual(deser instanceof Response, true))
it('deserialized prop test is boolean', () => assert.strictEqual(deser.test, true))
it('deserialized prop date is Date', () => assert.strictEqual(deser.date instanceof Date, true))
})
const jobVariablesAttributes = new JobVariablesAttributes();
jobVariablesAttributes.add(new GitLab.AbstractKeyValue('a', 'b'));
jobVariablesAttributes.add('a', 'b');
jobVariablesAttributes.push('b', 's');
await describe('JobVariablesAttributes class', () => {
it('JobVariablesAttributes', () => assert.equal(typeof jobVariablesAttributes.toString(), 'string'))
})
const opts = {method: 'post', headers: {'Content-Type': 'application/json'}}

@@ -27,4 +54,9 @@ const response = await GitLab.Request('https://maps.googleapis.com/maps/api/geocode/json?address=google', opts);

console.log(json)
describe('Node.js 16.x - Replacement of the missing node 16 fetch by own GitLab.Request', () => {
it('You must use an API key to authenticate each request', () => assert.equal(json.status, 'REQUEST_DENIED'))
await describe('GitLab.Request - Node.js 16.x - Replacement of the missing node 16 fetch', () => {
it('HttpResponse', () => assert.equal(response instanceof HttpResponse, true))
it('response has json function', () => assert.equal(!!response.json, true))
it('test Google api key response', () => assert.equal(json.status, 'REQUEST_DENIED'))
const res = HttpResponse.response({data: 'a'}, {status: 500, rawHeaders: ['a', 'b']})
it('HttpResponse status 500', () => assert.equal(res.status === 500, true))
it('HttpResponse is bad', () => assert.equal(HttpResponse.isGood(res), false))
})

@@ -34,11 +66,23 @@

const glerror = new GitLab.Error(gitLab, 'test')
await describe('GitLabError class', () => {
it('stack is null', () => assert.strictEqual(glerror.stack, null))
it('info is string', () => assert.strictEqual(typeof glerror.info, 'object'))
})
const names = ['groups', 'Releases'];
describe('Dynamic response classes', () => {
await describe('Dynamic response classes', () => {
for (let v of names) {
v = v.capitalize()
v = GitLab.DynamicResponse.getSingletonName(v)
const _classes = DynamicResponse.class(v)
const singleton = new _classes[DynamicResponse.getSingletonName(v)]({})
const list = new _classes[DynamicResponse.getSingletonName(v) + 's']([], {})
it(v + ' has AbstractProperties formatDate', () => assert.strictEqual(!!singleton.formatDate, true))
it(v + ' has AbstractProperties getOwnPropertyOf', () => assert.strictEqual(!!singleton.formatDate, true))
it(v + 's has AbstractProperties formatDate', () => assert.strictEqual(!!list.formatDate, true))
it(v + 's has AbstractProperties getOwnPropertyOf', () => assert.strictEqual(!!list.formatDate, true))
it(v + ' single response Class', () => assert.strictEqual(_classes[DynamicResponse.getSingletonName(v)].name, DynamicResponse.getSingletonName(v)))
it(v + ' instanceof GitLab.Response', () => assert.strictEqual(new _classes[DynamicResponse.getSingletonName(v)]({}) instanceof Response, true))
it(v + ' list responses Class', () => assert.strictEqual(_classes[DynamicResponse.getSingletonName(v) + 's'].name, DynamicResponse.getSingletonName(v) + 's'))
it(v + 's instanceof GitLab.Responses', () => assert.strictEqual(new _classes[DynamicResponse.getSingletonName(v) + 's']([], {}) instanceof Responses, true))
it(v + ' instanceof GitLab.Response', () => assert.strictEqual(singleton instanceof Response, true))
it(v + 's list responses Class', () => assert.strictEqual(_classes[DynamicResponse.getSingletonName(v) + 's'].name, DynamicResponse.getSingletonName(v) + 's'))
it(v + 's instanceof GitLab.Responses', () => assert.strictEqual(list instanceof Responses, true))
}

@@ -63,3 +107,3 @@ })

for (let a of gitLab.getOwnPropertyNames()) {
describe(a + ' API class', () => {
await describe(a + ' API class', () => {
it('instanceof AbstractProperties', () => assert.strictEqual(gitLab[a] instanceof AbstractProperties, true))

@@ -76,3 +120,3 @@ for (let k of Object.keys(gitLab[a].methods)) {

describe('Jobs API class', () => {
await describe('Jobs API class', () => {
it('count 2', () => {

@@ -79,0 +123,0 @@ assert.strictEqual(jobs.list.length, 2);

@@ -10,6 +10,7 @@ /*

*/
const GitLab = require("../");
const GitLab = require("../src/");
const {describe, it} = require("node:test");
const {strict: assert} = require("node:assert");
const Method = require("../src/GitLab/Method");
require('dotenv').config();

@@ -21,20 +22,23 @@ (async () => {

const gitLab = new GitLab.API(new GitLab.Options({
let gitLab = new GitLab.API(new GitLab.Options({
privateToken: process.env.GIT_TOKEN,
projectId: process.env.GIT_PID,
fetchMethod: GitLab.Request // axios, fetch, node-fetch, etc...
// auto config
//fetchMethod: GitLab.Request // axios, fetch, node-fetch, etc...
}));
// https://docs.gitlab.com/ee/api/releases/
gitLab.add('Releases').addMethods({
releases: new GitLab.Method({
method: 'get',
class: GitLab.Responses,
url: () => `projects/${gitLab.projectId}/releases`
const apimethods = gitLab.getOwnPropertyNames();
for (let am of apimethods) {
const coremethods = gitLab[am].methods;
await describe('Statement ' + am + ' of API', () => {
for (let m of Object.keys(coremethods)) {
it('method ' + m, () => {
assert.strictEqual(gitLab[am][m] instanceof Object, true);
})
}
})
})
console.log(gitLab.Releases.methods)
}
const releases = await gitLab.Releases.releases(new GitLab.PaginateParams({page: 1, per_page: 20}));
console.log(releases.list)
describe('New dynamic Releases class', () => {
await describe('New dynamic Releases class', () => {
it('Releases instanceof GitLab.Responses', () => {

@@ -51,5 +55,4 @@ assert.strictEqual(releases instanceof GitLab.Responses, true);

})
console.log(gitLab.Groups.methods)
const groups = await gitLab.Groups.groups(new GitLab.PaginateParams({page: 1, per_page: 20}));
describe('New dynamic Groups class', () => {
await describe('New dynamic Groups class', () => {
it('Groups instanceof GitLab.Responses', () => {

@@ -63,8 +66,6 @@ assert.strictEqual(groups instanceof GitLab.Responses, true);

console.log(gitLab.Pipelines.methods)
const pipelines = await gitLab.Pipelines.pipelines(new GitLab.PaginateParams({
page: 1, per_page: 20, status: 'success', source: 'push',
}));
console.log(pipelines.list)
describe('New dynamic Pipelines class', () => {
await describe('New dynamic Pipelines class', () => {
it('Pipelines instanceof GitLab.Responses', () => {

@@ -76,7 +77,6 @@ assert.strictEqual(pipelines instanceof GitLab.Responses, true);

})
})
});
const pipelinelatest = await gitLab.Pipelines.latest();
console.log(pipelinelatest)
describe('New dynamic Pipelines class', () => {
await describe('New dynamic Pipelines class', () => {
it('Pipeline instanceof GitLab.Response', () => {

@@ -87,2 +87,3 @@ assert.strictEqual(pipelinelatest instanceof GitLab.Response, true);

})();
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc