mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 22:46:27 +00:00
Support changelogs for groups (#257)
Closes #202 * Externalise hbs templates * Fix tests * Move templates * lint fix * Pass all upgrades to ensurePr * Group changelogs * Fix lint * Fix tests
This commit is contained in:
parent
6df68a260c
commit
d234a0d9dd
3 changed files with 38 additions and 24 deletions
|
@ -257,7 +257,7 @@ async function updateBranch(upgrades) {
|
|||
}
|
||||
const branchCreated = await branchWorker.ensureBranch(upgrades);
|
||||
if (branchCreated) {
|
||||
const pr = await prWorker.ensurePr(upgrade0);
|
||||
const pr = await prWorker.ensurePr(upgrades);
|
||||
if (pr) {
|
||||
await prWorker.checkAutoMerge(pr, upgrade0);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,9 @@ module.exports = {
|
|||
};
|
||||
|
||||
// Ensures that PR exists with matching title/body
|
||||
async function ensurePr(upgradeConfig) {
|
||||
async function ensurePr(upgrades) {
|
||||
logger.debug(`ensurePr(${JSON.stringify(upgrades)})`);
|
||||
const upgradeConfig = upgrades[0];
|
||||
const config = Object.assign({}, upgradeConfig);
|
||||
logger.debug('Ensuring PR');
|
||||
|
||||
|
@ -33,11 +35,23 @@ async function ensurePr(upgradeConfig) {
|
|||
}
|
||||
|
||||
// Get changelog and then generate template strings
|
||||
config.changelog = await getChangeLog(
|
||||
config.depName,
|
||||
config.changeLogFromVersion,
|
||||
config.changeLogToVersion
|
||||
);
|
||||
config.changelogs = [];
|
||||
for (const upgrade of upgrades) {
|
||||
let log = await getChangeLog(
|
||||
upgrade.depName,
|
||||
upgrade.changeLogFromVersion,
|
||||
upgrade.changeLogToVersion
|
||||
);
|
||||
if (!(log && log.length)) {
|
||||
log = 'No changelog available';
|
||||
}
|
||||
config.changelogs.push({
|
||||
depName: upgrade.depName,
|
||||
log,
|
||||
});
|
||||
}
|
||||
// Configure changelog for backwards compatibility
|
||||
config.changelog = config.changelogs[0].log;
|
||||
const prTitle = handlebars.compile(config.prTitle)(config);
|
||||
const prBody = handlebars.compile(config.prBody)(config);
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ describe('workers/pr', () => {
|
|||
expect(config.api.mergePr.mock.calls.length).toBe(0);
|
||||
});
|
||||
});
|
||||
describe('ensurePr(config)', () => {
|
||||
describe('ensurePr(upgrades)', () => {
|
||||
let config;
|
||||
let existingPr;
|
||||
beforeEach(() => {
|
||||
|
@ -81,7 +81,7 @@ describe('workers/pr', () => {
|
|||
existingPr = {
|
||||
title: 'Update dependency dummy to version 1.1.0',
|
||||
body:
|
||||
'This Pull Request updates dependency dummy from version `1.0.0` to `1.1.0`\n\n',
|
||||
'This Pull Request updates dependency dummy from version `1.0.0` to `1.1.0`\n\nNo changelog available',
|
||||
displayNumber: 'Existing PR',
|
||||
};
|
||||
});
|
||||
|
@ -89,45 +89,45 @@ describe('workers/pr', () => {
|
|||
config.api.getBranchPr = jest.fn(() => {
|
||||
throw new Error('oops');
|
||||
});
|
||||
const pr = await prWorker.ensurePr(config);
|
||||
const pr = await prWorker.ensurePr([config]);
|
||||
expect(pr).toBe(null);
|
||||
});
|
||||
it('should return null if waiting for success', async () => {
|
||||
config.api.getBranchStatus = jest.fn(() => 'failed');
|
||||
config.prCreation = 'status-success';
|
||||
const pr = await prWorker.ensurePr(config);
|
||||
const pr = await prWorker.ensurePr([config]);
|
||||
expect(pr).toBe(null);
|
||||
});
|
||||
it('should create PR if success', async () => {
|
||||
config.api.getBranchStatus = jest.fn(() => 'success');
|
||||
config.api.getBranchPr = jest.fn();
|
||||
config.prCreation = 'status-success';
|
||||
const pr = await prWorker.ensurePr(config);
|
||||
const pr = await prWorker.ensurePr([config]);
|
||||
expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
|
||||
});
|
||||
it('should return null if waiting for not pending', async () => {
|
||||
config.api.getBranchStatus = jest.fn(() => 'pending');
|
||||
config.prCreation = 'not-pending';
|
||||
const pr = await prWorker.ensurePr(config);
|
||||
const pr = await prWorker.ensurePr([config]);
|
||||
expect(pr).toBe(null);
|
||||
});
|
||||
it('should create PR if no longer pending', async () => {
|
||||
config.api.getBranchStatus = jest.fn(() => 'failed');
|
||||
config.api.getBranchPr = jest.fn();
|
||||
config.prCreation = 'not-pending';
|
||||
const pr = await prWorker.ensurePr(config);
|
||||
const pr = await prWorker.ensurePr([config]);
|
||||
expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
|
||||
});
|
||||
it('should create new branch if none exists', async () => {
|
||||
config.api.getBranchPr = jest.fn();
|
||||
const pr = await prWorker.ensurePr(config);
|
||||
const pr = await prWorker.ensurePr([config]);
|
||||
expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
|
||||
});
|
||||
it('should add labels to new PR', async () => {
|
||||
config.api.getBranchPr = jest.fn();
|
||||
config.api.addLabels = jest.fn();
|
||||
config.labels = ['foo'];
|
||||
const pr = await prWorker.ensurePr(config);
|
||||
const pr = await prWorker.ensurePr([config]);
|
||||
expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
|
||||
expect(config.api.addLabels.mock.calls.length).toBe(1);
|
||||
});
|
||||
|
@ -135,7 +135,7 @@ describe('workers/pr', () => {
|
|||
config.api.getBranchPr = jest.fn();
|
||||
config.api.addLabels = jest.fn();
|
||||
config.labels = [];
|
||||
const pr = await prWorker.ensurePr(config);
|
||||
const pr = await prWorker.ensurePr([config]);
|
||||
expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
|
||||
expect(config.api.addLabels.mock.calls.length).toBe(0);
|
||||
});
|
||||
|
@ -145,7 +145,7 @@ describe('workers/pr', () => {
|
|||
config.api.addReviewers = jest.fn();
|
||||
config.assignees = ['bar'];
|
||||
config.reviewers = ['baz'];
|
||||
const pr = await prWorker.ensurePr(config);
|
||||
const pr = await prWorker.ensurePr([config]);
|
||||
expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
|
||||
expect(config.api.addAssignees.mock.calls.length).toBe(1);
|
||||
expect(config.api.addReviewers.mock.calls.length).toBe(1);
|
||||
|
@ -157,7 +157,7 @@ describe('workers/pr', () => {
|
|||
config.assignees = ['bar'];
|
||||
config.reviewers = ['baz'];
|
||||
config.automerge = 'any';
|
||||
const pr = await prWorker.ensurePr(config);
|
||||
const pr = await prWorker.ensurePr([config]);
|
||||
expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
|
||||
expect(config.api.addAssignees.mock.calls.length).toBe(0);
|
||||
expect(config.api.addReviewers.mock.calls.length).toBe(0);
|
||||
|
@ -170,7 +170,7 @@ describe('workers/pr', () => {
|
|||
config.reviewers = ['baz'];
|
||||
config.upgradeType = 'minor';
|
||||
config.automerge = 'minor';
|
||||
const pr = await prWorker.ensurePr(config);
|
||||
const pr = await prWorker.ensurePr([config]);
|
||||
expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
|
||||
expect(config.api.addAssignees.mock.calls.length).toBe(0);
|
||||
expect(config.api.addReviewers.mock.calls.length).toBe(0);
|
||||
|
@ -183,7 +183,7 @@ describe('workers/pr', () => {
|
|||
config.reviewers = ['baz'];
|
||||
config.upgradeType = 'major';
|
||||
config.automerge = 'minor';
|
||||
const pr = await prWorker.ensurePr(config);
|
||||
const pr = await prWorker.ensurePr([config]);
|
||||
expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
|
||||
expect(config.api.addAssignees.mock.calls.length).toBe(1);
|
||||
expect(config.api.addReviewers.mock.calls.length).toBe(1);
|
||||
|
@ -194,7 +194,7 @@ describe('workers/pr', () => {
|
|||
config.newVersion = '1.1.0';
|
||||
config.api.getBranchPr = jest.fn(() => existingPr);
|
||||
config.api.updatePr = jest.fn();
|
||||
const pr = await prWorker.ensurePr(config);
|
||||
const pr = await prWorker.ensurePr([config]);
|
||||
expect(pr).toMatchObject(existingPr);
|
||||
});
|
||||
it('should return modified existing PR', async () => {
|
||||
|
@ -203,10 +203,10 @@ describe('workers/pr', () => {
|
|||
config.newVersion = '1.2.0';
|
||||
config.api.getBranchPr = jest.fn(() => existingPr);
|
||||
config.api.updatePr = jest.fn();
|
||||
const pr = await prWorker.ensurePr(config);
|
||||
const pr = await prWorker.ensurePr([config]);
|
||||
const updatedPr = Object.assign(existingPr, {
|
||||
body:
|
||||
'This Pull Request updates dependency dummy from version `1.0.0` to `1.2.0`\n\n',
|
||||
'This Pull Request updates dependency dummy from version `1.0.0` to `1.2.0`\n\nNo changelog available',
|
||||
});
|
||||
expect(pr).toMatchObject(updatedPr);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue