improvement: allow custom workflow branch name prefix (#1494)
This commit is contained in:
parent
62b2f9c06b
commit
da0f520f0d
@ -4,13 +4,12 @@ import { uniq, initial, last, get, find, hasIn, partial, result } from 'lodash';
|
|||||||
import { filterPromises, resolvePromiseProperties } from 'netlify-cms-lib-util';
|
import { filterPromises, resolvePromiseProperties } from 'netlify-cms-lib-util';
|
||||||
import { APIError, EditorialWorkflowError } from 'netlify-cms-lib-util';
|
import { APIError, EditorialWorkflowError } from 'netlify-cms-lib-util';
|
||||||
|
|
||||||
const CMS_BRANCH_PREFIX = 'cms/';
|
|
||||||
|
|
||||||
export default class API {
|
export default class API {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
this.api_root = config.api_root || 'https://api.github.com';
|
this.api_root = config.api_root || 'https://api.github.com';
|
||||||
this.token = config.token || false;
|
this.token = config.token || false;
|
||||||
this.branch = config.branch || 'master';
|
this.branch = config.branch || 'master';
|
||||||
|
this.workflow_branch_prefix = config.workflow_branch_prefix;
|
||||||
this.repo = config.repo || '';
|
this.repo = config.repo || '';
|
||||||
this.repoURL = `/repos/${this.repo}`;
|
this.repoURL = `/repos/${this.repo}`;
|
||||||
this.merge_method = config.squash_merges ? 'squash' : 'merge';
|
this.merge_method = config.squash_merges ? 'squash' : 'merge';
|
||||||
@ -91,7 +90,7 @@ export default class API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
generateBranchName(basename) {
|
generateBranchName(basename) {
|
||||||
return `${CMS_BRANCH_PREFIX}${basename}`;
|
return `${this.workflow_branch_prefix}/${basename}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkMetadataRef() {
|
checkMetadataRef() {
|
||||||
@ -650,7 +649,7 @@ export default class API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assertCmsBranch(branchName) {
|
assertCmsBranch(branchName) {
|
||||||
return branchName.startsWith(CMS_BRANCH_PREFIX);
|
return branchName.startsWith(`${this.workflow_branch_prefix}/`);
|
||||||
}
|
}
|
||||||
|
|
||||||
patchBranch(branchName, sha, opts = {}) {
|
patchBranch(branchName, sha, opts = {}) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import trimStart from 'lodash/trimStart';
|
import { trim, trimStart } from 'lodash';
|
||||||
import semaphore from 'semaphore';
|
import semaphore from 'semaphore';
|
||||||
import AuthenticationPage from './AuthenticationPage';
|
import AuthenticationPage from './AuthenticationPage';
|
||||||
import API from './API';
|
import API from './API';
|
||||||
@ -22,6 +22,8 @@ export default class GitHub {
|
|||||||
|
|
||||||
this.repo = config.getIn(['backend', 'repo'], '');
|
this.repo = config.getIn(['backend', 'repo'], '');
|
||||||
this.branch = config.getIn(['backend', 'branch'], 'master').trim();
|
this.branch = config.getIn(['backend', 'branch'], 'master').trim();
|
||||||
|
this.workflow_branch_prefix =
|
||||||
|
trim(config.getIn(['backend', 'workflow_branch_prefix'], ''), '/ ') || 'cms';
|
||||||
this.api_root = config.getIn(['backend', 'api_root'], 'https://api.github.com');
|
this.api_root = config.getIn(['backend', 'api_root'], 'https://api.github.com');
|
||||||
this.token = '';
|
this.token = '';
|
||||||
this.squash_merges = config.getIn(['backend', 'squash_merges']);
|
this.squash_merges = config.getIn(['backend', 'squash_merges']);
|
||||||
@ -40,6 +42,7 @@ export default class GitHub {
|
|||||||
this.api = new API({
|
this.api = new API({
|
||||||
token: this.token,
|
token: this.token,
|
||||||
branch: this.branch,
|
branch: this.branch,
|
||||||
|
workflow_branch_prefix: this.workflow_branch_prefix,
|
||||||
repo: this.repo,
|
repo: this.repo,
|
||||||
api_root: this.api_root,
|
api_root: this.api_root,
|
||||||
squash_merges: this.squash_merges,
|
squash_merges: this.squash_merges,
|
||||||
@ -158,7 +161,7 @@ export default class GitHub {
|
|||||||
branches.map(branch => {
|
branches.map(branch => {
|
||||||
promises.push(
|
promises.push(
|
||||||
new Promise(resolve => {
|
new Promise(resolve => {
|
||||||
const slug = branch.ref.split('refs/heads/cms/').pop();
|
const slug = branch.ref.split(`refs/heads/${this.workflow_branch_prefix}/`).pop();
|
||||||
return sem.take(() =>
|
return sem.take(() =>
|
||||||
this.api
|
this.api
|
||||||
.readUnpublishedBranchFile(slug)
|
.readUnpublishedBranchFile(slug)
|
||||||
|
@ -120,3 +120,28 @@ Template tags produce the following output:
|
|||||||
- `{{collection}}`: the name of the collection containing the entry changed
|
- `{{collection}}`: the name of the collection containing the entry changed
|
||||||
|
|
||||||
- `{{path}}`: the full path to the file changed
|
- `{{path}}`: the full path to the file changed
|
||||||
|
|
||||||
|
## Custom Editorial Workflow branch name prefixes
|
||||||
|
|
||||||
|
When using [editorial workflow](), a branch is created for each entry. By default the branch name
|
||||||
|
follows this template:
|
||||||
|
|
||||||
|
```
|
||||||
|
cms/{{slug}}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can customize the `cms` portion by setting `workflow_branch_prefix` under `backend` in your
|
||||||
|
`config.yml`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
backend:
|
||||||
|
name: some-backend
|
||||||
|
branch: dev
|
||||||
|
workflow_branch_prefix: cms-dev
|
||||||
|
```
|
||||||
|
|
||||||
|
The above configuration would change the branch name template to:
|
||||||
|
|
||||||
|
```
|
||||||
|
cms-dev/{{slug}}
|
||||||
|
```
|
Loading…
x
Reference in New Issue
Block a user