-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: suggest previously used scopes
The output of the 'git log' command is parsed to extract the various change scopes. Closes #7
- Loading branch information
1 parent
c6e5fcf
commit 4c4f3e2
Showing
4 changed files
with
79 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.leroymerlin.commit; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.InputStreamReader; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.Collectors; | ||
|
||
class Command { | ||
private final File workingDirectory; | ||
private final String command; | ||
|
||
Command(File workingDirectory, String command) { | ||
this.workingDirectory = workingDirectory; | ||
this.command = command; | ||
} | ||
|
||
static class Result { | ||
static Result ERROR = new Result(-1); | ||
|
||
private final int exitValue; | ||
private final List<String> output; | ||
|
||
Result(int exitValue) { | ||
this.exitValue = exitValue; | ||
this.output = null; | ||
} | ||
|
||
Result(int exitValue, List<String> output) { | ||
this.exitValue = exitValue; | ||
this.output = output; | ||
} | ||
|
||
boolean isSuccess() { | ||
return exitValue == 0; | ||
} | ||
|
||
List<String> getOutput() { | ||
return output; | ||
} | ||
} | ||
|
||
Result execute() { | ||
try { | ||
Process process = new ProcessBuilder("/bin/sh", "-c", this.command) | ||
.directory(workingDirectory) | ||
.start(); | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); | ||
|
||
List<String> output = reader.lines().collect(Collectors.toList()); | ||
|
||
process.waitFor(2, TimeUnit.SECONDS); | ||
process.destroy(); | ||
process.waitFor(); | ||
|
||
return new Result(process.exitValue(), output); | ||
} catch (Exception e) { | ||
return Result.ERROR; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters