logs: branch/branchName

This commit is contained in:
Rhys Arkins 2018-09-24 11:47:49 +02:00
parent 56ee66381b
commit 08cf55e81f
7 changed files with 30 additions and 21 deletions

View file

@ -230,7 +230,10 @@ async function getBranchStatus(branchName, requiredStatusChecks) {
); );
const noOfFailures = statuses.filter(status => status.state === 'FAILED') const noOfFailures = statuses.filter(status => status.state === 'FAILED')
.length; .length;
logger.debug({ branchName, sha, statuses }, 'branch status check result'); logger.debug(
{ branch: branchName, sha, statuses },
'branch status check result'
);
if (noOfFailures) { if (noOfFailures) {
return 'failed'; return 'failed';
} }

View file

@ -422,7 +422,7 @@ function mergeBranch(branchName) {
// istanbul ignore if // istanbul ignore if
if (config.pushProtection) { if (config.pushProtection) {
logger.info( logger.info(
{ branchName }, { branch: branchName },
'Branch protection: Attempting to merge branch when push protection is enabled' 'Branch protection: Attempting to merge branch when push protection is enabled'
); );
} }
@ -504,7 +504,7 @@ async function setBranchStatus(
if (existingStatus === state) { if (existingStatus === state) {
return; return;
} }
logger.info({ branchName, context, state }, 'Setting branch status'); logger.info({ branch: branchName, context, state }, 'Setting branch status');
const branchCommit = await config.storage.getBranchCommit(branchName); const branchCommit = await config.storage.getBranchCommit(branchName);
const url = `repos/${config.repository}/statuses/${branchCommit}`; const url = `repos/${config.repository}/statuses/${branchCommit}`;
const options = { const options = {
@ -836,7 +836,7 @@ async function createPr(
`repos/${config.parentRepo || config.repository}/pulls`, `repos/${config.parentRepo || config.repository}/pulls`,
options options
)).body; )).body;
logger.debug({ branchName, pr: pr.number }, 'PR created'); logger.debug({ branch: branchName, pr: pr.number }, 'PR created');
pr.displayNumber = `Pull Request #${pr.number}`; pr.displayNumber = `Pull Request #${pr.number}`;
pr.branchName = branchName; pr.branchName = branchName;
await addLabels(pr.number, labels); await addLabels(pr.number, labels);
@ -1200,7 +1200,7 @@ async function mergePr(prNo, branchName) {
// istanbul ignore if // istanbul ignore if
if (config.pushProtection) { if (config.pushProtection) {
logger.info( logger.info(
{ branchName, prNo }, { branch: branchName, prNo },
'Branch protection: Cannot automerge PR when push protection is enabled' 'Branch protection: Cannot automerge PR when push protection is enabled'
); );
return false; return false;
@ -1208,7 +1208,7 @@ async function mergePr(prNo, branchName) {
// istanbul ignore if // istanbul ignore if
if (config.prReviewsRequired) { if (config.prReviewsRequired) {
logger.debug( logger.debug(
{ branchName, prNo }, { branch: branchName, prNo },
'Branch protection: Attempting to merge PR when PR reviews are enabled' 'Branch protection: Attempting to merge PR when PR reviews are enabled'
); );
const repository = config.parentRepo || config.repository; const repository = config.parentRepo || config.repository;
@ -1216,7 +1216,7 @@ async function mergePr(prNo, branchName) {
const isApproved = reviews.body.some(review => review.state === 'APPROVED'); const isApproved = reviews.body.some(review => review.state === 'APPROVED');
if (!isApproved) { if (!isApproved) {
logger.info( logger.info(
{ branchName, prNo }, { branch: branchName, prNo },
'Branch protection: Cannot automerge PR until there is an approving review' 'Branch protection: Cannot automerge PR until there is an approving review'
); );
return false; return false;

View file

@ -148,9 +148,12 @@ class Storage {
); );
} catch (err) /* istanbul ignore next */ { } catch (err) /* istanbul ignore next */ {
if (err.message.startsWith('Reference does not exist')) { if (err.message.startsWith('Reference does not exist')) {
logger.info({ branchName }, 'Branch to delete does not exist'); logger.info(
{ branch: branchName },
'Branch to delete does not exist'
);
} else { } else {
logger.warn({ err, branchName }, 'Error deleting branch'); logger.warn({ err, branch: branchName }, 'Error deleting branch');
} }
} }
} }
@ -167,7 +170,7 @@ class Storage {
}; };
try { try {
await get.patch(url, options); await get.patch(url, options);
logger.debug({ branchName }, 'Branch merged'); logger.debug({ branch: branchName }, 'Branch merged');
} catch (err) { } catch (err) {
logger.info({ err }, `Error pushing branch merge for ${branchName}`); logger.info({ err }, `Error pushing branch merge for ${branchName}`);
throw new Error('Branch automerge failed'); throw new Error('Branch automerge failed');
@ -205,7 +208,7 @@ class Storage {
} catch (error) { } catch (error) {
if (error.statusCode === 404) { if (error.statusCode === 404) {
// If file not found, then return null JSON // If file not found, then return null JSON
logger.info({ filePath, branchName }, 'getFile 404'); logger.info({ filePath, branch: branchName }, 'getFile 404');
return null; return null;
} }
if ( if (
@ -281,11 +284,11 @@ class Storage {
try { try {
if (isBranchExisting) { if (isBranchExisting) {
await updateBranch(branchName, commit); await updateBranch(branchName, commit);
logger.debug({ branchName }, 'Branch updated'); logger.debug({ branch: branchName }, 'Branch updated');
return 'updated'; return 'updated';
} }
await createBranch(branchName, commit); await createBranch(branchName, commit);
logger.info({ branchName }, 'Branch created'); logger.info({ branch: branchName }, 'Branch created');
return 'created'; return 'created';
} catch (err) /* istanbul ignore next */ { } catch (err) /* istanbul ignore next */ {
logger.debug({ logger.debug({
@ -324,7 +327,7 @@ class Storage {
await deleteBranch(blockingBranch); await deleteBranch(blockingBranch);
} }
} }
logger.debug({ options, branchName }, 'Creating branch'); logger.debug({ options, branch: branchName }, 'Creating branch');
await get.post(`repos/${config.repository}/git/refs`, options); await get.post(`repos/${config.repository}/git/refs`, options);
branchList.push(branchName); branchList.push(branchName);
logger.debug('Created branch'); logger.debug('Created branch');

View file

@ -19,7 +19,7 @@ async function tryBranchAutomerge(config) {
logger.debug(`Automerging branch`); logger.debug(`Automerging branch`);
try { try {
await platform.mergeBranch(config.branchName); await platform.mergeBranch(config.branchName);
logger.info({ branchName: config.branchName }, 'Branch automerged'); logger.info({ branch: config.branchName }, 'Branch automerged');
return 'automerged'; // Branch no longer exists return 'automerged'; // Branch no longer exists
} catch (err) { } catch (err) {
logger.info({ err }, `Failed to automerge branch`); logger.info({ err }, `Failed to automerge branch`);

View file

@ -19,7 +19,7 @@ async function commitFilesToBranch(config) {
config.parentBranch || config.baseBranch || undefined config.parentBranch || config.baseBranch || undefined
); );
if (res) { if (res) {
logger.info({ branchName: config.branchName }, `Branch ${res}`); logger.info({ branch: config.branchName }, `Branch ${res}`);
} }
} else { } else {
logger.debug(`No files to commit`); logger.debug(`No files to commit`);

View file

@ -218,7 +218,7 @@ async function ensurePr(prConfig) {
); );
return existingPr; return existingPr;
} }
logger.debug({ branchName, prTitle }, `Creating PR`); logger.debug({ branch: branchName, prTitle }, `Creating PR`);
// istanbul ignore if // istanbul ignore if
if (config.updateType === 'rollback') { if (config.updateType === 'rollback') {
logger.warn('Creating Rollback PR'); logger.warn('Creating Rollback PR');
@ -233,16 +233,19 @@ async function ensurePr(prConfig) {
false, false,
config.statusCheckVerify config.statusCheckVerify
); );
logger.info({ branchName, pr: pr.number }, 'PR created'); logger.info({ branch: branchName, pr: pr.number }, 'PR created');
} catch (err) { } catch (err) {
logger.warn({ err }, `Failed to create PR`); logger.warn({ err }, `Failed to create PR`);
if (err.message === 'Validation Failed (422)') { if (err.message === 'Validation Failed (422)') {
logger.info({ branchName }, 'Deleting invalid branch'); logger.info({ branch: branchName }, 'Deleting invalid branch');
await platform.deleteBranch(branchName); await platform.deleteBranch(branchName);
} }
// istanbul ignore if // istanbul ignore if
if (err.statusCode === 502) { if (err.statusCode === 502) {
logger.info({ branchName }, 'Deleting branch due to server error'); logger.info(
{ branch: branchName },
'Deleting branch due to server error'
);
await platform.deleteBranch(branchName); await platform.deleteBranch(branchName);
} }
return null; return null;

View file

@ -21,7 +21,7 @@ async function getOnboardingConfig(config) {
renovateJson.labels = [String(label).replace('greenkeeper', 'renovate')]; renovateJson.labels = [String(label).replace('greenkeeper', 'renovate')];
} }
if (branchName) { if (branchName) {
logger.info({ branchName }, 'Migrating Greenkeeper branchName'); logger.info({ branch: branchName }, 'Migrating Greenkeeper branchName');
renovateJson.branchName = [ renovateJson.branchName = [
String(branchName).replace('greenkeeper', 'renovate'), String(branchName).replace('greenkeeper', 'renovate'),
]; ];