Skip to content
Snippets Groups Projects
Unverified Commit e063c8f9 authored by Artur Frysiak's avatar Artur Frysiak Committed by GitHub
Browse files

feat: handle GitLab push rule violation (#8416)


* feat: handle GitLab push rule violation

Closes #8414

* feat: handle GitLab push rule violation

* feat: handle GitLab push rule violation

Co-authored-by: default avatarMichael Kriese <michael.kriese@visualon.de>
parent 06254bab
Branches
Tags 24.29.0
No related merge requests found
......@@ -10,6 +10,7 @@ import Git, {
import { join } from 'upath';
import { configFileNames } from '../../config/app-strings';
import {
CONFIG_VALIDATION,
REPOSITORY_CHANGED,
REPOSITORY_DISABLED,
REPOSITORY_EMPTY,
......@@ -58,7 +59,7 @@ function checkForPlatformFailure(err: Error): void {
if (process.env.NODE_ENV === 'test') {
return;
}
const platformFailureStrings = [
const externalHostFailureStrings = [
'remote: Invalid username or password',
'gnutls_handshake() failed',
'The requested URL returned error: 5',
......@@ -70,12 +71,32 @@ function checkForPlatformFailure(err: Error): void {
'malformed object name',
'TF401027:', // You need the Git 'GenericContribute' permission to perform this action
];
for (const errorStr of platformFailureStrings) {
for (const errorStr of externalHostFailureStrings) {
if (err.message.includes(errorStr)) {
logger.debug({ err }, 'Converting git error to ExternalHostError');
throw new ExternalHostError(err, 'git');
}
}
const configErrorStrings = [
[
'GitLab: Branch name does not follow the pattern',
"Cannot push because branch name does not follow project's push rules",
],
[
'GitLab: Commit message does not follow the pattern',
"Cannot push because commit message does not follow project's push rules",
],
];
for (const [errorStr, validationError] of configErrorStrings) {
if (err.message.includes(errorStr)) {
logger.debug({ err }, 'Converting git error to CONFIG_VALIDATION error');
const error = new Error(CONFIG_VALIDATION);
error.validationError = validationError;
error.validationMessage = err.message;
throw error;
}
}
}
function localName(branchName: string): string {
......
......@@ -3,6 +3,7 @@ import { DateTime } from 'luxon';
import minimatch from 'minimatch';
import { RenovateConfig } from '../../config';
import {
CONFIG_VALIDATION,
MANAGER_LOCKFILE_ERROR,
PLATFORM_AUTHENTICATION_ERROR,
PLATFORM_BAD_CREDENTIALS,
......@@ -574,6 +575,9 @@ export async function processBranch(
} else if (err.message?.includes('fatal: bad revision')) {
logger.debug({ err }, 'Aborting job due to bad revision error');
throw new Error(REPOSITORY_CHANGED);
} else if (err.message === CONFIG_VALIDATION) {
logger.debug('Passing config validation error up');
throw err;
} else if (!(err instanceof ExternalHostError)) {
logger.error({ err }, `Error updating branch: ${String(err.message)}`);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment