Skip to content

Commit 09a372a

Browse files
committed
[FEATURE] ✨ Add option to halt before commit
Add the option `--halt-before-commit` to pause Patchbot before a commit. This way users may review changes manually instead of letting the CI do the job, which may be usefull for sensitive changes. Patchbot will ask to continue and abort of the user denies it. Refs #10
1 parent 6f962a2 commit 09a372a

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ the feature branch instead of a random name:
124124
./vendor/bin/patchbot patch --branch-name=feature-1337-add-license-file --patch-name=template --repository-url=https://git.example.com/repository
125125
```
126126

127+
It is recommend to let a CI run all tests, that's why Patchbot creates a feature
128+
branch by default. If you want to review changes manually before the commit,
129+
then use the `halt-before-commit` option:
130+
131+
```bash
132+
./vendor/bin/patchbot patch --halt-before-commit --patch-name=template --repository-url=https://git.example.com/repository
133+
```
134+
127135
### Merge feature branch
128136

129137
When you reviewed the feature branch and all tests are successful then

src/RoboFile.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class RoboFile extends \Robo\Tasks
2222
* @option $patch-name Name of the directory where the patch code resides
2323
* @option $source-branch Name of the branch to create a new branch upon
2424
* @option $branch-name Name of the feature branch to be created
25+
* @option $halt-before-commit Pause before changes are commited, asks to continue
2526
* @throws \Robo\Exception\TaskException
2627
*/
2728
public function patch(array $options = [
@@ -31,6 +32,7 @@ public function patch(array $options = [
3132
'patch-name|p' => 'template',
3233
'source-branch' => 'master', // rename to main in next mayor release
3334
'branch-name' => null,
35+
'halt-before-commit' => false,
3436
])
3537
{
3638
if (empty($options['repository-url'])) {
@@ -78,12 +80,27 @@ public function patch(array $options = [
7880
}
7981
chdir($currentDirectory);
8082

81-
// Commit changes
83+
// Check for changes
8284
$this->say('Commit changes');
83-
if (empty(exec('git status -s'))) {
85+
$fileChanges = exec('git status -s');
86+
if (empty($fileChanges)) {
8487
$this->say('Nothing to commit, no changes in repository');
8588
return;
8689
}
90+
91+
// Halt for manual review before commit
92+
if ($options['halt-before-commit']) {
93+
$this->say('Halt for manual review');
94+
$this->say('Working directory: ' . PHP_EOL . $currentDirectory);
95+
$this->say('File changes: ' . PHP_EOL . $fileChanges);
96+
$question = $this->io()->confirm('Continue?', true);
97+
if ($question === false) {
98+
return;
99+
}
100+
}
101+
102+
// Commit changes
103+
$this->say('Commit changes');
87104
$commitMessage = file_get_contents($patchSourceDirectory . $options['patch-name'] . '/commit-message.txt');
88105
$this->taskGitStack()
89106
->add('-A')

0 commit comments

Comments
 (0)