feat: log git
error message when authentication verification fails
This commit is contained in:
parent
d1c3ad0b57
commit
cd9f2bdd44
5
index.js
5
index.js
@ -56,7 +56,10 @@ async function run(options, plugins) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!await verifyAuth(options.repositoryUrl, options.branch)) {
|
||||
try {
|
||||
await verifyAuth(options.repositoryUrl, options.branch);
|
||||
} catch (err) {
|
||||
logger.error(`The command "${err.cmd}" failed with the error message %s.`, err.stderr);
|
||||
throw getError('EGITNOPERMISSION', {options});
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,9 @@ module.exports = async ({repositoryUrl, branch}) => {
|
||||
}
|
||||
|
||||
// Test if push is allowed without transforming the URL (e.g. is ssh keys are set up)
|
||||
if (!await verifyAuth(repositoryUrl, branch)) {
|
||||
try {
|
||||
await verifyAuth(repositoryUrl, branch);
|
||||
} catch (err) {
|
||||
const envVar = Object.keys(GIT_TOKENS).find(envVar => !isUndefined(process.env[envVar]));
|
||||
const gitCredentials = `${GIT_TOKENS[envVar] || ''}${process.env[envVar] || ''}`;
|
||||
const {protocols, ...parsed} = gitUrlParse(repositoryUrl);
|
||||
@ -52,5 +54,6 @@ module.exports = async ({repositoryUrl, branch}) => {
|
||||
// If credentials are set via anvironment variables, convert the URL to http/https and add basic auth, otherwise return `repositoryUrl` as is
|
||||
return gitCredentials ? {...parsed, protocols: [protocol], user: gitCredentials}.toString(protocol) : repositoryUrl;
|
||||
}
|
||||
|
||||
return repositoryUrl;
|
||||
};
|
||||
|
@ -86,13 +86,14 @@ async function isGitRepo() {
|
||||
* @param {String} repositoryUrl The remote repository URL.
|
||||
* @param {String} branch The repositoru branch for which to verify write access.
|
||||
*
|
||||
* @return {Boolean} `true` is authorized to push, falsy otherwise.
|
||||
* @throws {Error} if not authorized to push.
|
||||
*/
|
||||
async function verifyAuth(repositoryUrl, branch) {
|
||||
try {
|
||||
return (await execa('git', ['push', '--dry-run', repositoryUrl, `HEAD:${branch}`])).code === 0;
|
||||
await execa('git', ['push', '--dry-run', repositoryUrl, `HEAD:${branch}`]);
|
||||
} catch (err) {
|
||||
debug(err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user