8000 feat: log `git` error message when authentication verification fails · semantic-release/semantic-release@cd9f2bd · GitHub
[go: up one dir, main page]

Skip to content

Commit cd9f2bd

Browse files
pvdlggr2m
authored andcommitted
feat: log git error message when authentication verification fails
1 parent d1c3ad0 commit cd9f2bd

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ async function run(options, plugins) {
5656
return false;
5757
}
5858

59-
if (!await verifyAuth(options.repositoryUrl, options.branch)) {
59+
try {
60+
await verifyAuth(options.repositoryUrl, options.branch);
61+
} catch (err) {
62+
logger.error(`The command "${err.cmd}" failed with the error message %s.`, err.stderr);
6063
throw getError('EGITNOPERMISSION', {options});
6164
}
6265

lib/get-git-auth-url.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ module.exports = async ({repositoryUrl, branch}) => {
4343
}
4444

4545
// Test if push is allowed without transforming the URL (e.g. is ssh keys are set up)
46-
if (!await verifyAuth(repositoryUrl, branch)) {
46+
try {
47+
await verifyAuth(repositoryUrl, branch);
48+
} catch (err) {
4749
const envVar = Object.keys(GIT_TOKENS).find(envVar => !isUndefined(process.env[envVar]));
4850
const gitCredentials = `${GIT_TOKENS[envVar] || ''}${process.env[envVar] || ''}`;
4951
const {protocols, ...parsed} = gitUrlParse(repositoryUrl);
@@ -52,5 +54,6 @@ module.exports = async ({repositoryUrl, branch}) => {
5254
// If credentials are set via anvironment variables, convert the URL to http/https and add basic auth, otherwise return `repositoryUrl` as is
5355
return gitCredentials ? {...parsed, protocols: [protocol], user: gitCredentials}.toString(protocol) : repositoryUrl;
5456
}
57+
5558
return repositoryUrl;
5659
};

lib/git.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,14 @@ async function isGitRepo() {
8686
* @param {String} repositoryUrl The remote repository URL.
8787
* @param {String} branch The repositoru branch for which to verify write access.
8888
*
89-
* @return {Boolean} `true` is authorized to push, falsy otherwise.
89+
* @throws {Error} if not authorized to push.
9090
*/
9191
async function verifyAuth(repositoryUrl, branch) {
9292
try {
93-
return (await execa('git', ['push', '--dry-run', repositoryUrl, `HEAD:${branch}`])).code === 0;
93+
await execa('git', ['push', '--dry-run', repositoryUrl, `HEAD:${branch}`]);
9494
} catch (err) {
9595
de 4C62 bug(err);
96+
throw err;
9697
}
9798
}
9899

0 commit comments

Comments
 (0)
0