From 04087026dd7631f3f65b56cb3d2f15e35555e8a5 Mon Sep 17 00:00:00 2001 From: Chris Swithinbank <swithinbank@gmail.com> Date: Mon, 14 May 2018 17:46:37 +0200 Subject: [PATCH] Add squash merges option for editorial workflow (#1330) --- .all-contributorsrc | 3 ++- README.md | 2 +- src/backends/git-gateway/implementation.js | 1 + src/backends/github/API.js | 2 ++ src/backends/github/implementation.js | 3 ++- website/site/content/docs/beta-features.md | 11 +++++++++++ 6 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 6b0deed1..afb46b4b 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -672,7 +672,8 @@ "avatar_url": "https://avatars2.githubusercontent.com/u/357379?v=4", "profile": "http://chrisswithinbank.net/", "contributions": [ - "doc" + "doc", + "code" ] }, { diff --git a/README.md b/README.md index a0b5a136..05afa5c6 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ These wonderful folks are responsible for developing and maintaining Netlify CMS | [<img src="https://avatars0.githubusercontent.com/u/250958?v=4" width="100px;"/><br /><sub><b>Etienne Bernard</b></sub>](https://github.com/ebernard)<br />[π](https://github.com/netlify/netlify-cms/commits?author=ebernard "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/871660?v=4" width="100px;"/><br /><sub><b>Eli Williamson</b></sub>](http://eliwilliamson.com)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=eliwilliamson "Code") [π¨](#design-eliwilliamson "Design") | [<img src="https://avatars0.githubusercontent.com/u/858837?v=4" width="100px;"/><br /><sub><b>Covington Doan</b></sub>](https://www.covingtondoan.com)<br />[π](https://github.com/netlify/netlify-cms/commits?author=covingtondoan "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/1299080?v=4" width="100px;"/><br /><sub><b>Lennart Ziburski</b></sub>](http://lennartziburski.com)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=ziburski "Code") [π¨](#design-ziburski "Design") [π](https://github.com/netlify/netlify-cms/commits?author=ziburski "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/387640?v=4" width="100px;"/><br /><sub><b>Darrel O'Pry</b></sub>](http://darrelopry.com)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=dopry "Code") [π](#infra-dopry "Infrastructure (Hosting, Build-Tools, etc)") [β οΈ](https://github.com/netlify/netlify-cms/commits?author=dopry "Tests") | [<img src="https://avatars1.githubusercontent.com/u/13856868?v=4" width="100px;"/><br /><sub><b>Erin Symons</b></sub>](https://github.com/yourfrienderin)<br />[π](https://github.com/netlify/netlify-cms/commits?author=yourfrienderin "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/5200555?v=4" width="100px;"/><br /><sub><b>Austin Green</b></sub>](https://github.com/AustinGreen)<br />[π](https://github.com/netlify/netlify-cms/commits?author=AustinGreen "Documentation") [π‘](#example-AustinGreen "Examples") | | [<img src="https://avatars2.githubusercontent.com/u/799360?v=4" width="100px;"/><br /><sub><b>Bryan Robinson</b></sub>](http://bryanlrobinson.com)<br />[π](https://github.com/netlify/netlify-cms/commits?author=brob "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/561983?v=4" width="100px;"/><br /><sub><b>Darren</b></sub>](https://github.com/dardub)<br />[π](https://github.com/netlify/netlify-cms/commits?author=dardub "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/576512?v=4" width="100px;"/><br /><sub><b>Richard Pullinger</b></sub>](http://www.richardpullinger.com)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=rpullinger "Code") | [<img src="https://avatars1.githubusercontent.com/u/3718939?v=4" width="100px;"/><br /><sub><b>Taylor Bryant</b></sub>](https://taylorbryant.blog)<br />[π](https://github.com/netlify/netlify-cms/commits?author=taylorbryant "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/5881826?v=4" width="100px;"/><br /><sub><b>kvanerkelens</b></sub>](https://github.com/kvanerkelens)<br />[π](https://github.com/netlify/netlify-cms/commits?author=kvanerkelens "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/8291663?v=4" width="100px;"/><br /><sub><b>Patrick Sier</b></sub>](https://patsier.com/)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=pjsier "Code") | [<img src="https://avatars2.githubusercontent.com/u/6132191?v=4" width="100px;"/><br /><sub><b>Christian Nolte</b></sub>](http://noltech.net)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=drlogout "Code") | | [<img src="https://avatars1.githubusercontent.com/u/3818?v=4" width="100px;"/><br /><sub><b>Edward Betts</b></sub>](http://edwardbetts.com/)<br />[π](https://github.com/netlify/netlify-cms/commits?author=EdwardBetts "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/8771435?v=4" width="100px;"/><br /><sub><b>Josh Hardman</b></sub>](https://github.com/jhardman0830)<br />[π](https://github.com/netlify/netlify-cms/commits?author=jhardman0830 "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/11616378?v=4" width="100px;"/><br /><sub><b>Mantas</b></sub>](https://behance.net/mistermantas)<br />[π](https://github.com/netlify/netlify-cms/commits?author=mistermantas "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/5244986?v=4" width="100px;"/><br /><sub><b>Marco Biedermann</b></sub>](https://www.marcobiedermann.com)<br />[π](https://github.com/netlify/netlify-cms/commits?author=marcobiedermann "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/7525670?v=4" width="100px;"/><br /><sub><b>Max Stoiber</b></sub>](https://mxstbr.blog/newsletter)<br />[π](https://github.com/netlify/netlify-cms/commits?author=mxstbr "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/89368?v=4" width="100px;"/><br /><sub><b>Vyacheslav Matyukhin</b></sub>](http://berekuk.ru)<br />[π](https://github.com/netlify/netlify-cms/commits?author=berekuk "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/9059048?v=4" width="100px;"/><br /><sub><b>jimmaaay</b></sub>](https://jimmythompson.me)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=jimmaaay "Code") | -| [<img src="https://avatars3.githubusercontent.com/u/802086?v=4" width="100px;"/><br /><sub><b>LuΓs Miguel</b></sub>](https://github.com/Quicksaver)<br />[π](https://github.com/netlify/netlify-cms/issues?q=author%3AQuicksaver "Bug reports") [π»](https://github.com/netlify/netlify-cms/commits?author=Quicksaver "Code") | [<img src="https://avatars2.githubusercontent.com/u/357379?v=4" width="100px;"/><br /><sub><b>Chris Swithinbank</b></sub>](http://chrisswithinbank.net/)<br />[π](https://github.com/netlify/netlify-cms/commits?author=delucis "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/1262221?v=4" width="100px;"/><br /><sub><b>remmah</b></sub>](https://github.com/remmah)<br />[π](https://github.com/netlify/netlify-cms/commits?author=remmah "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/29388?v=4" width="100px;"/><br /><sub><b>Sumeet Jain</b></sub>](http://sumeetjain.com)<br />[π](https://github.com/netlify/netlify-cms/commits?author=sumeetjain "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/26816046?v=4" width="100px;"/><br /><sub><b>Sagar Khatri</b></sub>](https://github.com/ragasirtahk)<br />[π](https://github.com/netlify/netlify-cms/commits?author=ragasirtahk "Documentation") [π‘](#example-ragasirtahk "Examples") | [<img src="https://avatars0.githubusercontent.com/u/8182932?v=4" width="100px;"/><br /><sub><b>Kevin Doocey</b></sub>](https://www.dooceykev.in)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=Doocey "Code") | [<img src="https://avatars0.githubusercontent.com/u/31023010?v=4" width="100px;"/><br /><sub><b>Swieckowski</b></sub>](https://www.linkedin.com/in/arthur-swieckowski/)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=Swieckowski "Code") [π](https://github.com/netlify/netlify-cms/commits?author=Swieckowski "Documentation") [β οΈ](https://github.com/netlify/netlify-cms/commits?author=Swieckowski "Tests") | +| [<img src="https://avatars3.githubusercontent.com/u/802086?v=4" width="100px;"/><br /><sub><b>LuΓs Miguel</b></sub>](https://github.com/Quicksaver)<br />[π](https://github.com/netlify/netlify-cms/issues?q=author%3AQuicksaver "Bug reports") [π»](https://github.com/netlify/netlify-cms/commits?author=Quicksaver "Code") | [<img src="https://avatars2.githubusercontent.com/u/357379?v=4" width="100px;"/><br /><sub><b>Chris Swithinbank</b></sub>](http://chrisswithinbank.net/)<br />[π](https://github.com/netlify/netlify-cms/commits?author=delucis "Documentation") [π»](https://github.com/netlify/netlify-cms/commits?author=delucis "Code") | [<img src="https://avatars3.githubusercontent.com/u/1262221?v=4" width="100px;"/><br /><sub><b>remmah</b></sub>](https://github.com/remmah)<br />[π](https://github.com/netlify/netlify-cms/commits?author=remmah "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/29388?v=4" width="100px;"/><br /><sub><b>Sumeet Jain</b></sub>](http://sumeetjain.com)<br />[π](https://github.com/netlify/netlify-cms/commits?author=sumeetjain "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/26816046?v=4" width="100px;"/><br /><sub><b>Sagar Khatri</b></sub>](https://github.com/ragasirtahk)<br />[π](https://github.com/netlify/netlify-cms/commits?author=ragasirtahk "Documentation") [π‘](#example-ragasirtahk "Examples") | [<img src="https://avatars0.githubusercontent.com/u/8182932?v=4" width="100px;"/><br /><sub><b>Kevin Doocey</b></sub>](https://www.dooceykev.in)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=Doocey "Code") | [<img src="https://avatars0.githubusercontent.com/u/31023010?v=4" width="100px;"/><br /><sub><b>Swieckowski</b></sub>](https://www.linkedin.com/in/arthur-swieckowski/)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=Swieckowski "Code") [π](https://github.com/netlify/netlify-cms/commits?author=Swieckowski "Documentation") [β οΈ](https://github.com/netlify/netlify-cms/commits?author=Swieckowski "Tests") | | [<img src="https://avatars2.githubusercontent.com/u/283419?v=4" width="100px;"/><br /><sub><b>Tim Carry</b></sub>](http://www.pixelastic.com/)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=pixelastic "Code") [π¨](#design-pixelastic "Design") [π](https://github.com/netlify/netlify-cms/commits?author=pixelastic "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/30510616?v=4" width="100px;"/><br /><sub><b>Sol Park</b></sub>](https://github.com/solpark)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=solpark "Code") | [<img src="https://avatars0.githubusercontent.com/u/29218846?v=4" width="100px;"/><br /><sub><b>Michael Romani</b></sub>](https://github.com/MichaelRomani)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=MichaelRomani "Code") | [<img src="https://avatars1.githubusercontent.com/u/15175868?v=4" width="100px;"/><br /><sub><b>Xifeng Jin</b></sub>](http://linkedin/in/xifengjin88)<br />[π](https://github.com/netlify/netlify-cms/issues?q=author%3Axifengjin88 "Bug reports") [π»](https://github.com/netlify/netlify-cms/commits?author=xifengjin88 "Code") | [<img src="https://avatars1.githubusercontent.com/u/372831?v=4" width="100px;"/><br /><sub><b>Pedro Duarte</b></sub>](http://pedroduarte.me)<br />[π](https://github.com/netlify/netlify-cms/issues?q=author%3Apeduarte "Bug reports") [π»](https://github.com/netlify/netlify-cms/commits?author=peduarte "Code") [π](https://github.com/netlify/netlify-cms/commits?author=peduarte "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/6064830?v=4" width="100px;"/><br /><sub><b>Antonio Argote</b></sub>](http://antonioargote.com)<br />[π¨](#design-Strangehill "Design") | [<img src="https://avatars3.githubusercontent.com/u/1479451?v=4" width="100px;"/><br /><sub><b>Kristaps Taube</b></sub>](https://www.ktaube.com)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=ktaube "Code") | | [<img src="https://avatars3.githubusercontent.com/u/26639499?v=4" width="100px;"/><br /><sub><b>David Ko</b></sub>](https://github.com/daveyko)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=daveyko "Code") | [<img src="https://avatars3.githubusercontent.com/u/440562?v=4" width="100px;"/><br /><sub><b>IΓ±aki GarcΓa</b></sub>](http://www.txorua.com)<br />[π¨](#design-igarbla "Design") | [<img src="https://avatars3.githubusercontent.com/u/27162255?v=4" width="100px;"/><br /><sub><b>Sam</b></sub>](https://github.com/gazebosx3)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=gazebosx3 "Code") | [<img src="https://avatars1.githubusercontent.com/u/174777?v=4" width="100px;"/><br /><sub><b>Josh Dzielak</b></sub>](https://dzello.com)<br />[π](https://github.com/netlify/netlify-cms/commits?author=dzello "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/2193?v=4" width="100px;"/><br /><sub><b>Jeremy Bise</b></sub>](http://thosegeeks.com)<br />[π](https://github.com/netlify/netlify-cms/commits?author=jeremybise "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/13282103?v=4" width="100px;"/><br /><sub><b>terrierscript</b></sub>](https://terrierscript.com)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=terrierscript "Code") | [<img src="https://avatars0.githubusercontent.com/u/3949335?v=4" width="100px;"/><br /><sub><b>Christopher Geary</b></sub>](https://twitter.com/crgeary)<br />[π](#plugin-crgeary "Plugin/utility libraries") | | [<img src="https://avatars0.githubusercontent.com/u/23248886?v=4" width="100px;"/><br /><sub><b>Brian Macdonald</b></sub>](https://github.com/brianlmacdonald)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=brianlmacdonald "Code") | [<img src="https://avatars1.githubusercontent.com/u/15092?v=4" width="100px;"/><br /><sub><b>John Vandenberg</b></sub>](https://jayvdb.github.io/)<br />[π](https://github.com/netlify/netlify-cms/commits?author=jayvdb "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/24911956?v=4" width="100px;"/><br /><sub><b>MarkZither</b></sub>](https://github.com/MarkZither)<br />[π](https://github.com/netlify/netlify-cms/commits?author=MarkZither "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/9257284?v=4" width="100px;"/><br /><sub><b>Rob Phoenix</b></sub>](https://www.robphoenix.com)<br />[π](https://github.com/netlify/netlify-cms/commits?author=robphoenix "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/3028764?v=4" width="100px;"/><br /><sub><b>Steve Lathrop</b></sub>](https://www.SteLa.io)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=slathrop "Code") [π](https://github.com/netlify/netlify-cms/commits?author=slathrop "Documentation") [π‘](#example-slathrop "Examples") | [<img src="https://avatars0.githubusercontent.com/u/10004167?v=4" width="100px;"/><br /><sub><b>Maciej Matuszewski</b></sub>](https://github.com/maciejmatu)<br />[π»](https://github.com/netlify/netlify-cms/commits?author=maciejmatu "Code") | [<img src="https://avatars0.githubusercontent.com/u/36023898?v=4" width="100px;"/><br /><sub><b>Eko Eryanto</b></sub>](https://github.com/ekoeryanto)<br />[π](#plugin-ekoeryanto "Plugin/utility libraries") | diff --git a/src/backends/git-gateway/implementation.js b/src/backends/git-gateway/implementation.js index 447c5324..fe9b8ea0 100644 --- a/src/backends/git-gateway/implementation.js +++ b/src/backends/git-gateway/implementation.js @@ -70,6 +70,7 @@ export default class GitGateway extends GitHubBackend { branch: this.branch, tokenPromise: this.tokenPromise, commitAuthor: pick(userData, ["name", "email"]), + squash_merges: this.squash_merges, }); return userData; } else { diff --git a/src/backends/github/API.js b/src/backends/github/API.js index 459524dd..783bb041 100644 --- a/src/backends/github/API.js +++ b/src/backends/github/API.js @@ -15,6 +15,7 @@ export default class API { this.branch = config.branch || "master"; this.repo = config.repo || ""; this.repoURL = `/repos/${ this.repo }`; + this.merge_method = config.squash_merges ? "squash" : "merge"; } user() { @@ -635,6 +636,7 @@ export default class API { body: JSON.stringify({ commit_message: "Automatically generated. Merged on Netlify CMS.", sha: headSha, + merge_method: this.merge_method, }), }) .catch((error) => { diff --git a/src/backends/github/implementation.js b/src/backends/github/implementation.js index 2663e15d..2fa63f4b 100644 --- a/src/backends/github/implementation.js +++ b/src/backends/github/implementation.js @@ -17,6 +17,7 @@ export default class GitHub { this.branch = config.getIn(["backend", "branch"], "master").trim(); this.api_root = config.getIn(["backend", "api_root"], "https://api.github.com"); this.token = ''; + this.squash_merges = config.getIn(["backend", "squash_merges"]); } authComponent() { @@ -29,7 +30,7 @@ export default class GitHub { authenticate(state) { this.token = state.token; - this.api = new API({ token: this.token, branch: this.branch, repo: this.repo, api_root: this.api_root }); + this.api = new API({ token: this.token, branch: this.branch, repo: this.repo, api_root: this.api_root, squash_merges: this.squash_merges }); return this.api.user().then(user => this.api.hasWriteAccess().then((isCollab) => { // Unauthorized user diff --git a/website/site/content/docs/beta-features.md b/website/site/content/docs/beta-features.md index 47e6fada..e0ed55b9 100644 --- a/website/site/content/docs/beta-features.md +++ b/website/site/content/docs/beta-features.md @@ -77,3 +77,14 @@ import styles from '!css-loader!sass-loader!../main.scss' CMS.registerPreviewStyle(styles.toString(), { raw: true }) ``` +## Squash merge GitHub pull requests +When using the [Editorial Workflow](/docs/configuration-options/#publish-mode) with the `github` or `git-gateway` backends, Netlify CMS creates a pull request for each unpublished entry. Every time the unpublished entry is changed and saved, a new commit is added to the pull request. When the entry is published, the pull request is merged, and all of those commits are added to your project commit history in a merge commit. + +The squash merge option causes all commits to be "squashed" into a single commit when the pull request is merged, and the resulting commit is rebased onto the target branch, avoiding the merge commit altogether. + +To enable this feature, you can set the following option in your `config.yml`: + +```yaml +backend: + squash_merges: true +```