You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP →

@codefresh-io/cf-git-providers

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codefresh-io/cf-git-providers - npm Package Compare versions

Comparing version

to
0.6.0

@@ -24,3 +24,3 @@ import { Provider, Repository, Branch, Webhook, ProviderName, User, PullRequest, RepositoryPermission, PermissionScopes, GitAuth, RefreshTokenHandler } from './types';

});
createRepository(opt: {
createRepository(opts: {
owner: string;

@@ -36,3 +36,3 @@ repo: string;

private getProjectKey;
private getProjectByKey;
private verifyProjectKey;
getName(): ProviderName;

@@ -54,5 +54,8 @@ fetchRawFile(opts: {

}): Promise<Repository>;
listBranches(): Promise<Branch[]>;
listBranches(opts: {
owner: string;
repo: string;
}): Promise<Branch[]>;
listRepositoriesForOwner(): Promise<Repository[]>;
createRepositoryWebhook(opt: {
createRepositoryWebhook(opts: {
owner: string;

@@ -63,9 +66,7 @@ repo: string;

}): Promise<Webhook>;
listWebhooks(opt: {
listWebhooks(opts: {
owner: string;
repo: string;
limit?: number;
page?: number;
}): Promise<Webhook[]>;
deleteRepositoryWebhook(opt: {
deleteRepositoryWebhook(opts: {
owner: string;

@@ -75,14 +76,10 @@ repo: string;

}): Promise<void>;
listRepositoriesWithAffiliation(opt: {
listRepositoriesWithAffiliation(opts: {
affiliation: string;
sort?: 'name' | 'pushed' | 'created';
direction?: 'desc' | 'asc';
limit?: number;
page?: number;
}): Promise<Repository[]>;
listOrganizations(opt: {
listOrganizations(opts: {
limit?: number;
page?: number;
}): Promise<string[]>;
getRepositoryPermissions(opt: {
getRepositoryPermissions(opts: {
owner: string;

@@ -92,3 +89,3 @@ repo: string;

listRepositoriesForOrganization(): Promise<Repository[]>;
createCommitStatus(opt: {
createCommitStatus(opts: {
owner: string;

@@ -102,3 +99,3 @@ repo: string;

}): Promise<void>;
getUser(opt?: {
getUser(opts?: {
username?: string;

@@ -109,3 +106,3 @@ }): Promise<User>;

getPullRequest(): Promise<PullRequest>;
assertApiScopes(opt: {
assertApiScopes(opts: {
scopes: PermissionScopes[];

@@ -112,0 +109,0 @@ repoUrl?: string;

@@ -148,7 +148,5 @@ "use strict";

}
async createRepository(opt) {
const isOwner = opt.owner.startsWith('~');
const projectKey = isOwner
? opt.owner
: await this.getProjectKey(opt.owner);
async createRepository(opts) {
const isOwner = opts.owner.startsWith('~');
const projectKey = await this.getProjectKey(opts.owner);
const [err, res] = await helpers_1.to(this.performAPICall({

@@ -159,3 +157,3 @@ api: `${isOwner ? 'users' : 'projects'}/${projectKey}/repos?avatarSize=${exports.avatarSize}`,

data: {
name: opt.repo,
name: opts.repo,
scmId: 'git'

@@ -165,3 +163,3 @@ }

if (err) {
throw new CFError(`Failed to create repository ${opt.repo} in ${projectKey} , err: ${JSON.stringify(err)}`);
throw new CFError(`Failed to create repository ${opts.repo} in ${projectKey} , err: ${JSON.stringify(err)}`);
}

@@ -258,7 +256,14 @@ return _toRepo(res.body);

async getProjectKey(projectName) {
const [projectByKeyError] = await helpers_1.to(this.getProjectByKey(projectName));
if (!projectByKeyError) {
if (projectName.startsWith('~')) {
return projectName;
}
const [getProjErr, proj] = await helpers_1.to(this.paginateForResult({
const nameExists = await this.verifyProjectKey(projectName);
if (nameExists) {
return projectName;
}
const isUsername = await this.verifyProjectKey('~' + projectName);
if (isUsername) {
return '~' + projectName;
}
const proj = await this.paginateForResult({
api: `projects`,

@@ -269,20 +274,19 @@ json: true,

},
}, (project) => project.name === projectName));
if (getProjErr) {
throw new CFError(`Failed to get project "${projectName}", with: ${getProjErr}`);
}
}, (project) => project.name === projectName);
if (!proj) {
throw new CFError(`Project with name "${projectName}" was not found. To use the user-centric api add the "~" prefix: "~${projectName}"`);
throw new CFError('Project was not found');
}
return proj.key;
}
async getProjectByKey(projectKey) {
const [getProjErr, proj] = await helpers_1.to(this.performAPICall({
api: `projects/${projectKey}`,
json: true,
}));
if (getProjErr) {
throw new CFError(`Failed to get project with key "${projectKey}", with: ${getProjErr}`);
async verifyProjectKey(projectKey) {
try {
const res = await this.performAPICall({
api: `projects/${projectKey}`,
json: true,
});
return res.statusCode === 200;
}
return proj.body;
catch (error) {
throw new CFError(`Failed to get project with key "${projectKey}", error: ${error}`);
}
}

@@ -293,5 +297,3 @@ getName() {

async fetchRawFile(opts) {
const projectKey = opts.owner.startsWith('~')
? opts.owner
: await this.getProjectKey(opts.owner);
const projectKey = await this.getProjectKey(opts.owner);
const lines = [];

@@ -324,5 +326,3 @@ let start = 0;

async getBranch(opts) {
const projectKey = opts.owner.startsWith('~')
? opts.owner
: await this.getProjectKey(opts.owner);
const projectKey = await this.getProjectKey(opts.owner);
const [getBranchErr, branch] = await helpers_1.to(this.paginateForResult({

@@ -346,5 +346,3 @@ apiVersion: ApiVersions.V1,

async getRepository(opts) {
const projectKey = opts.owner.startsWith('~')
? opts.owner
: await this.getProjectKey(opts.owner);
const projectKey = await this.getProjectKey(opts.owner);
const [repo, lastCommit, defaultBranch] = await Promise.all([

@@ -378,14 +376,25 @@ this.performAPICall({

}
async listBranches() {
throw new Error('Method not implemented.');
async listBranches(opts) {
try {
const projectKey = await this.getProjectKey(opts.owner);
const branches = await this.paginateForResult({
api: `projects/${projectKey}/repos/${opts.repo}/branches`,
qs: {
details: String(true),
},
json: true,
});
return branches.map(_toBranch);
}
catch (error) {
throw new CFError(`Failed list branches: ${JSON.stringify(opts)}, err: ${JSON.stringify(error)}`);
}
}
async listRepositoriesForOwner() {
throw new Error('Method not implemented.');
throw new Error('Method listRepositoriesForOwner not implemented.');
}
async createRepositoryWebhook(opt) {
const projectKey = opt.owner.startsWith('~')
? opt.owner
: await this.getProjectKey(opt.owner);
async createRepositoryWebhook(opts) {
const projectKey = await this.getProjectKey(opts.owner);
const [err, res] = await helpers_1.to(this.performAPICall({
api: `projects/${projectKey}/repos/${opt.repo}/webhooks`,
api: `projects/${projectKey}/repos/${opts.repo}/webhooks`,
method: 'POST',

@@ -409,5 +418,5 @@ json: true,

configuration: {
secret: opt.secret,
secret: opts.secret,
},
url: opt.endpoint,
url: opts.endpoint,
active: true,

@@ -417,31 +426,27 @@ },

if (err) {
throw new CFError(`Failed to create repository webhooks: ${JSON.stringify(opt)}, err: ${JSON.stringify(err)}`);
throw new CFError(`Failed to create repository webhooks: ${JSON.stringify(opts)}, err: ${JSON.stringify(err)}`);
}
if (res.statusCode >= 400) {
throw new CFError(`Failed to create repository webhooks: ${JSON.stringify(opt)}, status code: ${res.statusCode}, err: ${_extractErrorFromResponse(res)}`);
throw new CFError(`Failed to create repository webhooks: ${JSON.stringify(opts)}, status code: ${res.statusCode}, err: ${_extractErrorFromResponse(res)}`);
}
return _toWebhook(opt.owner, opt.repo, res.body);
return _toWebhook(opts.owner, opts.repo, res.body);
}
async listWebhooks(opt) {
const projectKey = opt.owner.startsWith('~')
? opt.owner
: await this.getProjectKey(opt.owner);
async listWebhooks(opts) {
const projectKey = await this.getProjectKey(opts.owner);
const [getHooksErr, hooks] = await helpers_1.to(this.paginateForResult({
api: `projects/${projectKey}/repos/${opt.repo}/webhooks`,
api: `projects/${projectKey}/repos/${opts.repo}/webhooks`,
json: true,
}));
if (getHooksErr) {
throw new CFError(`Failed to list repository webhooks: ${JSON.stringify(opt)}, err: ${JSON.stringify(getHooksErr)}`);
throw new CFError(`Failed to list repository webhooks: ${JSON.stringify(opts)}, err: ${JSON.stringify(getHooksErr)}`);
}
if (hooks.statusCode >= 400) {
throw new CFError(`Failed to list repository webhooks: ${JSON.stringify(opt)}, status code: ${hooks.statusCode}, err: ${_extractErrorFromResponse(hooks)}`);
throw new CFError(`Failed to list repository webhooks: ${JSON.stringify(opts)}, status code: ${hooks.statusCode}, err: ${_extractErrorFromResponse(hooks)}`);
}
return hooks.map(_toWebhook.bind(null, opt.owner, opt.repo));
return hooks.map(_toWebhook.bind(null, opts.owner, opts.repo));
}
async deleteRepositoryWebhook(opt) {
const projectKey = opt.owner.startsWith('~')
? opt.owner
: await this.getProjectKey(opt.owner);
async deleteRepositoryWebhook(opts) {
const projectKey = await this.getProjectKey(opts.owner);
const [err, res] = await helpers_1.to(this.performAPICall({
api: `projects/${projectKey}/repos/${opt.repo}/webhooks/${opt.hookId}`,
api: `projects/${projectKey}/repos/${opts.repo}/webhooks/${opts.hookId}`,
method: 'DELETE',

@@ -451,10 +456,9 @@ json: true,

if (err) {
throw new CFError(`Failed to delete webhook: ${JSON.stringify(opt)}, err: ${JSON.stringify(err)}`);
throw new CFError(`Failed to delete webhook: ${JSON.stringify(opts)}, err: ${JSON.stringify(err)}`);
}
if (res.statusCode >= 400) {
throw new CFError(`Failed to delete webhook: ${JSON.stringify(opt)}, status code: ${res.statusCode}, err: ${_extractErrorFromResponse(res)}`);
throw new CFError(`Failed to delete webhook: ${JSON.stringify(opts)}, status code: ${res.statusCode}, err: ${_extractErrorFromResponse(res)}`);
}
}
async listRepositoriesWithAffiliation(opt) {
const { limit = 25, page = 1 } = opt;
async listRepositoriesWithAffiliation(opts) {
const [getReposErr, repos] = await helpers_1.to(this.paginateForResult({

@@ -464,4 +468,2 @@ api: `repos?avatarSize=${exports.avatarSize}`,

qs: {
start: String(page),
limit: String(limit),
permission: 'REPO_READ',

@@ -471,15 +473,16 @@ }

if (getReposErr) {
throw new CFError(`Failed to list repos: ${JSON.stringify(opt)}, err: ${JSON.stringify(getReposErr)}`);
throw new CFError(`Failed to list repos: ${JSON.stringify(opts)}, err: ${JSON.stringify(getReposErr)}`);
}
if (repos.statusCode >= 400) {
throw new CFError(`Failed to get repos: ${JSON.stringify(opt)}, status code: ${repos.statusCode}, ${_extractErrorFromResponse(repos)}`);
throw new CFError(`Failed to list repos: ${JSON.stringify(opts)}, status code: ${repos.statusCode}, ${_extractErrorFromResponse(repos)}`);
}
return repos.map(_toRepo);
}
async listOrganizations(opt) {
const { limit = 25, page = 1 } = opt;
async listOrganizations(opts) {
const { limit = 25, page = 0 } = opts;
const start = page * limit;
const [err, res] = await helpers_1.to(this.performAPICall({
api: `projects`,
qs: {
start: String(page),
start: String(start),
limit: String(limit),

@@ -501,7 +504,5 @@ },

}
async getRepositoryPermissions(opt) {
async getRepositoryPermissions(opts) {
var _a, _b, _c, _d;
const projectKey = opt.owner.startsWith('~')
? opt.owner
: await this.getProjectKey(opt.owner);
const projectKey = await this.getProjectKey(opts.owner);
const [reposReadResErr, reposReadRes] = await helpers_1.to(this.performAPICall({

@@ -514,7 +515,7 @@ apiVersion: ApiVersions.V1,

throw new CFError({
message: `Failed to get repository permissions: ${opt.owner}/${opt.repo}: ${reposReadResErr}`,
message: `Failed to get repository permissions: ${opts.owner}/${opts.repo}: ${reposReadResErr}`,
cause: reposReadResErr,
});
}
const read = -1 != ((_b = (_a = reposReadRes.body) === null || _a === void 0 ? void 0 : _a.values) === null || _b === void 0 ? void 0 : _b.findIndex((repo) => repo.name == opt.repo));
const read = -1 != ((_b = (_a = reposReadRes.body) === null || _a === void 0 ? void 0 : _a.values) === null || _b === void 0 ? void 0 : _b.findIndex((repo) => repo.name == opts.repo));
const [reposWriteResErr, reposWriteRes] = await helpers_1.to(this.performAPICall({

@@ -527,7 +528,7 @@ apiVersion: ApiVersions.V1,

throw new CFError({
message: `Failed to get repository permissions: ${opt.owner}/${opt.repo}: ${reposWriteResErr}`,
message: `Failed to get repository permissions: ${opts.owner}/${opts.repo}: ${reposWriteResErr}`,
cause: reposWriteResErr,
});
}
const write = -1 != ((_d = (_c = reposWriteRes.body) === null || _c === void 0 ? void 0 : _c.values) === null || _d === void 0 ? void 0 : _d.findIndex((repo) => repo.name == opt.repo));
const write = -1 != ((_d = (_c = reposWriteRes.body) === null || _c === void 0 ? void 0 : _c.values) === null || _d === void 0 ? void 0 : _d.findIndex((repo) => repo.name == opts.repo));
return {

@@ -539,30 +540,28 @@ read,

async listRepositoriesForOrganization() {
throw new Error('Method not implemented.');
throw new Error('Method listRepositoriesForOrganization not implemented.');
}
async createCommitStatus(opt) {
const projectKey = opt.owner.startsWith('~')
? opt.owner
: await this.getProjectKey(opt.owner);
async createCommitStatus(opts) {
const projectKey = await this.getProjectKey(opts.owner);
const [err, res] = await helpers_1.to(this.performAPICall({
api: `projects/${projectKey}/repos/${opt.repo}/commits/${opt.sha}/builds`,
api: `projects/${projectKey}/repos/${opts.repo}/commits/${opts.sha}/builds`,
method: 'POST',
json: true,
data: {
key: opt.context,
name: opt.context,
description: opt.description,
url: opt.targetUrl,
state: statesMap[opt.state],
key: opts.context,
name: opts.context,
description: opts.description,
url: opts.targetUrl,
state: statesMap[opts.state],
},
}));
if (err) {
throw new CFError(`Failed to create commit status: ${JSON.stringify(opt)}, err: ${JSON.stringify(err)}`);
throw new CFError(`Failed to create commit status: ${JSON.stringify(opts)}, err: ${JSON.stringify(err)}`);
}
if (res.statusCode >= 400) {
throw new CFError(`Failed to create commit status: ${JSON.stringify(opt)}, status code: ${res.statusCode}, err: ${_extractErrorFromResponse(res)}`);
throw new CFError(`Failed to create commit status: ${JSON.stringify(opts)}, status code: ${res.statusCode}, err: ${_extractErrorFromResponse(res)}`);
}
}
async getUser(opt) {
async getUser(opts) {
var _a;
let username = opt === null || opt === void 0 ? void 0 : opt.username;
let username = opts === null || opts === void 0 ? void 0 : opts.username;
if (!username) {

@@ -603,17 +602,17 @@ const res = await this.performAPICall({

async getPullRequestFiles() {
throw new Error('Method not implemented.');
throw new Error('Method getPullRequestFiles not implemented.');
}
async getPullRequest() {
throw new Error('Method not implemented.');
throw new Error('Method getPullRequest not implemented.');
}
async assertApiScopes(opt) {
if (opt.scopes.includes('admin_repo_hook')) {
async assertApiScopes(opts) {
if (opts.scopes.includes('admin_repo_hook')) {
await this.assertAdminScope();
return;
}
if ((opt.scopes.includes('repo_write') || opt.scopes.includes('repo_create')) && opt.repoUrl) {
await this.assertWriteScope(opt.repoUrl);
if ((opts.scopes.includes('repo_write') || opts.scopes.includes('repo_create')) && opts.repoUrl) {
await this.assertWriteScope(opts.repoUrl);
return;
}
if (opt.scopes.includes('repo_read')) {
if (opts.scopes.includes('repo_read')) {
await this.assertReadScope();

@@ -620,0 +619,0 @@ }

@@ -367,12 +367,12 @@ "use strict";

async listRepositoriesForOwner() {
throw new Error('Method not implemented.');
throw new Error('Method listRepositoriesForOwner not implemented.');
}
async createRepositoryWebhook() {
throw new Error('Method not implemented.');
throw new Error('Method createRepositoryWebhook not implemented.');
}
async listWebhooks() {
throw new Error('Method not implemented.');
throw new Error('Method listWebhooks not implemented.');
}
async deleteRepositoryWebhook() {
throw new Error('Method not implemented.');
throw new Error('Method deleteRepositoryWebhook not implemented.');
}

@@ -419,6 +419,6 @@ async listRepositoriesWithAffiliation(opt) {

async listRepositoriesForOrganization() {
throw new Error('Method not implemented.');
throw new Error('Method listRepositoriesForOrganization not implemented.');
}
async createCommitStatus() {
throw new Error('Method not implemented.');
throw new Error('Method createCommitStatus not implemented.');
}

@@ -449,6 +449,6 @@ async getUser(opt) {

async getPullRequestFiles() {
throw new Error('Method not implemented.');
throw new Error('Method getPullRequestFiles not implemented.');
}
async getPullRequest() {
throw new Error('Method not implemented.');
throw new Error('Method getPullRequest not implemented.');
}

@@ -455,0 +455,0 @@ async getRepositoryPermissions(opt) {

@@ -498,6 +498,6 @@ "use strict";

async getPullRequestFiles() {
throw new Error('Method not implemented.');
throw new Error('Method getPullRequestFiles not implemented.');
}
async getPullRequest() {
throw new Error('Method not implemented.');
throw new Error('Method getPullRequest not implemented.');
}

@@ -504,0 +504,0 @@ // check read permissions for both user and token and write permissions for user only

{
"name": "@codefresh-io/cf-git-providers",
"version": "0.5.1",
"version": "0.6.0",
"description": "An NPM module/CLI for interacting with various git providers",

@@ -37,3 +37,3 @@ "keywords": [

"engines": {
"node": ">=12.0.0"
"node": ">=14.20.0"
},

@@ -40,0 +40,0 @@ "files": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet