Socket
Socket
Sign inDemoInstall

gitlab-x

Package Overview
Dependencies
4
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.11 to 0.2.2

.gitlab-ci.yml

11

.vscode/launch.json

@@ -14,3 +14,3 @@ {

],
"program": "${workspaceFolder}/index.js",
"program": "${workspaceFolder}/bin.js",
"env": {

@@ -21,6 +21,7 @@ "GITLAB_URL": "https://git.fs-stuttgart.de",

"args": [
"get",
"raw",
"/vehicle/node/description",
"package.json"
"commit",
"img.jpg",
"/m.partenfelder/config-shipper-test",
"e8.jpg",
"--verbose"
]

@@ -27,0 +28,0 @@ }

@@ -78,5 +78,8 @@ import axios from "axios";

async fileExists(projectId, branchName, filePath) {
async fileExists(projectIdentifier, filePath, branchName) {
if(typeof branchName === 'undefined') {
branchName = (await this.getProject(projectIdentifier)).default_branch;
}
const encodedFilePath = encodeURIComponent(trimSlashes(filePath))
const url = `${this.API_URL}/projects/${projectId}/repository/files/${encodedFilePath}?ref=${branchName}`
const url = `${this.getProjectUrl(projectIdentifier)}/repository/files/${encodedFilePath}?ref=${branchName}`
try {

@@ -92,3 +95,3 @@ if(this.VERBOSE) console.log(`GET > ${url}`);

else {
throw new GitlabApiError(`Error requesting file '${filePath}' from branch '${branchName}' for project ID '${projectId}'\n\nOriginal Error:\n${e}`)
throw new GitlabApiError(`Error requesting file '${filePath}' from branch '${branchName}' for project identified by '${projectIdentifier}'\n\nOriginal Error:\n${e}`)
}

@@ -98,4 +101,4 @@ }

async postCommit(projectId, commitObject) {
const url = `${this.API_URL}/projects/${projectId}/repository/commits`
async postCommit(projectIdentifier, commitObject) {
const url = `${this.getProjectUrl(projectIdentifier)}/repository/commits`
const config = {

@@ -113,3 +116,3 @@ headers: {

catch(e) {
throw new GitlabApiError(`Error executing commit on project ID '${projectId}'\n\nOriginal Error:\n${e}`)
throw new GitlabApiError(`Error executing commit on project identified by '${projectIdentifier}'\n\nOriginal Error:\n${e}`)
}

@@ -144,3 +147,10 @@ }

if(this.VERBOSE) console.log(`GET > ${url}`);
const res = await axios.get(url, this.config);
const res = await axios.request({
responseType: 'arraybuffer',
url: url,
method: "get",
headers: {
"PRIVATE-TOKEN": this.AT
}
});
if(res.status === 200) {

@@ -147,0 +157,0 @@ return res.data;

@@ -1,137 +0,8 @@

#!/usr/bin/env node
import * as util_import from './util.js'
import * as api_driver_import from './api-driver.js'
import * as commit_helper_import from './commit-helper.js'
/*
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'
const version = "0.1.11";
const parser = new ArgumentParser({
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('-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'})
parser.add_argument('--ref', {metavar: 'ref', type: String, help: 'provide a git ref'})
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 "version":
await doVersion(args);
break;
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();
let fields;
switch(objectType) {
case "project":
fields = parameters;
if(args.verbose) console.log(`Doing 'GET' > 'project' with identifier '${objectIdentifier}' and fields '${fields}'`);
await getProject(args, objectIdentifier, fields);
break;
case "branches":
fields = parameters;
if(args.verbose) console.log(`Doing 'GET' > 'branches' with identifier '${objectIdentifier}' and fields '${fields}'`);
await getBranches(args, objectIdentifier, fields);
break;
case "raw":
if(parameters.length != 1) {
throw new Error(`Error: wrong number of parameters for 'get raw' action`)
}
const filePath = parameters.shift();
if(args.verbose) console.log(`Doing 'GET' > 'raw' with identifier project identifier '${objectIdentifier}' and file path '${fields}'`);
await getRaw(args, objectIdentifier, filePath);
break;
default:
throw new Error(`Error: object type '${objectType}' is not supported`)
}
}
async function doVersion(args) {
const api = getApiDriver(args);
const version = await api.getVersion();
const result = filterFields(args, version, args.parameters);
console.dir(result);
}
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);
}
async function getBranches(args, objectIdentifier, fields) {
const api = getApiDriver(args);
const branches = await api.getBranches(objectIdentifier);
const result = filterFields(args, branches, fields);
console.dir(result);
}
async function getRaw(args, projectIdentifier, filePath) {
const api = getApiDriver(args);
const rawFile = await api.getRawFile(projectIdentifier, filePath, args.ref);
console.log(rawFile);
}
export const getApiDriver = util_import.getApiDriver;
export const apiTest = util_import.apiTest;
export const GitlabApiDriver = api_driver_import.GitlabApiDriver;
export const commitSingleFile = commit_helper_import.commitSingleFile;
{
"name": "gitlab-x",
"version": "0.1.11",
"version": "0.2.2",
"description": "GitLab Executor API Interface",

@@ -8,3 +8,3 @@ "repository": "https://github.com/mxcd/gitlab-api",

"bin": {
"gitlab-x": "./index.js"
"gitlab-x": "./bin.js"
},

@@ -11,0 +11,0 @@ "scripts": {

@@ -77,2 +77,5 @@ ## gitlab-x

##### get raw
`$ npx gitlab-x get raw <project_identifier> <file_path> [--ref <branch>]`
`$ npx gitlab-x get raw <project_identifier> <file_path> [--ref <branch>]`
#### commit
`$ npx gitlab-x commit <local file> <project identifier> [<target file>] [--ref <branch>] [--force]`
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc