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

gitlab-x

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-x - npm Package Compare versions

Comparing version 0.0.7 to 0.1.0

.vscode/launch.json

104

index.js
#!/usr/bin/env node
const { ArgumentParser } = require('argparse');
const { version } = require('./package.json');
/*
gitlab-x command structure
gitlab-x => print help
gitlab-x help => print help
gitlab-x [-v | --version] => print version
gitlab-x get project <id | path> => get project json
gitlab-x ci-lint => /ci/lint
*/
import pkg from 'argparse';
const {ArgumentParser} = pkg;
import { apiTest, getApiDriver, filterFields } from './util.js'
import { readFileSync } from 'fs'
const version = JSON.parse(readFileSync('./package.json')).version;
const parser = new ArgumentParser({
description: 'Argparse example'
description: 'gitlab-x: Gitlab Executor API Interface'
});
parser.add_argument('action', {metavar: 'action', type: String, nargs: '?', default: 'get', help: 'action to be executed'});
parser.add_argument('parameters', {metavar: 'parameters', type: String, nargs: '*', help: 'action parameters to be used'});
parser.add_argument('-v', '--version', { action: 'version', version });
parser.add_argument('-f', '--foo', { help: 'foo bar' });
parser.add_argument('-b', '--bar', { help: 'bar foo' });
parser.add_argument('--baz', { help: 'baz bar' });
parser.add_argument('-t', '--access-token');
parser.add_argument('-u', '--url')
parser.add_argument('--verbose', {action: 'store_true', help: 'increased console output'})
parser.add_argument('--json', {action: 'store_true', help: 'always print result as json, even if it is a single value'})
console.log("npx test");
const args = parser.parse_args()
// Check presence of AT and URL
// Only use ENV variables when args are not set
if(typeof process.env.GITLAB_AT === 'undefined' && typeof args.access_token === 'undefined') {
throw new Error("Error: no access token specified. Either set it as ENV variable 'GITLAB_AT' or pass it with [-t | --access-token]")
}
else if (typeof args.access_token === 'undefined') {
args.access_token = process.env.GITLAB_AT;
}
if(typeof process.env.GITLAB_URL === 'undefined' && typeof args.url === 'undefined') {
throw new Error("Error: no GitLab URL specified. Either set it as ENV variable 'GITLAB_URL' or pass it with [-u | --url]")
}
else if(typeof args.url === 'undefined') {
args.url = process.env.GITLAB_URL;
}
if(args.verbose) {
console.dir(args);
}
(async () => {
if(!await apiTest(args)) {
throw new Error(`Error: API at '${args.url}' not accessible with given access token`)
}
doAction(args);
})();
async function doAction(args) {
const action = args.action;
if(args.verbose) console.log(`Action is '${action}'`);
switch(action) {
case "get":
await doGetAction(args);
break;
default:
throw new Error(`Error: '${action}' is an invalid action`);
}
}
async function doGetAction(args) {
// get action syntax:
// gitlab-x get <object type> <object identifier> [<object fields>...]
let parameters = args.parameters;
if(parameters.length < 2) {
throw new Error(`Error: not enough parameter for 'get' action`)
}
const objectType = parameters.shift();
const objectIdentifier = parameters.shift();
// remaining parameters are object fields
const fields = parameters;
switch(objectType) {
case "project":
if(args.verbose) console.log(`Doing 'GET' > 'project' with identifier '${objectIdentifier}' and fields '${fields}'`);
await getProject(args, objectIdentifier, fields);
break;
default:
throw new Error(`Error: object type '${objectType}' is not supported`)
}
}
async function getProject(args, objectIdentifier, fields) {
const api = getApiDriver(args);
const project = await api.getProject(objectIdentifier);
const result = filterFields(args, project, fields);
console.dir(result);
}

13

package.json
{
"name": "gitlab-x",
"version": "0.0.7",
"description": "GitLab API interface",
"version": "0.1.0",
"description": "GitLab Executor API Interface",
"repository": "https://github.com/mxcd/gitlab-api",

@@ -14,4 +14,11 @@ "main": "index.js",

},
"type": "module",
"author": "Max Partenfelder",
"license": "ISC"
"license": "ISC",
"dependencies": {
"argparse": "^2.0.1",
"axios": "^0.21.0",
"diff": "^5.0.0",
"fs": "0.0.1-security"
}
}
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