Skip to content

Commit df68be8

Browse files
authored
Merge pull request #13 from implausible/feature/add-hook-callbacks
Add hook callbacks for rebase and merge operations
2 parents b7ff2ad + 078680a commit df68be8

11 files changed

Lines changed: 108 additions & 13 deletions

File tree

docs/Feature.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Starts a git flow "feature"
2525
| featureName | <code>String</code> | The name of the feature to start |
2626
| options | <code>Object</code> | Options for start feature |
2727

28+
2829
<a name="Feature+finishFeature"></a>
2930
### feature.finishFeature(featureName, options) ⇒ <code>Commit</code>
3031
Finishes a git flow "feature"
@@ -38,6 +39,17 @@ Finishes a git flow "feature"
3839
| featureName | <code>String</code> | The name of the feature to finish |
3940
| options | <code>Object</code> | Options for finish feature |
4041

42+
**Options**:
43+
44+
| Option | Type | Description |
45+
| --- | --- | --- |
46+
| keepBranch | Boolean | Keep the branch after merge |
47+
| isRebase | Boolean | Use Rebase instead of merge |
48+
| preRebaseCallback | Function | Callback that is fired before rebase occurs, only applicable if **isRebase** is truthy. If the callback returns a Promise, the **preRebaseCallback** promise must succeed before the rebase occurs. The **preRebaseCallback** is called with development branch name and the feature branch name. |
49+
| processMergeMessageCallback | Function | Callback that is fired before merge occurs, only applicable if **isRebase** is falsy. If the callback returns a Promise, the **processMergeMessageCallback** promise must succeed before the merge occurs. The result of the **processMergeMessageCallback** must be a string or a promise that resolves to a string, as that message will be used for the merge message. the **processMergeMessageCallback** will be called with the generated merge message as a parameter. |
50+
| postMergeCallback | Function | Callback fired after a successful merge occurs. |
51+
| beforeRebaseFinishCallback | Function | Callback that is fired right before a rebase is finished with metadata reflecting the rebase operation in full. See [Rebase Branches](http://www.nodegit.org/api/repository/#rebaseBranches) |
52+
4153
<a name="Feature.startFeature"></a>
4254
### Feature.startFeature(repo, featureName, options) ⇒ <code>Branch</code>
4355
Starts a git flow "feature"
@@ -66,3 +78,13 @@ Finishes a git flow "feature"
6678
| featureName | <code>String</code> | The name of the feature to finish |
6779
| options | <code>Object</code> | Options for finish feature |
6880

81+
**Options**:
82+
83+
| Option | Type | Description |
84+
| --- | --- | --- |
85+
| keepBranch | Boolean | Keep the branch after merge |
86+
| isRebase | Boolean | Use Rebase instead of merge |
87+
| preRebaseCallback | Function | Callback that is fired before rebase occurs, only applicable if **isRebase** is truthy. If the callback returns a Promise, the **preRebaseCallback** promise must succeed before the rebase occurs. The **preRebaseCallback** is called with development branch name and the feature branch name. |
88+
| processMergeMessageCallback | Function | Callback that is fired before merge occurs, only applicable if **isRebase** is falsy. If the callback returns a Promise, the **processMergeMessageCallback** promise must succeed before the merge occurs. The result of the **processMergeMessageCallback** must be a string or a promise that resolves to a string, as that message will be used for the merge message. the **processMergeMessageCallback** will be called with the generated merge message as a parameter. |
89+
| postMergeCallback | Function | Callback fired after a successful merge occurs. |
90+
| beforeRebaseFinishCallback | Function | Callback that is fired right before a rebase is finished with metadata reflecting the rebase operation in full. See [Rebase Branches](http://www.nodegit.org/api/repository/#rebaseBranches) |

docs/Hotfix.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ Finishes a git flow "hotfix"
3838
| hotfixVersion | <code>String</code> | The version of the hotfix to finish |
3939
| options | <code>Object</code> | Options for finish hotfix |
4040

41+
**Options**:
42+
43+
| Option | Type | Description |
44+
| --- | --- | --- |
45+
| keepBranch | Boolean | Keep the branch after merge |
46+
| message | String | Tag will be created with this message |
47+
| processMergeMessageCallback | Function | Callback that is fired before merge occurs. If the callback returns a Promise, the **processMergeMessageCallback** promise must succeed before the merge occurs. The result of the **processMergeMessageCallback** must be a string or a promise that resolves to a string, as that message will be used for the merge message. the **processMergeMessageCallback** will be called with the generated merge message as a parameter. |
48+
| postDevelopMergeCallback | Function | Callback fired after a successful merge with development occurs. |
49+
| postMasterMergeCallback | Function | Callback fired after a successful merge with master occurs. |
50+
4151
<a name="Hotfix.startHotfix"></a>
4252
### Hotfix.startHotfix(repo, hotfixVersion, options) ⇒ <code>Branch</code>
4353
Starts a git flow "hotfix"
@@ -66,3 +76,12 @@ Finishes a git flow "hotfix"
6676
| hotfixVersion | <code>String</code> | The version of the hotfix to finish |
6777
| options | <code>Object</code> | Options for finish hotfix |
6878

79+
**Options**:
80+
81+
| Option | Type | Description |
82+
| --- | --- | --- |
83+
| keepBranch | Boolean | Keep the branch after merge |
84+
| message | String | Tag will be created with this message |
85+
| processMergeMessageCallback | Function | Callback that is fired before merge occurs. If the callback returns a Promise, the **processMergeMessageCallback** promise must succeed before the merge occurs. The result of the **processMergeMessageCallback** must be a string or a promise that resolves to a string, as that message will be used for the merge message. the **processMergeMessageCallback** will be called with the generated merge message as a parameter. |
86+
| postDevelopMergeCallback | Function | Callback fired after a successful merge with development occurs. |
87+
| postMasterMergeCallback | Function | Callback fired after a successful merge with master occurs. |

docs/Release.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ Finishes a git flow "release"
3838
| releaseVersion | <code>String</code> | The name of the release to finish |
3939
| options | <code>Object</code> | Options for finish release |
4040

41+
**Options**:
42+
43+
| Option | Type | Description |
44+
| --- | --- | --- |
45+
| keepBranch | Boolean | Keep the branch after merge |
46+
| message | String | Tag will be created with this message |
47+
| processMergeMessageCallback | Function | Callback that is fired before merge occurs. If the callback returns a Promise, the **processMergeMessageCallback** promise must succeed before the merge occurs. The result of the **processMergeMessageCallback** must be a string or a promise that resolves to a string, as that message will be used for the merge message. the **processMergeMessageCallback** will be called with the generated merge message as a parameter. |
48+
| postDevelopMergeCallback | Function | Callback fired after a successful merge with development occurs. |
49+
| postMasterMergeCallback | Function | Callback fired after a successful merge with master occurs. |
50+
4151
<a name="Release.startRelease"></a>
4252
### Release.startRelease(repo, releaseVersion, options) ⇒ <code>Branch</code>
4353
Starts a git flow "release"
@@ -66,3 +76,12 @@ Finishes a git flow "release"
6676
| releaseVersion | <code>String</code> | The name of the release to finish |
6777
| options | <code>Object</code> | Options for finish release |
6878

79+
**Options**:
80+
81+
| Option | Type | Description |
82+
| --- | --- | --- |
83+
| keepBranch | Boolean | Keep the branch after merge |
84+
| message | String | Tag will be created with this message |
85+
| processMergeMessageCallback | Function | Callback that is fired before merge occurs. If the callback returns a Promise, the **processMergeMessageCallback** promise must succeed before the merge occurs. The result of the **processMergeMessageCallback** must be a string or a promise that resolves to a string, as that message will be used for the merge message. the **processMergeMessageCallback** will be called with the generated merge message as a parameter. |
86+
| postDevelopMergeCallback | Function | Callback fired after a successful merge with development occurs. |
87+
| postMasterMergeCallback | Function | Callback fired after a successful merge with master occurs. |

spec/tests/Feature-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const expectFinishFeatureSuccess = function expectFinishFeatureSuccess(featureBr
3232

3333
if (!keepBranch) {
3434
return promise.catch((err) => {
35-
expect(err.message).toBe(`Cannot locate local branch '${featureBranch.shorthand()}'`);
35+
expect(err.message.toLowerCase()).toBe(`cannot locate local branch '${featureBranch.shorthand().toLowerCase()}'`);
3636
});
3737
}
3838

spec/tests/Hotfix-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const expectFinishHotfixSuccess = function expectFinishHotfixSuccess(
5656
if (!keepBranch) {
5757
return promise
5858
.catch((err) => {
59-
expect(err.message).toBe(`Cannot locate local branch '${hotfixBranch.shorthand()}'`);
59+
expect(err.message.toLowerCase()).toBe(`cannot locate local branch '${hotfixBranch.shorthand().toLowerCase()}'`);
6060
});
6161
}
6262

spec/tests/Release-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const expectFinishReleaseSuccess = function expectFinishReleaseSuccess(
5656
if (!keepBranch) {
5757
return promise
5858
.catch((err) => {
59-
expect(err.message).toBe(`Cannot locate local branch '${releaseBranch.shorthand()}'`);
59+
expect(err.message.toLowerCase()).toBe(`cannot locate local branch '${releaseBranch.shorthand().toLowerCase()}'`);
6060
});
6161
}
6262

src/Feature.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@ class Feature {
7070
* @return {Commit} The commit created by finishing the feature
7171
*/
7272
static finishFeature(repo, featureName, options = {}) {
73-
const {keepBranch, isRebase, processMergeMessageCallback} = options;
73+
const {
74+
keepBranch,
75+
isRebase,
76+
preRebaseCallback = () => {},
77+
processMergeMessageCallback,
78+
postMergeCallback = () => {},
79+
beforeRebaseFinishCallback = () => {}
80+
} = options;
7481

7582
if (!repo) {
7683
return Promise.reject(new Error('Repo is required'));
@@ -86,10 +93,11 @@ class Feature {
8693
let featureCommit;
8794
let cancelDevelopMerge;
8895
let mergeCommit;
96+
let developBranchName;
8997
let featureBranchName;
9098
return Config.getConfig(repo)
9199
.then((config) => {
92-
const developBranchName = config['gitflow.branch.develop'];
100+
developBranchName = config['gitflow.branch.develop'];
93101
featureBranchName = config['gitflow.prefix.feature'] + featureName;
94102

95103
return Promise.all(
@@ -113,9 +121,11 @@ class Feature {
113121
cancelDevelopMerge = isSameCommit || isRebase;
114122

115123
if (!cancelDevelopMerge) {
116-
return utils.Repo.merge(developBranch, featureBranch, repo, processMergeMessageCallback);
124+
return utils.Repo.merge(developBranch, featureBranch, repo, processMergeMessageCallback)
125+
.then(utils.InjectIntermediateCallback(postMergeCallback));
117126
} else if (isRebase && !isSameCommit) {
118-
return utils.Repo.rebase(developBranch, featureBranch, repo);
127+
return Promise.resolve(preRebaseCallback(developBranchName, featureBranchName))
128+
.then(() => utils.Repo.rebase(developBranch, featureBranch, repo, beforeRebaseFinishCallback));
119129
}
120130
return Promise.resolve();
121131
})

src/Hotfix.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ class Hotfix {
6363
* @return {Commit} The commit created by finishing the hotfix
6464
*/
6565
static finishHotfix(repo, hotfixVersion, options = {}) {
66-
const {keepBranch, message, processMergeMessageCallback} = options;
66+
const {
67+
keepBranch,
68+
message,
69+
processMergeMessageCallback,
70+
postDevelopMergeCallback = () => {},
71+
postMasterMergeCallback = () => {}
72+
} = options;
6773

6874
if (!repo) {
6975
return Promise.reject(new Error('Repo is required'));
@@ -116,7 +122,8 @@ class Hotfix {
116122

117123
// Merge hotfix into develop
118124
if (!cancelDevelopMerge) {
119-
return utils.Repo.merge(developBranch, hotfixBranch, repo, processMergeMessageCallback);
125+
return utils.Repo.merge(developBranch, hotfixBranch, repo, processMergeMessageCallback)
126+
.then(utils.InjectIntermediateCallback(postDevelopMergeCallback));
120127
}
121128
return Promise.resolve();
122129
})
@@ -127,6 +134,7 @@ class Hotfix {
127134
// Merge the hotfix branch into master
128135
if (!cancelMasterMerge) {
129136
return utils.Repo.merge(masterBranch, hotfixBranch, repo, processMergeMessageCallback)
137+
.then(utils.InjectIntermediateCallback(postMasterMergeCallback))
130138
.then((oid) => utils.Tag.create(oid, tagName, message, repo));
131139
}
132140

src/Release.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ class Release {
7070
* @return {Commit} The commit created by finishing the release
7171
*/
7272
static finishRelease(repo, releaseVersion, options = {}) {
73-
const {keepBranch, message, processMergeMessageCallback} = options;
73+
const {
74+
keepBranch,
75+
message,
76+
processMergeMessageCallback,
77+
postDevelopMergeCallback = () => {},
78+
postMasterMergeCallback = () => {}
79+
} = options;
7480

7581
if (!repo) {
7682
return Promise.reject(new Error('Repo is required'));
@@ -123,7 +129,8 @@ class Release {
123129

124130
// Merge release into develop
125131
if (!cancelDevelopMerge) {
126-
return utils.Repo.merge(developBranch, releaseBranch, repo, processMergeMessageCallback);
132+
return utils.Repo.merge(developBranch, releaseBranch, repo, processMergeMessageCallback)
133+
.then(utils.InjectIntermediateCallback(postDevelopMergeCallback));
127134
}
128135
return Promise.resolve();
129136
})
@@ -134,6 +141,7 @@ class Release {
134141
// Merge the release branch into master
135142
if (!cancelMasterMerge) {
136143
return utils.Repo.merge(masterBranch, releaseBranch, repo, processMergeMessageCallback)
144+
.then(utils.InjectIntermediateCallback(postMasterMergeCallback))
137145
.then((oid) => utils.Tag.create(oid, tagName, message, repo));
138146
}
139147

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module.exports =
2+
(callback) => (a) => Promise.resolve(callback()).then(() => a);

0 commit comments

Comments
 (0)