@codefresh-io/cf-git-providers
Advanced tools
Comparing version
@@ -61,2 +61,10 @@ "use strict"; | ||
}; | ||
const _toUser = (user, email) => { | ||
return { | ||
login: user.username, | ||
email: email || user.email, | ||
avatar_url: user.avatar_url, | ||
web_url: user.web_url, | ||
}; | ||
}; | ||
const _toRepo = (rawRepo) => { | ||
@@ -323,6 +331,38 @@ const isGroup = lodash_1.get(rawRepo, 'namespace.kind') === 'group'; // is it a group/org repository | ||
async getUser(opt) { | ||
throw new Error('Method not implemented.'); | ||
const user = (opt === null || opt === void 0 ? void 0 : opt.username) ? opt.username : 'authenticated user'; | ||
const [err, res] = await helpers_1.to(this.performAPICall({ | ||
api: (opt === null || opt === void 0 ? void 0 : opt.username) ? 'users' : 'user', | ||
json: true, | ||
qs: (opt === null || opt === void 0 ? void 0 : opt.username) ? { username: opt.username } : {} | ||
})); | ||
if (err) { | ||
throw new CFError({ | ||
message: `Failed to get ${user}: , status code: ${err.statusCode}`, | ||
cause: err, | ||
}); | ||
} | ||
else if (res.statusCode >= 400) { | ||
throw new CFError(`Failed to get user: ${user}, status code: ${res.statusCode}`); | ||
} | ||
return _toUser(res.body); | ||
} | ||
async getUserByEmail(email) { | ||
throw new Error('Method not implemented.'); | ||
const [err, res] = await helpers_1.to(this.performAPICall({ | ||
api: 'users', | ||
json: true, | ||
qs: { search: email } | ||
})); | ||
if (err) { | ||
throw new CFError({ | ||
message: `Failed to get user with email ${email}: , status code: ${err.statusCode}`, | ||
cause: err, | ||
}); | ||
} | ||
else if (res.statusCode >= 400) { | ||
throw new CFError(`Failed to get user with email: ${email}, status code: ${res.statusCode}`); | ||
} | ||
if (res.body.length === 0) { | ||
throw new CFError(`No user with email: ${email} was found on ${this.getName()}`); | ||
} | ||
return _toUser(res.body[0], email); | ||
} | ||
@@ -329,0 +369,0 @@ } |
{ | ||
"name": "@codefresh-io/cf-git-providers", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "An NPM module/CLI for interacting with various git providers", | ||
@@ -70,2 +70,2 @@ "keywords": [ | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
207759
1.54%3112
1.3%