diff --git a/packages/git-proxy-cli/index.js b/packages/git-proxy-cli/index.ts old mode 100755 new mode 100644 similarity index 85% rename from packages/git-proxy-cli/index.js rename to packages/git-proxy-cli/index.ts index 66502191f..44d7f418b --- a/packages/git-proxy-cli/index.js +++ b/packages/git-proxy-cli/index.ts @@ -1,9 +1,11 @@ #!/usr/bin/env node -const axios = require('axios'); -const yargs = require('yargs/yargs'); -const { hideBin } = require('yargs/helpers'); -const fs = require('fs'); -const util = require('util'); +import axios from 'axios'; +import yargs from 'yargs/yargs'; +import { hideBin } from 'yargs/helpers'; +import fs from 'fs'; +import util from 'util'; + +import { CommitData, PushData, PushFilters } from './types'; const GIT_PROXY_COOKIE_FILE = 'git-proxy-cookie'; // GitProxy UI HOST and PORT (configurable via environment variable) @@ -19,7 +21,7 @@ axios.defaults.timeout = 30000; * @param {string} username The user name to login with * @param {string} password The password to use for the login */ -async function login(username, password) { +async function login(username: string, password: string) { try { let response = await axios.post( `${baseUrl}/api/auth/login`, @@ -44,7 +46,7 @@ async function login(username, password) { const user = `"${response.data.username}" <${response.data.email}>`; const isAdmin = response.data.admin ? ' (admin)' : ''; console.log(`Login ${user}${isAdmin}: OK`); - } catch (error) { + } catch (error: any) { if (error.response) { console.error(`Error: Login '${username}': '${error.response.status}'`); process.exitCode = 1; @@ -76,7 +78,7 @@ async function login(username, password) { * @param {boolean} filters.rejected - If not null, filters for pushes with * given attribute and status. */ -async function getGitPushes(filters) { +async function getGitPushes(filters: PushFilters) { if (!fs.existsSync(GIT_PROXY_COOKIE_FILE)) { console.error('Error: List: Authentication required'); process.exitCode = 1; @@ -91,40 +93,46 @@ async function getGitPushes(filters) { params: filters, }); - const records = []; - response.data?.forEach((push) => { - const record = {}; - record.id = push.id; - record.timestamp = push.timestamp; - record.url = push.url; - record.allowPush = push.allowPush; - record.authorised = push.authorised; - record.blocked = push.blocked; - record.canceled = push.canceled; - record.error = push.error; - record.rejected = push.rejected; - - record.lastStep = { - stepName: push.lastStep?.stepName, - error: push.lastStep?.error, - errorMessage: push.lastStep?.errorMessage, - blocked: push.lastStep?.blocked, - blockedMessage: push.lastStep?.blockedMessage, + const records: PushData[] = []; + response.data.forEach((push: PushData) => { + const record: PushData = { + id: push.id, + timestamp: push.timestamp, + url: push.url, + allowPush: push.allowPush, + authorised: push.authorised, + blocked: push.blocked, + canceled: push.canceled, + error: push.error, + rejected: push.rejected, }; - record.commitData = []; - push.commitData?.forEach((pushCommitDataRecord) => { - record.commitData.push({ - message: pushCommitDataRecord.message, - committer: pushCommitDataRecord.committer, + if (push.lastStep) { + record.lastStep = { + stepName: push.lastStep?.stepName, + error: push.lastStep?.error, + errorMessage: push.lastStep?.errorMessage, + blocked: push.lastStep?.blocked, + blockedMessage: push.lastStep?.blockedMessage, + }; + } + + if (push.commitData) { + const commitData: CommitData[] = []; + push.commitData.forEach((pushCommitDataRecord: CommitData) => { + commitData.push({ + message: pushCommitDataRecord.message, + committer: pushCommitDataRecord.committer, + }); }); - }); + record.commitData = commitData; + } records.push(record); }); console.log(`${util.inspect(records, false, null, false)}`); - } catch (error) { + } catch (error: any) { // default error const errorMessage = `Error: List: '${error.message}'`; process.exitCode = 2; @@ -136,7 +144,7 @@ async function getGitPushes(filters) { * Authorise git push by ID * @param {string} id The ID of the git push to authorise */ -async function authoriseGitPush(id) { +async function authoriseGitPush(id: string) { if (!fs.existsSync(GIT_PROXY_COOKIE_FILE)) { console.error('Error: Authorise: Authentication required'); process.exitCode = 1; @@ -168,7 +176,7 @@ async function authoriseGitPush(id) { ); console.log(`Authorise: ID: '${id}': OK`); - } catch (error) { + } catch (error: any) { // default error let errorMessage = `Error: Authorise: '${error.message}'`; process.exitCode = 2; @@ -176,8 +184,7 @@ async function authoriseGitPush(id) { if (error.response) { switch (error.response.status) { case 401: - errorMessage = - 'Error: Authorise: Authentication required (401): ' + error?.response?.data?.message; + errorMessage = 'Error: Authorise: Authentication required'; process.exitCode = 3; break; case 404: @@ -193,7 +200,7 @@ async function authoriseGitPush(id) { * Reject git push by ID * @param {string} id The ID of the git push to reject */ -async function rejectGitPush(id) { +async function rejectGitPush(id: string) { if (!fs.existsSync(GIT_PROXY_COOKIE_FILE)) { console.error('Error: Reject: Authentication required'); process.exitCode = 1; @@ -216,7 +223,7 @@ async function rejectGitPush(id) { ); console.log(`Reject: ID: '${id}': OK`); - } catch (error) { + } catch (error: any) { // default error let errorMessage = `Error: Reject: '${error.message}'`; process.exitCode = 2; @@ -224,8 +231,7 @@ async function rejectGitPush(id) { if (error.response) { switch (error.response.status) { case 401: - errorMessage = - 'Error: Reject: Authentication required (401): ' + error?.response?.data?.message; + errorMessage = 'Error: Reject: Authentication required'; process.exitCode = 3; break; case 404: @@ -241,7 +247,7 @@ async function rejectGitPush(id) { * Cancel git push by ID * @param {string} id The ID of the git push to cancel */ -async function cancelGitPush(id) { +async function cancelGitPush(id: string) { if (!fs.existsSync(GIT_PROXY_COOKIE_FILE)) { console.error('Error: Cancel: Authentication required'); process.exitCode = 1; @@ -264,7 +270,7 @@ async function cancelGitPush(id) { ); console.log(`Cancel: ID: '${id}': OK`); - } catch (error) { + } catch (error: any) { // default error let errorMessage = `Error: Cancel: '${error.message}'`; process.exitCode = 2; @@ -272,8 +278,7 @@ async function cancelGitPush(id) { if (error.response) { switch (error.response.status) { case 401: - errorMessage = - 'Error: Cancel: Authentication required (401): ' + error?.response?.data?.message; + errorMessage = 'Error: Cancel: Authentication required'; process.exitCode = 3; break; case 404: @@ -302,7 +307,7 @@ async function logout() { headers: { Cookie: cookies }, }, ); - } catch (error) { + } catch (error: any) { console.log(`Warning: Logout: '${error.message}'`); } } @@ -326,7 +331,7 @@ async function reloadConfig() { await axios.post(`${baseUrl}/api/v1/admin/reload-config`, {}, { headers: { Cookie: cookies } }); console.log('Configuration reloaded successfully'); - } catch (error) { + } catch (error: any) { const errorMessage = `Error: Reload config: '${error.message}'`; process.exitCode = 2; console.error(errorMessage); @@ -341,7 +346,13 @@ async function reloadConfig() { * @param {string} gitAccount The git account for the new user * @param {boolean} [admin=false] Whether the user should be an admin (optional) */ -async function createUser(username, password, email, gitAccount, admin = false) { +async function createUser( + username: string, + password: string, + email: string, + gitAccount: string, + admin: boolean = false, +) { if (!fs.existsSync(GIT_PROXY_COOKIE_FILE)) { console.error('Error: Create User: Authentication required'); process.exitCode = 1; @@ -366,7 +377,7 @@ async function createUser(username, password, email, gitAccount, admin = false) ); console.log(`User '${username}' created successfully`); - } catch (error) { + } catch (error: any) { let errorMessage = `Error: Create User: '${error.message}'`; process.exitCode = 2; @@ -518,8 +529,10 @@ yargs(hideBin(process.argv)) // eslint-disable-line @typescript-eslint/no-unused }) .command({ command: 'reload-config', - description: 'Reload GitProxy configuration without restarting', - action: reloadConfig, + describe: 'Reload GitProxy configuration without restarting', + handler() { + reloadConfig(); + }, }) .command({ command: 'create-user', diff --git a/packages/git-proxy-cli/package.json b/packages/git-proxy-cli/package.json index 8ff84f189..e588f0173 100644 --- a/packages/git-proxy-cli/package.json +++ b/packages/git-proxy-cli/package.json @@ -2,7 +2,9 @@ "name": "@finos/git-proxy-cli", "version": "0.1.0", "description": "Command line interface tool for FINOS GitProxy.", - "bin": "./index.js", + "bin": { + "git-proxy-cli": "./dist/index.js" + }, "dependencies": { "axios": "^1.11.0", "yargs": "^17.7.2", @@ -12,8 +14,10 @@ "chai": "^4.5.0" }, "scripts": { - "lint": "eslint --fix . --ext .js,.jsx", - "test": "NODE_ENV=test ts-mocha --exit --timeout 10000", + "build": "tsc", + "lint": "eslint \"./*.ts\" --fix", + "test:dev": "NODE_ENV=test ts-mocha test/*.ts --exit --timeout 10000", + "test": "npm run build && NODE_ENV=test ts-mocha test/*.ts --exit --timeout 10000", "test-coverage": "nyc npm run test", "test-coverage-ci": "nyc --reporter=lcovonly --reporter=text --reporter=html npm run test" }, diff --git a/packages/git-proxy-cli/test/testCli.test.js b/packages/git-proxy-cli/test/testCli.test.ts similarity index 74% rename from packages/git-proxy-cli/test/testCli.test.js rename to packages/git-proxy-cli/test/testCli.test.ts index 02d067579..1b7b4fa75 100644 --- a/packages/git-proxy-cli/test/testCli.test.js +++ b/packages/git-proxy-cli/test/testCli.test.ts @@ -1,15 +1,13 @@ -/* eslint-disable max-len */ -const helper = require('./testCliUtils'); +import * as helper from './testCliUtils'; +import path from 'path'; -const path = require('path'); +import { setConfigFile } from '../../../src/config/file'; -// set test proxy config file path *before* loading the proxy -require('../../../src/config/file').configFile = path.join( - process.cwd(), - 'test', - 'testCli.proxy.config.json', -); -const service = require('../../../src/service'); +import service from '../../../src/service/index'; +import Proxy from '../../../src/proxy'; +import { Repo } from '../../../src/db/types'; + +setConfigFile(path.join(process.cwd(), 'test', 'testCli.proxy.config.json')); /* test constants */ // push ID which does not exist @@ -28,12 +26,14 @@ const TEST_PASSWORD = 'testpassword'; const TEST_EMAIL = 'jane.doe@email.com'; const TEST_GIT_ACCOUNT = 'testGitAccount'; +const CLI_PATH = 'npx git-proxy-cli'; + describe('test git-proxy-cli', function () { // *** help *** describe(`test git-proxy-cli :: help`, function () { it(`print help if no command or option is given`, async function () { - const cli = `npx -- @finos/git-proxy-cli`; + const cli = `${CLI_PATH}`; const expectedExitCode = 1; const expectedMessages = null; const expectedErrorMessages = [ @@ -45,7 +45,7 @@ describe('test git-proxy-cli', function () { }); it(`print help if invalid command or option is given`, async function () { - const cli = `npx -- @finos/git-proxy-cli invalid --invalid`; + const cli = `${CLI_PATH} invalid --invalid`; const expectedExitCode = 1; const expectedMessages = null; const expectedErrorMessages = [ @@ -57,7 +57,7 @@ describe('test git-proxy-cli', function () { }); it(`print help if "--help" option is given`, async function () { - const cli = `npx -- @finos/git-proxy-cli invalid --help`; + const cli = `${CLI_PATH} invalid --help`; const expectedExitCode = 0; const expectedMessages = ['Commands:', 'Options:']; const expectedErrorMessages = null; @@ -69,7 +69,7 @@ describe('test git-proxy-cli', function () { describe(`test git-proxy-cli :: version`, function () { it(`"--version" option prints version details `, async function () { - const cli = `npx -- @finos/git-proxy-cli --version`; + const cli = `${CLI_PATH} --version`; const expectedExitCode = 0; const expectedMessages = ['0.1.0']; const expectedErrorMessages = null; @@ -81,7 +81,7 @@ describe('test git-proxy-cli', function () { describe('test git-proxy-cli :: configuration', function () { it(`"config" command prints configuration details`, async function () { - const cli = `npx -- @finos/git-proxy-cli config`; + const cli = `${CLI_PATH} config`; const expectedExitCode = 0; const expectedMessages = ['GitProxy URL:']; const expectedErrorMessages = null; @@ -103,7 +103,7 @@ describe('test git-proxy-cli', function () { it('login should fail when server is down', async function () { const username = 'admin'; const password = 'admin'; - const cli = `npx -- @finos/git-proxy-cli login --username ${username} --password ${password}`; + const cli = `${CLI_PATH} login --username ${username} --password ${password}`; const expectedExitCode = 2; const expectedMessages = null; const expectedErrorMessages = [`Error: Login '${username}':`]; @@ -113,12 +113,12 @@ describe('test git-proxy-cli', function () { it('login should fail with invalid credentials', async function () { const username = 'unkn0wn'; const password = 'p4ssw0rd'; - const cli = `npx -- @finos/git-proxy-cli login --username ${username} --password ${password}`; + const cli = `${CLI_PATH} login --username ${username} --password ${password}`; const expectedExitCode = 1; const expectedMessages = null; const expectedErrorMessages = [`Error: Login '${username}': '401'`]; try { - await helper.startServer(service); + await helper.startServer(service as unknown as Proxy); await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages); } finally { await helper.closeServer(service.httpServer); @@ -128,12 +128,12 @@ describe('test git-proxy-cli', function () { it('login shoud be successful with valid credentials (admin)', async function () { const username = 'admin'; const password = 'admin'; - const cli = `npx -- @finos/git-proxy-cli login --username ${username} --password ${password}`; + const cli = `${CLI_PATH} login --username ${username} --password ${password}`; const expectedExitCode = 0; const expectedMessages = [`Login "${username}" (admin): OK`]; const expectedErrorMessages = null; try { - await helper.startServer(service); + await helper.startServer(service as unknown as Proxy); await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages); } finally { await helper.closeServer(service.httpServer); @@ -141,12 +141,12 @@ describe('test git-proxy-cli', function () { }); it('login shoud be successful with valid credentials (non-admin)', async function () { - const cli = `npx -- @finos/git-proxy-cli login --username ${TEST_USER} --password ${TEST_PASSWORD}`; + const cli = `${CLI_PATH} login --username ${TEST_USER} --password ${TEST_PASSWORD}`; const expectedExitCode = 0; const expectedMessages = [`Login "${TEST_USER}" <${TEST_EMAIL}>: OK`]; const expectedErrorMessages = null; try { - await helper.startServer(service); + await helper.startServer(service as unknown as Proxy); await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages); } finally { await helper.closeServer(service.httpServer); @@ -160,7 +160,7 @@ describe('test git-proxy-cli', function () { it('logout shoud succeed when server is down (and not logged in before)', async function () { await helper.removeCookiesFile(); - const cli = `npx -- @finos/git-proxy-cli logout`; + const cli = `${CLI_PATH} logout`; const expectedExitCode = 0; const expectedMessages = [`Logout: OK`]; const expectedErrorMessages = null; @@ -169,13 +169,13 @@ describe('test git-proxy-cli', function () { it('logout should succeed when server is down (but logged in before)', async function () { try { - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); } finally { await helper.closeServer(service.httpServer); } - const cli = `npx -- @finos/git-proxy-cli logout`; + const cli = `${CLI_PATH} logout`; const expectedExitCode = 0; const expectedMessages = [`Logout: OK`]; const expectedErrorMessages = null; @@ -186,11 +186,11 @@ describe('test git-proxy-cli', function () { try { await helper.createCookiesFileWithExpiredCookie(); - const cli = `npx -- @finos/git-proxy-cli logout`; + const cli = `${CLI_PATH} logout`; const expectedExitCode = 0; const expectedMessages = [`Logout: OK`]; const expectedErrorMessages = null; - await helper.startServer(service); + await helper.startServer(service as unknown as Proxy); await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages); } finally { await helper.closeServer(service.httpServer); @@ -199,10 +199,10 @@ describe('test git-proxy-cli', function () { it('logout shoud be successful when authenticated (server is up)', async function () { try { - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); - const cli = `npx -- @finos/git-proxy-cli logout`; + const cli = `${CLI_PATH} logout`; const expectedExitCode = 0; const expectedMessages = [`Logout: OK`]; const expectedErrorMessages = null; @@ -219,7 +219,7 @@ describe('test git-proxy-cli', function () { const pushId = `auth000000000000000000000000000000000000__${Date.now()}`; before(async function () { - await helper.addRepoToDb(TEST_REPO_CONFIG); + await helper.addRepoToDb(TEST_REPO_CONFIG as Repo); await helper.addUserToDb(TEST_USER, TEST_PASSWORD, TEST_EMAIL, TEST_GIT_ACCOUNT); await helper.addGitPushToDb(pushId, TEST_REPO_CONFIG.url, TEST_USER, TEST_EMAIL); }); @@ -233,14 +233,14 @@ describe('test git-proxy-cli', function () { it('attempt to authorise should fail when server is down', async function () { try { // start server -> login -> stop server - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); } finally { await helper.closeServer(service.httpServer); } const id = GHOST_PUSH_ID; - const cli = `npx -- @finos/git-proxy-cli authorise --id ${id}`; + const cli = `${CLI_PATH} authorise --id ${id}`; const expectedExitCode = 2; const expectedMessages = null; const expectedErrorMessages = ['Error: Authorise:']; @@ -251,7 +251,7 @@ describe('test git-proxy-cli', function () { await helper.removeCookiesFile(); const id = GHOST_PUSH_ID; - const cli = `npx -- @finos/git-proxy-cli authorise --id ${id}`; + const cli = `${CLI_PATH} authorise --id ${id}`; const expectedExitCode = 1; const expectedMessages = null; const expectedErrorMessages = ['Error: Authorise: Authentication required']; @@ -261,9 +261,9 @@ describe('test git-proxy-cli', function () { it('attempt to authorise should fail when not authenticated (server restarted)', async function () { try { await helper.createCookiesFileWithExpiredCookie(); - await helper.startServer(service); + await helper.startServer(service as unknown as Proxy); const id = pushId; - const cli = `npx -- @finos/git-proxy-cli authorise --id ${id}`; + const cli = `${CLI_PATH} authorise --id ${id}`; const expectedExitCode = 3; const expectedMessages = null; const expectedErrorMessages = ['Error: Authorise: Authentication required']; @@ -275,11 +275,11 @@ describe('test git-proxy-cli', function () { it('attempt to authorise should fail when git push ID not found', async function () { try { - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); const id = GHOST_PUSH_ID; - const cli = `npx -- @finos/git-proxy-cli authorise --id ${id}`; + const cli = `${CLI_PATH} authorise --id ${id}`; const expectedExitCode = 4; const expectedMessages = null; const expectedErrorMessages = [`Error: Authorise: ID: '${id}': Not Found`]; @@ -296,7 +296,7 @@ describe('test git-proxy-cli', function () { const pushId = `cancel0000000000000000000000000000000000__${Date.now()}`; before(async function () { - await helper.addRepoToDb(TEST_REPO_CONFIG); + await helper.addRepoToDb(TEST_REPO_CONFIG as Repo); await helper.addUserToDb(TEST_USER, TEST_PASSWORD, TEST_EMAIL, TEST_GIT_ACCOUNT); await helper.addGitPushToDb(pushId, TEST_USER, TEST_EMAIL, TEST_REPO); }); @@ -310,14 +310,14 @@ describe('test git-proxy-cli', function () { it('attempt to cancel should fail when server is down', async function () { try { // start server -> login -> stop server - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); } finally { await helper.closeServer(service.httpServer); } const id = GHOST_PUSH_ID; - const cli = `npx -- @finos/git-proxy-cli cancel --id ${id}`; + const cli = `${CLI_PATH} cancel --id ${id}`; const expectedExitCode = 2; const expectedMessages = null; const expectedErrorMessages = ['Error: Cancel:']; @@ -328,7 +328,7 @@ describe('test git-proxy-cli', function () { await helper.removeCookiesFile(); const id = GHOST_PUSH_ID; - const cli = `npx -- @finos/git-proxy-cli cancel --id ${id}`; + const cli = `${CLI_PATH} cancel --id ${id}`; const expectedExitCode = 1; const expectedMessages = null; const expectedErrorMessages = ['Error: Cancel: Authentication required']; @@ -338,9 +338,9 @@ describe('test git-proxy-cli', function () { it('attempt to cancel should fail when not authenticated (server restarted)', async function () { try { await helper.createCookiesFileWithExpiredCookie(); - await helper.startServer(service); + await helper.startServer(service as unknown as Proxy); const id = pushId; - const cli = `npx -- @finos/git-proxy-cli cancel --id ${id}`; + const cli = `${CLI_PATH} cancel --id ${id}`; const expectedExitCode = 3; const expectedMessages = null; const expectedErrorMessages = ['Error: Cancel: Authentication required']; @@ -353,11 +353,11 @@ describe('test git-proxy-cli', function () { it('attempt to cancel should fail when git push ID not found', async function () { try { - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); const id = GHOST_PUSH_ID; - const cli = `npx -- @finos/git-proxy-cli cancel --id ${id}`; + const cli = `${CLI_PATH} cancel --id ${id}`; const expectedExitCode = 4; const expectedMessages = null; const expectedErrorMessages = [`Error: Cancel: ID: '${id}': Not Found`]; @@ -374,13 +374,13 @@ describe('test git-proxy-cli', function () { it('attempt to ls should fail when server is down', async function () { try { // start server -> login -> stop server - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); } finally { await helper.closeServer(service.httpServer); } - const cli = `npx -- @finos/git-proxy-cli ls`; + const cli = `${CLI_PATH} ls`; const expectedExitCode = 2; const expectedMessages = null; const expectedErrorMessages = ['Error: List:']; @@ -390,7 +390,7 @@ describe('test git-proxy-cli', function () { it('attempt to ls should fail when not authenticated', async function () { await helper.removeCookiesFile(); - const cli = `npx -- @finos/git-proxy-cli ls`; + const cli = `${CLI_PATH} ls`; const expectedExitCode = 1; const expectedMessages = null; const expectedErrorMessages = ['Error: List: Authentication required']; @@ -399,10 +399,10 @@ describe('test git-proxy-cli', function () { it('attempt to ls should fail when invalid option given', async function () { try { - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); - const cli = `npx -- @finos/git-proxy-cli ls --invalid`; + const cli = `${CLI_PATH} ls --invalid`; const expectedExitCode = 1; const expectedMessages = null; const expectedErrorMessages = ['Options:', 'Unknown argument: invalid']; @@ -419,7 +419,7 @@ describe('test git-proxy-cli', function () { const pushId = `reject0000000000000000000000000000000000__${Date.now()}`; before(async function () { - await helper.addRepoToDb(TEST_REPO_CONFIG); + await helper.addRepoToDb(TEST_REPO_CONFIG as Repo); await helper.addUserToDb(TEST_USER, TEST_PASSWORD, TEST_EMAIL, TEST_GIT_ACCOUNT); await helper.addGitPushToDb(pushId, TEST_REPO_CONFIG.url, TEST_USER, TEST_EMAIL); }); @@ -433,14 +433,14 @@ describe('test git-proxy-cli', function () { it('attempt to reject should fail when server is down', async function () { try { // start server -> login -> stop server - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); } finally { await helper.closeServer(service.httpServer); } const id = GHOST_PUSH_ID; - const cli = `npx -- @finos/git-proxy-cli reject --id ${id}`; + const cli = `${CLI_PATH} reject --id ${id}`; const expectedExitCode = 2; const expectedMessages = null; const expectedErrorMessages = ['Error: Reject:']; @@ -451,7 +451,7 @@ describe('test git-proxy-cli', function () { await helper.removeCookiesFile(); const id = GHOST_PUSH_ID; - const cli = `npx -- @finos/git-proxy-cli reject --id ${id}`; + const cli = `${CLI_PATH} reject --id ${id}`; const expectedExitCode = 1; const expectedMessages = null; const expectedErrorMessages = ['Error: Reject: Authentication required']; @@ -461,9 +461,9 @@ describe('test git-proxy-cli', function () { it('attempt to reject should fail when not authenticated (server restarted)', async function () { try { await helper.createCookiesFileWithExpiredCookie(); - await helper.startServer(service); + await helper.startServer(service as unknown as Proxy); const id = pushId; - const cli = `npx -- @finos/git-proxy-cli reject --id ${id}`; + const cli = `${CLI_PATH} reject --id ${id}`; const expectedExitCode = 3; const expectedMessages = null; const expectedErrorMessages = ['Error: Reject: Authentication required']; @@ -475,11 +475,11 @@ describe('test git-proxy-cli', function () { it('attempt to reject should fail when git push ID not found', async function () { try { - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); const id = GHOST_PUSH_ID; - const cli = `npx -- @finos/git-proxy-cli reject --id ${id}`; + const cli = `${CLI_PATH} reject --id ${id}`; const expectedExitCode = 4; const expectedMessages = null; const expectedErrorMessages = [`Error: Reject: ID: '${id}': Not Found`]; @@ -504,13 +504,13 @@ describe('test git-proxy-cli', function () { it('attempt to create user should fail when server is down', async function () { try { // start server -> login -> stop server - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); } finally { await helper.closeServer(service.httpServer); } - const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --password newpass --email new@email.com --gitAccount newgit`; + const cli = `${CLI_PATH} create-user --username newuser --password newpass --email new@email.com --gitAccount newgit`; const expectedExitCode = 2; const expectedMessages = null; const expectedErrorMessages = ['Error: Create User:']; @@ -520,7 +520,7 @@ describe('test git-proxy-cli', function () { it('attempt to create user should fail when not authenticated', async function () { await helper.removeCookiesFile(); - const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --password newpass --email new@email.com --gitAccount newgit`; + const cli = `${CLI_PATH} create-user --username newuser --password newpass --email new@email.com --gitAccount newgit`; const expectedExitCode = 1; const expectedMessages = null; const expectedErrorMessages = ['Error: Create User: Authentication required']; @@ -529,12 +529,10 @@ describe('test git-proxy-cli', function () { it('attempt to create user should fail when not admin', async function () { try { - await helper.startServer(service); - await helper.runCli( - `npx -- @finos/git-proxy-cli login --username testuser --password testpassword`, - ); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username testuser --password testpassword`); - const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --password newpass --email new@email.com --gitAccount newgit`; + const cli = `${CLI_PATH} create-user --username newuser --password newpass --email new@email.com --gitAccount newgit`; const expectedExitCode = 3; const expectedMessages = null; const expectedErrorMessages = ['Error: Create User: Authentication required']; @@ -546,10 +544,10 @@ describe('test git-proxy-cli', function () { it('attempt to create user should fail with missing required fields', async function () { try { - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); - const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --password "" --email new@email.com --gitAccount newgit`; + const cli = `${CLI_PATH} create-user --username newuser --password "" --email new@email.com --gitAccount newgit`; const expectedExitCode = 4; const expectedMessages = null; const expectedErrorMessages = ['Error: Create User: Missing required fields']; @@ -562,10 +560,10 @@ describe('test git-proxy-cli', function () { it('should successfully create a new user', async function () { const uniqueUsername = `newuser_${Date.now()}`; try { - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); - const cli = `npx -- @finos/git-proxy-cli create-user --username ${uniqueUsername} --password newpass --email new@email.com --gitAccount newgit`; + const cli = `${CLI_PATH} create-user --username ${uniqueUsername} --password newpass --email new@email.com --gitAccount newgit`; const expectedExitCode = 0; const expectedMessages = [`User '${uniqueUsername}' created successfully`]; const expectedErrorMessages = null; @@ -573,7 +571,7 @@ describe('test git-proxy-cli', function () { // Verify we can login with the new user await helper.runCli( - `npx -- @finos/git-proxy-cli login --username ${uniqueUsername} --password newpass`, + `${CLI_PATH} login --username ${uniqueUsername} --password newpass`, 0, [`Login "${uniqueUsername}" : OK`], null, @@ -583,7 +581,7 @@ describe('test git-proxy-cli', function () { // Clean up the created user try { await helper.removeUserFromDb(uniqueUsername); - } catch (error) { + } catch (error: any) { // Ignore cleanup errors } } @@ -592,10 +590,10 @@ describe('test git-proxy-cli', function () { it('should successfully create a new admin user', async function () { const uniqueUsername = `newadmin_${Date.now()}`; try { - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); - const cli = `npx -- @finos/git-proxy-cli create-user --username ${uniqueUsername} --password newpass --email ${uniqueUsername}@email.com --gitAccount newgit --admin`; + const cli = `${CLI_PATH} create-user --username ${uniqueUsername} --password newpass --email ${uniqueUsername}@email.com --gitAccount newgit --admin`; const expectedExitCode = 0; const expectedMessages = [`User '${uniqueUsername}' created successfully`]; const expectedErrorMessages = null; @@ -603,7 +601,7 @@ describe('test git-proxy-cli', function () { // Verify we can login with the new admin user await helper.runCli( - `npx -- @finos/git-proxy-cli login --username ${uniqueUsername} --password newpass`, + `${CLI_PATH} login --username ${uniqueUsername} --password newpass`, 0, [`Login "${uniqueUsername}" <${uniqueUsername}@email.com> (admin): OK`], null, @@ -613,7 +611,7 @@ describe('test git-proxy-cli', function () { // Clean up the created user try { await helper.removeUserFromDb(uniqueUsername); - } catch (error) { + } catch (error: any) { console.error('Error cleaning up user', error); } } @@ -626,7 +624,7 @@ describe('test git-proxy-cli', function () { const pushId = `0000000000000000000000000000000000000000__${Date.now()}`; before(async function () { - await helper.addRepoToDb(TEST_REPO_CONFIG); + await helper.addRepoToDb(TEST_REPO_CONFIG as Repo); await helper.addUserToDb(TEST_USER, TEST_PASSWORD, TEST_EMAIL, TEST_GIT_ACCOUNT); await helper.addGitPushToDb(pushId, TEST_REPO_CONFIG.url, TEST_USER, TEST_EMAIL); }); @@ -639,10 +637,10 @@ describe('test git-proxy-cli', function () { it('attempt to ls should list existing push', async function () { try { - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); - const cli = `npx -- @finos/git-proxy-cli ls --authorised false --blocked true --canceled false --rejected false`; + const cli = `${CLI_PATH} ls --authorised false --blocked true --canceled false --rejected false`; const expectedExitCode = 0; const expectedMessages = [ pushId, @@ -662,10 +660,10 @@ describe('test git-proxy-cli', function () { it('attempt to ls should not list existing push when filtered for authorised', async function () { try { - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); - const cli = `npx -- @finos/git-proxy-cli ls --authorised true`; + const cli = `${CLI_PATH} ls --authorised true`; const expectedExitCode = 0; const expectedMessages = ['[]']; const expectedErrorMessages = null; @@ -677,10 +675,10 @@ describe('test git-proxy-cli', function () { it('attempt to ls should not list existing push when filtered for canceled', async function () { try { - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); - const cli = `npx -- @finos/git-proxy-cli ls --canceled true`; + const cli = `${CLI_PATH} ls --canceled true`; const expectedExitCode = 0; const expectedMessages = ['[]']; const expectedErrorMessages = null; @@ -692,10 +690,10 @@ describe('test git-proxy-cli', function () { it('attempt to ls should not list existing push when filtered for rejected', async function () { try { - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); - const cli = `npx -- @finos/git-proxy-cli ls --rejected true`; + const cli = `${CLI_PATH} ls --rejected true`; const expectedExitCode = 0; const expectedMessages = ['[]']; const expectedErrorMessages = null; @@ -707,10 +705,10 @@ describe('test git-proxy-cli', function () { it('attempt to ls should not list existing push when filtered for non-blocked', async function () { try { - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); - const cli = `npx -- @finos/git-proxy-cli ls --blocked false`; + const cli = `${CLI_PATH} ls --blocked false`; const expectedExitCode = 0; const expectedMessages = ['[]']; const expectedErrorMessages = null; @@ -722,22 +720,22 @@ describe('test git-proxy-cli', function () { it('authorise push and test if appears on authorised list', async function () { try { - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); - let cli = `npx -- @finos/git-proxy-cli ls --authorised true --canceled false --rejected false`; + let cli = `${CLI_PATH} ls --authorised true --canceled false --rejected false`; let expectedExitCode = 0; let expectedMessages = ['[]']; let expectedErrorMessages = null; await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages); - cli = `npx -- @finos/git-proxy-cli authorise --id ${pushId}`; + cli = `${CLI_PATH} authorise --id ${pushId}`; expectedExitCode = 0; expectedMessages = [`Authorise: ID: '${pushId}': OK`]; expectedErrorMessages = null; await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages); - cli = `npx -- @finos/git-proxy-cli ls --authorised true --canceled false --rejected false`; + cli = `${CLI_PATH} ls --authorised true --canceled false --rejected false`; expectedExitCode = 0; expectedMessages = [pushId, TEST_REPO]; expectedErrorMessages = null; @@ -749,22 +747,22 @@ describe('test git-proxy-cli', function () { it('reject push and test if appears on rejected list', async function () { try { - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); - let cli = `npx -- @finos/git-proxy-cli ls --authorised false --canceled false --rejected true`; + let cli = `${CLI_PATH} ls --authorised false --canceled false --rejected true`; let expectedExitCode = 0; let expectedMessages = ['[]']; let expectedErrorMessages = null; await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages); - cli = `npx -- @finos/git-proxy-cli reject --id ${pushId}`; + cli = `${CLI_PATH} reject --id ${pushId}`; expectedExitCode = 0; expectedMessages = [`Reject: ID: '${pushId}': OK`]; expectedErrorMessages = null; await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages); - cli = `npx -- @finos/git-proxy-cli ls --authorised false --canceled false --rejected true`; + cli = `${CLI_PATH} ls --authorised false --canceled false --rejected true`; expectedExitCode = 0; expectedMessages = [pushId, TEST_REPO]; expectedErrorMessages = null; @@ -776,22 +774,22 @@ describe('test git-proxy-cli', function () { it('cancel push and test if appears on canceled list', async function () { try { - await helper.startServer(service); - await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); + await helper.startServer(service as unknown as Proxy); + await helper.runCli(`${CLI_PATH} login --username admin --password admin`); - let cli = `npx -- @finos/git-proxy-cli ls --authorised false --canceled true --rejected false`; + let cli = `${CLI_PATH} ls --authorised false --canceled true --rejected false`; let expectedExitCode = 0; let expectedMessages = ['[]']; let expectedErrorMessages = null; await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages); - cli = `npx -- @finos/git-proxy-cli cancel --id ${pushId}`; + cli = `${CLI_PATH} cancel --id ${pushId}`; expectedExitCode = 0; expectedMessages = [`Cancel: ID: '${pushId}': OK`]; expectedErrorMessages = null; await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages); - cli = `npx -- @finos/git-proxy-cli ls --authorised false --canceled true --rejected false`; + cli = `${CLI_PATH} ls --authorised false --canceled true --rejected false`; expectedExitCode = 0; expectedMessages = [pushId, TEST_REPO]; expectedErrorMessages = null; diff --git a/packages/git-proxy-cli/test/testCliUtils.js b/packages/git-proxy-cli/test/testCliUtils.ts similarity index 76% rename from packages/git-proxy-cli/test/testCliUtils.js rename to packages/git-proxy-cli/test/testCliUtils.ts index aec7961ba..dfc88311f 100644 --- a/packages/git-proxy-cli/test/testCliUtils.js +++ b/packages/git-proxy-cli/test/testCliUtils.ts @@ -1,13 +1,17 @@ -const fs = require('fs'); -const util = require('util'); -const { exec } = require('child_process'); -const execAsync = util.promisify(exec); -const { expect } = require('chai'); +import fs from 'fs'; +import util from 'util'; +import { exec } from 'child_process'; +import { expect } from 'chai'; + +import Proxy from '../../../src/proxy'; +import { Action } from '../../../src/proxy/actions/Action'; +import { Step } from '../../../src/proxy/actions/Step'; +import { exec as execProcessor } from '../../../src/proxy/processors/push-action/audit'; +import * as db from '../../../src/db'; +import { Server } from 'http'; +import { Repo } from '../../../src/db/types'; -const actions = require('../../../src/proxy/actions/Action'); -const steps = require('../../../src/proxy/actions/Step'); -const processor = require('../../../src/proxy/processors/push-action/audit'); -const db = require('../../../src/db'); +const execAsync = util.promisify(exec); // cookie file name const GIT_PROXY_COOKIE_FILE = 'git-proxy-cookie'; @@ -26,11 +30,11 @@ const GIT_PROXY_COOKIE_FILE = 'git-proxy-cookie'; * match the `expectedExitCode`. */ async function runCli( - cli, - expectedExitCode = 0, - expectedMessages = null, - expectedErrorMessages = null, - debug = true, + cli: string, + expectedExitCode: number = 0, + expectedMessages: string[] | null = null, + expectedErrorMessages: string[] | null = null, + debug: boolean = true, ) { try { console.log(`cli: '${cli}'`); @@ -50,7 +54,7 @@ async function runCli( expect(stderr).to.include(expectedErrorMessage); }); } - } catch (error) { + } catch (error: any) { const exitCode = error.code; if (!exitCode) { // an AssertionError is thrown from failing some of the expectations @@ -81,11 +85,11 @@ async function runCli( /** * Starts the server. - * @param {Object} service - The GitProxy API service to be started. + * @param {Proxy} service - The GitProxy API service to be started. * @return {Promise} A promise that resolves when the service has * successfully started. Does not return any value upon resolution. */ -async function startServer(service) { +async function startServer(service: Proxy) { await service.start(); } @@ -104,8 +108,8 @@ async function startServer(service) { * @throws {Error} If the server cannot be closed properly or if an error * occurs during the close operation. */ -async function closeServer(server, waitTime = 0) { - return new Promise((resolve, reject) => { +async function closeServer(server: Server, waitTime: number = 0) { + return new Promise((resolve, reject) => { server.closeAllConnections(); server.close((err) => { if (err) { @@ -147,14 +151,14 @@ async function removeCookiesFile() { * @param {object} newRepo The new repo attributes. * @param {boolean} debug Print debug messages to console if true. */ -async function addRepoToDb(newRepo, debug = false) { +async function addRepoToDb(newRepo: Repo, debug = false) { const repos = await db.getRepos(); const found = repos.find((y) => y.project === newRepo.project && newRepo.name === y.name); if (!found) { await db.createRepo(newRepo); const repo = await db.getRepoByUrl(newRepo.url); - await db.addUserCanPush(repo._id, 'admin'); - await db.addUserCanAuthorise(repo._id, 'admin'); + await db.addUserCanPush(repo?._id || '', 'admin'); + await db.addUserCanAuthorise(repo?._id || '', 'admin'); if (debug) { console.log(`New repo added to database: ${newRepo}`); } @@ -169,9 +173,9 @@ async function addRepoToDb(newRepo, debug = false) { * Removes a repo from the DB. * @param {string} repoUrl The url of the repo to remove. */ -async function removeRepoFromDb(repoUrl) { +async function removeRepoFromDb(repoUrl: string) { const repo = await db.getRepoByUrl(repoUrl); - await db.deleteRepo(repo._id); + await db.deleteRepo(repo?._id || ''); } /** @@ -182,17 +186,23 @@ async function removeRepoFromDb(repoUrl) { * @param {string} userEmail The email of the user who pushed the git push. * @param {boolean} debug Flag to enable logging for debugging. */ -async function addGitPushToDb(id, repoUrl, user = null, userEmail = null, debug = false) { - const action = new actions.Action( +async function addGitPushToDb( + id: string, + repoUrl: string, + user: string | null = null, + userEmail: string | null = null, + debug: boolean = false, +) { + const action = new Action( id, 'push', // type 'get', // method Date.now(), // timestamp repoUrl, ); - action.user = user; - action.userEmail = userEmail; - const step = new steps.Step( + action.user = user || ''; + action.userEmail = userEmail || ''; + const step = new Step( 'authBlock', // stepName false, // error null, // errorMessage @@ -208,10 +218,12 @@ async function addGitPushToDb(id, repoUrl, user = null, userEmail = null, debug committer: 'committer', commitTs: 'commitTs', message: 'message', + authorEmail: 'authorEmail', + committerEmail: 'committerEmail', }); action.commitData = commitData; action.addStep(step); - const result = await processor.exec(null, action); + const result = await execProcessor(null, action); if (debug) { console.log(`New git push added to DB: ${util.inspect(result)}`); } @@ -221,7 +233,7 @@ async function addGitPushToDb(id, repoUrl, user = null, userEmail = null, debug * Removes a push from the DB * @param {string} id */ -async function removeGitPushFromDb(id) { +async function removeGitPushFromDb(id: string) { await db.deletePush(id); } @@ -234,7 +246,14 @@ async function removeGitPushFromDb(id) { * @param {boolean} admin Flag to make the user administrator. * @param {boolean} debug Flag to enable logging for debugging. */ -async function addUserToDb(username, password, email, gitAccount, admin = false, debug = false) { +async function addUserToDb( + username: string, + password: string, + email: string, + gitAccount: string, + admin: boolean = false, + debug: boolean = false, +) { const result = await db.createUser(username, password, email, gitAccount, admin); if (debug) { console.log(`New user added to DB: ${util.inspect(result)}`); @@ -245,20 +264,20 @@ async function addUserToDb(username, password, email, gitAccount, admin = false, * Remove a user record from the database if present. * @param {string} username The user name. */ -async function removeUserFromDb(username) { +async function removeUserFromDb(username: string) { await db.deleteUser(username); } -module.exports = { - runCli: runCli, - startServer: startServer, - closeServer: closeServer, - addRepoToDb: addRepoToDb, - removeRepoFromDb: removeRepoFromDb, - addGitPushToDb: addGitPushToDb, - removeGitPushFromDb: removeGitPushFromDb, - addUserToDb: addUserToDb, - removeUserFromDb: removeUserFromDb, - createCookiesFileWithExpiredCookie: createCookiesFileWithExpiredCookie, - removeCookiesFile: removeCookiesFile, +export { + runCli, + startServer, + closeServer, + addRepoToDb, + removeRepoFromDb, + addGitPushToDb, + removeGitPushFromDb, + addUserToDb, + removeUserFromDb, + createCookiesFileWithExpiredCookie, + removeCookiesFile, }; diff --git a/packages/git-proxy-cli/tsconfig.json b/packages/git-proxy-cli/tsconfig.json index 236bfabc5..5f1c37145 100644 --- a/packages/git-proxy-cli/tsconfig.json +++ b/packages/git-proxy-cli/tsconfig.json @@ -5,14 +5,18 @@ "allowJs": true, "checkJs": false, "jsx": "react-jsx", - "moduleResolution": "Node", + "moduleResolution": "nodenext", "strict": true, - "noEmit": true, + "declaration": true, "skipLibCheck": true, "isolatedModules": true, - "module": "CommonJS", + "module": "NodeNext", "esModuleInterop": true, - "allowSyntheticDefaultImports": true + "allowSyntheticDefaultImports": true, + "resolveJsonModule": true, + "outDir": "./dist", + "rootDir": "." }, - "include": ["index.js", "test", "coverage"] + "include": ["index.ts", "types.ts"], + "exclude": ["src/config/**/*", "src/db/**/*", "src/proxy/**/*", "src/service/**/*", "src/ui/**/*"] } diff --git a/packages/git-proxy-cli/types.ts b/packages/git-proxy-cli/types.ts new file mode 100644 index 000000000..22feb22b9 --- /dev/null +++ b/packages/git-proxy-cli/types.ts @@ -0,0 +1,35 @@ +export interface PushFilters { + allowPush?: boolean; + authorised?: boolean; + blocked?: boolean; + canceled?: boolean; + error?: boolean; + rejected?: boolean; +} + +export interface PushData { + id: string; + timestamp: number; + url: string; + allowPush: boolean; + authorised: boolean; + blocked: boolean; + canceled: boolean; + error: boolean; + rejected: boolean; + lastStep?: PushStep; + commitData?: CommitData[]; +} + +export interface PushStep { + stepName: string; + error: boolean; + errorMessage: string; + blocked: boolean; + blockedMessage: string; +} + +export interface CommitData { + message: string; + committer: string; +}