From 6a0524edb7ea16d4d4aff10a3087b2deaf910147 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@keylocation.sg>
Date: Sat, 29 Apr 2017 04:42:17 +0200
Subject: [PATCH] Enable templates via env and update design decision doc
 (#192)

Closes #190
---
 docs/configuration.md     | 24 ++++++++++----------
 docs/design-decisions.md  | 48 ++++++++++++++++++---------------------
 lib/config/definitions.js | 12 ----------
 3 files changed, 34 insertions(+), 50 deletions(-)

diff --git a/docs/configuration.md b/docs/configuration.md
index 730a7feacc..a7be23c62c 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -146,21 +146,21 @@ Obviously, you can't set repository or package file location with this method.
 | `rebaseStalePrs` | Rebase stale PRs (GitHub only) | boolean | `false` | `RENOVATE_REBASE_STALE_PRS` | `--rebase-stale-prs` |
 | `prCreation` | When to create the PR for a branch. Values: immediate, not-pending, status-success. | string | `"immediate"` | `RENOVATE_PR_CREATION` | `--pr-creation` |
 | `automerge` | What types of upgrades to merge to base branch automatically. Values: none, minor or any | string | `"none"` | `RENOVATE_AUTOMERGE` | `--automerge` |
-| `branchName` | Branch name template | string | `"renovate/{{depName}}-{{newVersionMajor}}.x"` |  |  |
-| `commitMessage` | Commit message template | string | `"Update dependency {{depName}} to version {{newVersion}}"` |  |  |
-| `prTitle` | Pull Request title template | string | `"{{#if isPin}}Pin{{else}}Update{{/if}} dependency {{depName}} to version {{#if isRange}}{{newVersion}}{{else}}{{#if isMajor}}{{newVersionMajor}}.x{{else}}{{newVersion}}{{/if}}{{/if}}"` |  |  |
-| `prBody` | Pull Request body template | string | `"This Pull Request updates dependency {{depName}} from version `{{currentVersion}}` to `{{newVersion}}`\n\n{{changelog}}"` |  |  |
+| `branchName` | Branch name template | string | `"renovate/{{depName}}-{{newVersionMajor}}.x"` | `RENOVATE_BRANCH_NAME` |  |
+| `commitMessage` | Commit message template | string | `"Update dependency {{depName}} to version {{newVersion}}"` | `RENOVATE_COMMIT_MESSAGE` |  |
+| `prTitle` | Pull Request title template | string | `"{{#if isPin}}Pin{{else}}Update{{/if}} dependency {{depName}} to version {{#if isRange}}{{newVersion}}{{else}}{{#if isMajor}}{{newVersionMajor}}.x{{else}}{{newVersion}}{{/if}}{{/if}}"` | `RENOVATE_PR_TITLE` |  |
+| `prBody` | Pull Request body template | string | `"This Pull Request updates dependency {{depName}} from version `{{currentVersion}}` to `{{newVersion}}`\n\n{{changelog}}"` | `RENOVATE_PR_BODY` |  |
 | `maintainYarnLock` | Keep yarn.lock files updated in base branch | boolean | `false` | `RENOVATE_MAINTAIN_YARN_LOCK` | `--maintain-yarn-lock` |
-| `yarnMaintenanceBranchName` | Branch name template when maintaining yarn.lock | string | `"renovate/yarn-lock"` |  |  |
-| `yarnMaintenanceCommitMessage` | Commit message template when maintaining yarn.lock | string | `"Renovate yarn.lock file"` |  |  |
-| `yarnMaintenancePrTitle` | Pull Request title template when maintaining yarn.lock | string | `"Renovate yarn.lock file"` |  |  |
-| `yarnMaintenancePrBody` | Pull Request body template when maintaining yarn.lock | string | `"This PR regenerates yarn.lock files based on the existing `package.json` files."` |  |  |
+| `yarnMaintenanceBranchName` | Branch name template when maintaining yarn.lock | string | `"renovate/yarn-lock"` | `RENOVATE_YARN_MAINTENANCE_BRANCH_NAME` |  |
+| `yarnMaintenanceCommitMessage` | Commit message template when maintaining yarn.lock | string | `"Renovate yarn.lock file"` | `RENOVATE_YARN_MAINTENANCE_COMMIT_MESSAGE` |  |
+| `yarnMaintenancePrTitle` | Pull Request title template when maintaining yarn.lock | string | `"Renovate yarn.lock file"` | `RENOVATE_YARN_MAINTENANCE_PR_TITLE` |  |
+| `yarnMaintenancePrBody` | Pull Request body template when maintaining yarn.lock | string | `"This PR regenerates yarn.lock files based on the existing `package.json` files."` | `RENOVATE_YARN_MAINTENANCE_PR_BODY` |  |
 | `groupName` | Human understandable name for the dependency group | string | `null` | `RENOVATE_GROUP_NAME` | `--group-name` |
 | `groupSlug` | Slug to use for group (e.g. in branch name). Will be calculated from groupName if null | string | `null` | `RENOVATE_GROUP_SLUG` | `--group-slug` |
-| `groupBranchName` | Branch name template for the group | string | `"renovate/{{groupSlug}}"` |  |  |
-| `groupCommitMessage` | Group commit message | string | `"Renovate {{groupName}} packages"` |  |  |
-| `groupPrTitle` | Pull Request title template for the group | string | `"Renovate {{groupName}} packages"` |  |  |
-| `groupPrBody` | Pull Request body template for the group | string | `"This PR renovates the package group \"{{groupName}}\"."` |  |  |
+| `groupBranchName` | Branch name template for the group | string | `"renovate/{{groupSlug}}"` | `RENOVATE_GROUP_BRANCH_NAME` |  |
+| `groupCommitMessage` | Group commit message | string | `"Renovate {{groupName}} packages"` | `RENOVATE_GROUP_COMMIT_MESSAGE` |  |
+| `groupPrTitle` | Pull Request title template for the group | string | `"Renovate {{groupName}} packages"` | `RENOVATE_GROUP_PR_TITLE` |  |
+| `groupPrBody` | Pull Request body template for the group | string | `"This PR renovates the package group \"{{groupName}}\"."` | `RENOVATE_GROUP_PR_BODY` |  |
 | `labels` | Labels to add to Pull Request | list | `[]` | `RENOVATE_LABELS` | `--labels` |
 | `assignees` | Assignees for Pull Request | list | `[]` | `RENOVATE_ASSIGNEES` | `--assignees` |
 | `reviewers` | Requested reviewers for Pull Requests (GitHub only) | list | `[]` | `RENOVATE_REVIEWERS` | `--reviewers` |
diff --git a/docs/design-decisions.md b/docs/design-decisions.md
index 2cdb3c1394..d31b30f2ed 100644
--- a/docs/design-decisions.md
+++ b/docs/design-decisions.md
@@ -8,14 +8,13 @@ No state storage is needed on `renovate` or GitHub/GitLab apart from what you se
 
 #### API only
 
-So far, nothing we need to do requires git directly. e.g. we do not need to perform a git clone of the entire repository. Therefore, all operations are performed via the API.
+So far, nothing we need to do requires a full `git clone` of the repository. e.g. we do not need to perform a git clone of the entire repository. Therefore, all operations are performed via the API.
 
 ## Synchronous Operation
 
 The script current processes repositories, package files, and dependencies within them all synchronously.
 
 - Greatly reduces chance of hitting simultaneous API rate limits
-- Implicitly enables any configuration that results in multiple commits in the same branch
 - Simplifies logging
 
 Note: Initial queries to NPM are done in parallel.
@@ -27,19 +26,12 @@ This allows examples such as token configured via environment variable and label
 
 ## Cascading Configuration
 
-Configuration options applied per-package file override those per-repository, which override those which are global (all repositories).
+Configuration options applied per-package override those applied per package-type, which override those per-repository, which override those which are global (all repositories).
 
-The following options apply per-package file:
+The following options can be configured down to a per-package type level:
 
 - Dependency Types
 - Ignored Dependencies
-- Labels
-- Assignees
-- Ignore Unstable
-- Ignore Future
-- Respect Latest
-- Recreate Closed
-- Recreate Unmergeable
 
 The following options apply per-repository:
 
@@ -51,6 +43,8 @@ The following options apply globally:
 
 - Log Level
 
+The remaining configuration options can be applied per-package.
+
 ## Automatic discovery of package.json locations
 
 Note: GitHub only.
@@ -61,19 +55,9 @@ This can be overridden by the configuration option `packageFiles`, where you lis
 
 ## Separate Branches per dependency
 
-`renovate` will maintain separate branches per-dependency. So if 20 dependencies need updating, there will be at least 20 branches/PRs. Although this may seem undesirable, it was considered even less desirable if all 20 were in the same Pull Request and it's up to the users to determine which dependency upgrade(s) caused the build to fail.
-
-However, it's still possible to override the default branch and PR name templates in such a way to produce a single branch for all dependencies. Here's an example configuration:
+By default, `renovate` will maintain separate branches per-dependency. So if 20 dependencies need updating, there will be at least 20 branches/PRs. Although this may seem undesirable, it was considered even less desirable if all 20 were in the same Pull Request and it's up to the users to determine which dependency upgrade(s) caused the build to fail.
 
-```javascript
-templates: {
-  branchName: 'renovate-all',
-  prTitle: 'Renovate dependencies',
-  prBody: 'This Pull Request is for package.json updates generated by the renovate utility.',
-},
-```
-
-This could be done via configuration file or inside `package.json`. Perhaps it could be useful to make this a directly configurable option in future.
+However, it's still possible to override the default branch and PR name templates in such a way to produce a single branch for all dependencies. The `groupName` configuration option can be used at a repository level (e.g. give it the value `All`) and then all dependency updates will be in the same branch/PR.
 
 ## One PR per Major release
 
@@ -83,6 +67,8 @@ This could be done via configuration file or inside `package.json`. Perhaps it c
 - It's also often the case that previous major versions continue receiving Minor or Patch updates.
 - Projects should get Minor and Patch updates for their current Major release even if a new Major release exists
 
+This can be overriden via the config option `separateMajorReleases`.
+
 ## Branch naming
 
 Branches are named like `renovate/webpack-1.x` instead of `renovate/webpack-1.2.0`.
@@ -90,7 +76,7 @@ Branches are named like `renovate/webpack-1.x` instead of `renovate/webpack-1.2.
 - Branches often receive updates (e.g. new patches) before they're merged.
 - Naming the branch like `1.x` means its name still names sense if a `1.2.1` release happens
 
-Note: Branch names are configurable using the `templates` field.
+Note: Branch names are configurable using string templates.
 
 ## Pull Request Recreation
 
@@ -99,9 +85,9 @@ This option is configurable.
 
 ## Range handling
 
-`renovate` always pins dependencies, instead of updating ranges. Even if the project is using tilde ranges, why not pin them for consistency if you're also using `renovate` every day?
+`renovate` prefers pinned dependency versions, instead of maintaining ranges. Even if the project is using tilde ranges, why not pin them for consistency if you're also using `renovate` every day?
 
-Perhaps this will be made configurable in future once requirements are understood.
+This is now configurable via the `pinVersions` configuration option.
 
 ## Rebasing Unmergeable Pull Requests
 
@@ -112,3 +98,13 @@ With the default behaviour of one branch per dependency, it's often that case th
 `renovate` will rebase any unmergeable branches and add the latest necessary commit on top of the most recent `master` commit.
 
 Note: `renovate` will only do this if the original branch hasn't been modified by anyone else.
+
+## Suppressing string templates from CLI
+
+String templates (e.g. commit or PR name) are not configurable via CLI options, in order to not pollute the CLI help and make it unreadable. If you must configure via CLI, use an environment variable instead. e.g.
+
+```sh
+$ RENOVATE_BRANCH_NAME=foo renovate
+```
+
+Alternatively, consider using a Configuration File.
diff --git a/lib/config/definitions.js b/lib/config/definitions.js
index bbb07e5af7..cf63fd384a 100644
--- a/lib/config/definitions.js
+++ b/lib/config/definitions.js
@@ -113,7 +113,6 @@ const options = [
     type: 'string',
     default: 'renovate/{{depName}}-{{newVersionMajor}}.x',
     cli: false,
-    env: false,
   },
   {
     name: 'commitMessage',
@@ -121,7 +120,6 @@ const options = [
     type: 'string',
     default: 'Update dependency {{depName}} to version {{newVersion}}',
     cli: false,
-    env: false,
   },
   {
     name: 'prTitle',
@@ -129,7 +127,6 @@ const options = [
     type: 'string',
     default: '{{#if isPin}}Pin{{else}}Update{{/if}} dependency {{depName}} to version {{#if isRange}}{{newVersion}}{{else}}{{#if isMajor}}{{newVersionMajor}}.x{{else}}{{newVersion}}{{/if}}{{/if}}',
     cli: false,
-    env: false,
   },
   {
     name: 'prBody',
@@ -137,7 +134,6 @@ const options = [
     type: 'string',
     default: 'This Pull Request updates dependency {{depName}} from version `{{currentVersion}}` to `{{newVersion}}`\n\n{{changelog}}',
     cli: false,
-    env: false,
   },
   // Yarn Lock Maintenance
   {
@@ -152,7 +148,6 @@ const options = [
     type: 'string',
     default: 'renovate/yarn-lock',
     cli: false,
-    env: false,
   },
   {
     name: 'yarnMaintenanceCommitMessage',
@@ -160,7 +155,6 @@ const options = [
     type: 'string',
     default: 'Renovate yarn.lock file',
     cli: false,
-    env: false,
   },
   {
     name: 'yarnMaintenancePrTitle',
@@ -168,7 +162,6 @@ const options = [
     type: 'string',
     default: 'Renovate yarn.lock file',
     cli: false,
-    env: false,
   },
   {
     name: 'yarnMaintenancePrBody',
@@ -176,7 +169,6 @@ const options = [
     type: 'string',
     default: 'This PR regenerates yarn.lock files based on the existing `package.json` files.',
     cli: false,
-    env: false,
   },
   // Dependency Groups
   {
@@ -197,7 +189,6 @@ const options = [
     type: 'string',
     default: 'renovate/{{groupSlug}}',
     cli: false,
-    env: false,
   },
   {
     name: 'groupCommitMessage',
@@ -205,7 +196,6 @@ const options = [
     type: 'string',
     default: 'Renovate {{groupName}} packages',
     cli: false,
-    env: false,
   },
   {
     name: 'groupPrTitle',
@@ -213,7 +203,6 @@ const options = [
     type: 'string',
     default: 'Renovate {{groupName}} packages',
     cli: false,
-    env: false,
   },
   {
     name: 'groupPrBody',
@@ -221,7 +210,6 @@ const options = [
     type: 'string',
     default: 'This PR renovates the package group "{{groupName}}".',
     cli: false,
-    env: false,
   },
   // Pull Request options
   {
-- 
GitLab