Comparing version 0.2.3 to 0.2.4
@@ -1,10 +0,10 @@ | ||
import axios from "axios"; | ||
import {trimSlashes, trimTailingSlash, trimLeadingSlash, resolveProjectIdentifier} from "./util.js"; | ||
const axios = require("axios"); | ||
const util = require("./util.js"); | ||
const API_PATH = `/api/v4`; | ||
export class GitlabApiDriver { | ||
class GitlabApiDriver { | ||
constructor(baseUrl, accessToken, verbose) { | ||
this.VERBOSE = verbose; | ||
this.BASE_URL = trimTailingSlash(baseUrl); | ||
this.BASE_URL = util.trimTailingSlash(baseUrl); | ||
@@ -24,3 +24,3 @@ if(this.BASE_URL.startsWith("http://")) { | ||
getProjectUrl(identifier) { | ||
const resolvedIdentifier = resolveProjectIdentifier(this.BASE_URL, identifier); | ||
const resolvedIdentifier = util.resolveProjectIdentifier(this.BASE_URL, identifier); | ||
if(typeof resolvedIdentifier.id !== 'undefined') { | ||
@@ -30,3 +30,3 @@ return `${this.API_URL}/projects/${resolvedIdentifier.id}`; | ||
else if(typeof resolvedIdentifier.path !== 'undefined') { | ||
const encodedPath = encodeURIComponent(trimSlashes(resolvedIdentifier.path)) | ||
const encodedPath = encodeURIComponent(util.trimSlashes(resolvedIdentifier.path)) | ||
return `${this.API_URL}/projects/${encodedPath}`; | ||
@@ -84,3 +84,3 @@ } | ||
} | ||
const encodedFilePath = encodeURIComponent(trimSlashes(filePath)) | ||
const encodedFilePath = encodeURIComponent(util.trimSlashes(filePath)) | ||
const url = `${this.getProjectUrl(projectIdentifier)}/repository/files/${encodedFilePath}?ref=${branchName}` | ||
@@ -142,3 +142,3 @@ try { | ||
} | ||
const encodedFilePath = encodeURIComponent(trimSlashes(filePath)) | ||
const encodedFilePath = encodeURIComponent(util.trimSlashes(filePath)) | ||
const url = `${this.getProjectUrl(projectIdentifier)}/repository/files/${encodedFilePath}/raw?ref=${branchName}` | ||
@@ -188,2 +188,5 @@ try { | ||
} | ||
} | ||
} | ||
module.exports.GitlabApiDriver = GitlabApiDriver | ||
module.exports.GitlabApiError = GitlabApiError |
11
bin.js
#!/usr/bin/env node | ||
// Imports | ||
import pkg from 'argparse'; | ||
const {ArgumentParser} = pkg; | ||
import { apiTest, getApiDriver, filterFields } from './util.js' | ||
import {GitlabApiDriver} from './api-driver.js' | ||
import * as commitHelper from './commit-helper.js' | ||
const {ArgumentParser} = require("argparse"); | ||
const { apiTest, getApiDriver, filterFields } = require('./util.js'); | ||
const GitlabApiDriver = require('./api-driver.js').GitlabApiDriver | ||
const commitHelper = require('./commit-helper.js'); | ||
// version (same as package.json due to npx problems) | ||
const version = "0.2.3"; | ||
const version = "0.2.4"; | ||
@@ -13,0 +12,0 @@ const parser = new ArgumentParser({ |
@@ -1,5 +0,6 @@ | ||
import { existsSync, readFileSync } from 'fs' | ||
import { basename } from 'path' | ||
import { apiTest, getApiDriver, filterFields } from './util.js' | ||
import {diffLines} from "diff"; | ||
const existsSync = require('fs').existsSync; | ||
const readFileSync = require('fs').readFileSync; | ||
const basename = require('path').basename; | ||
const getApiDriver = require('./util.js').getApiDriver; | ||
const diffLines = require("diff").diffLines; | ||
@@ -20,3 +21,3 @@ | ||
*/ | ||
export async function commitSingleFile(localFile, projectIdentifier, remoteFile, options) { | ||
async function commitSingleFile(localFile, projectIdentifier, remoteFile, options) { | ||
const VERBOSE = options.verbose || false; | ||
@@ -119,2 +120,4 @@ const FORCE = options.force || false; | ||
return isAscii; | ||
} | ||
} | ||
module.exports.commitSingleFile = commitSingleFile; |
12
index.js
@@ -1,8 +0,4 @@ | ||
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' | ||
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; | ||
module.exports.getApiDriver = require('./util.js').getApiDriver | ||
module.exports.apiTest = require('./util.js').apiTest; | ||
module.exports.GitlabApiDriver = require('./api-driver.js').GitlabApiDriver; | ||
module.exports.commitSingleFile = require('./commit-helper.js').commitSingleFile; |
{ | ||
"name": "gitlab-x", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "GitLab Executor API Interface", | ||
@@ -14,3 +14,2 @@ "repository": "https://github.com/mxcd/gitlab-api", | ||
}, | ||
"type": "module", | ||
"author": "Max Partenfelder", | ||
@@ -17,0 +16,0 @@ "license": "ISC", |
26
util.js
@@ -1,16 +0,16 @@ | ||
import { GitlabApiDriver } from "./api-driver.js"; | ||
const { GitlabApiDriver } = require("./api-driver.js"); | ||
export function trimLeadingSlash(str) { | ||
function trimLeadingSlash(str) { | ||
return str.startsWith("/") ? str.substring(1) : str; | ||
} | ||
export function trimTailingSlash(str) { | ||
function trimTailingSlash(str) { | ||
return str.endsWith("/") ? str.substring(0, str.length-1) : str; | ||
} | ||
export function trimSlashes(str) { | ||
function trimSlashes(str) { | ||
return trimLeadingSlash(trimTailingSlash(str)); | ||
} | ||
export function resolveProjectIdentifier(baseUrl, identifier) { | ||
function resolveProjectIdentifier(baseUrl, identifier) { | ||
if(!isNaN(parseInt(identifier))) { | ||
@@ -29,3 +29,3 @@ return {id: parseInt(identifier)}; | ||
export async function apiTest(args) { | ||
async function apiTest(args) { | ||
if(args.verbose) console.log(`Fetching GitLab Version`); | ||
@@ -42,7 +42,7 @@ const api = getApiDriver(args); | ||
export function getApiDriver(args) { | ||
function getApiDriver(args) { | ||
return new GitlabApiDriver(args.url, args.access_token, args.verbose); | ||
} | ||
export function filterFields(args, obj, fields) { | ||
function filterFields(args, obj, fields) { | ||
const filterSingleObj = (args, obj, fields) => { | ||
@@ -81,2 +81,10 @@ if(fields.length === 1 && !args.json) { | ||
} | ||
} | ||
} | ||
module.exports.trimLeadingSlash = trimLeadingSlash; | ||
module.exports.trimTailingSlash= trimTailingSlash; | ||
module.exports.trimSlashes= trimSlashes; | ||
module.exports.resolveProjectIdentifier= resolveProjectIdentifier; | ||
module.exports.apiTest= apiTest; | ||
module.exports.getApiDriver= getApiDriver; | ||
module.exports.filterFields= filterFields; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23295
492
7
No