From f103297b2fcd39ea117450bc844d38aa5fab29b7 Mon Sep 17 00:00:00 2001 From: Herbert Ng <herb-ng@users.noreply.github.com> Date: Tue, 3 Sep 2019 23:52:53 +1000 Subject: [PATCH] feat: add prPriority to config (#4401) --- lib/config/definitions.ts | 9 +++++++ lib/workers/repository/process/sort.js | 3 +++ renovate-schema.json | 5 ++++ .../process/__snapshots__/sort.spec.js.snap | 25 ++++++++++++++++++ test/workers/repository/process/sort.spec.js | 26 +++++++++++++++++++ website/docs/configuration-options.md | 21 +++++++++++++++ 6 files changed, 89 insertions(+) diff --git a/lib/config/definitions.ts b/lib/config/definitions.ts index 79a0f256f9..a617a1563a 100644 --- a/lib/config/definitions.ts +++ b/lib/config/definitions.ts @@ -1006,6 +1006,15 @@ const options: RenovateOptions[] = [ type: 'integer', default: 0, // no limit }, + { + name: 'prPriority', + description: + 'Set sorting priority for PR creation. PRs with higher priority are created first, negative priority last.', + type: 'integer', + default: 0, + cli: false, + env: false, + }, { name: 'bbUseDefaultReviewers', description: 'Use the default reviewers (Bitbucket server only).', diff --git a/lib/workers/repository/process/sort.js b/lib/workers/repository/process/sort.js index 807101f240..b6a8f9b3a4 100644 --- a/lib/workers/repository/process/sort.js +++ b/lib/workers/repository/process/sort.js @@ -14,6 +14,9 @@ function sortBranches(branches) { ]; logger.trace({ branches }, 'branches'); branches.sort((a, b) => { + if (a.prPriority !== b.prPriority) { + return b.prPriority - a.prPriority; + } const sortDiff = sortOrder.indexOf(a.updateType) - sortOrder.indexOf(b.updateType); if (sortDiff !== 0) { diff --git a/renovate-schema.json b/renovate-schema.json index 1cebd4b269..cea32222b8 100644 --- a/renovate-schema.json +++ b/renovate-schema.json @@ -618,6 +618,11 @@ "type": "integer", "default": 0 }, + "prPriority": { + "description": "Set sorting priority for PR creation. PRs with higher priority are created first, negative priority last.", + "type": "integer", + "default": 0 + }, "bbUseDefaultReviewers": { "description": "Use the default reviewers (Bitbucket server only).", "type": "boolean", diff --git a/test/workers/repository/process/__snapshots__/sort.spec.js.snap b/test/workers/repository/process/__snapshots__/sort.spec.js.snap index 449b66d61e..98c23b6a54 100644 --- a/test/workers/repository/process/__snapshots__/sort.spec.js.snap +++ b/test/workers/repository/process/__snapshots__/sort.spec.js.snap @@ -1,5 +1,30 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`workers/repository/process/sort sortBranches() sorts based on prPriority 1`] = ` +Array [ + Object { + "prPriority": 1, + "prTitle": "some major update", + "updateType": "major", + }, + Object { + "prPriority": 0, + "prTitle": "some other pin", + "updateType": "pin", + }, + Object { + "prPriority": -1, + "prTitle": "some pin", + "updateType": "pin", + }, + Object { + "prPriority": -1, + "prTitle": "a minor update", + "updateType": "minor", + }, +] +`; + exports[`workers/repository/process/sort sortBranches() sorts based on updateType and prTitle 1`] = ` Array [ Object { diff --git a/test/workers/repository/process/sort.spec.js b/test/workers/repository/process/sort.spec.js index d32462551b..63d24e1143 100644 --- a/test/workers/repository/process/sort.spec.js +++ b/test/workers/repository/process/sort.spec.js @@ -26,5 +26,31 @@ describe('workers/repository/process/sort', () => { sortBranches(branches); expect(branches).toMatchSnapshot(); }); + it('sorts based on prPriority', () => { + const branches = [ + { + updateType: 'major', + prTitle: 'some major update', + prPriority: 1, + }, + { + updateType: 'pin', + prTitle: 'some pin', + prPriority: -1, + }, + { + updateType: 'pin', + prTitle: 'some other pin', + prPriority: 0, + }, + { + updateType: 'minor', + prTitle: 'a minor update', + prPriority: -1, + }, + ]; + sortBranches(branches); + expect(branches).toMatchSnapshot(); + }); }); }); diff --git a/website/docs/configuration-options.md b/website/docs/configuration-options.md index ebe3dfd678..b6213e2991 100644 --- a/website/docs/configuration-options.md +++ b/website/docs/configuration-options.md @@ -923,6 +923,27 @@ Note that this limit is enforced on a per-repository basis. If you set `prCreation=not-pending`, then Renovate will wait until tests are non-pending (all pass or at least one fails) before creating PRs. However there are cases where PRs may remain in pending state forever, e.g. absence of tests or status checks that are set to pending indefinitely. Therefore we set an upper limit - default 24 hours - for how long we wait until creating a PR. Note also this is the same length of time as for Renovate's own `unpublishSafe` status check for npm. +## prPriority + +Sometimes Renovate needs to rate limit its creation of PRs, e.g. hourly or concurrent PR limits. In such cases it sorts/prioritizes by default based on the update type (e.g. patches raised before minor, minor before major). If you have dependencies that are more or less important than others then you can use the `prPriority` field for PR sorting. The default value is 0, so therefore setting a negative value will make dependencies sort last, while higher values sort first. + +Here's an example of how you would define PR priority so that devDependencies are raised last and `react` is raised first: + +```json +{ + "packageRules": [ + { + "depTypeList": ["devDependencies"], + "prPriority": -1 + }, + { + "packageNames": ["react"], + "prPriority": 5 + } + ] +} +``` + ## prTitle The PR title is important for some of Renovate's matching algorithms (e.g. determining whether to recreate a PR or not) so ideally don't modify it much. -- GitLab