-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from ajoberstar/fixes
minor: Allow commit messages to bump to 1.0.0
- Loading branch information
Showing
16 changed files
with
166 additions
and
51 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
Binary file not shown.
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
71 changes: 71 additions & 0 deletions
71
reckon-core/src/main/java/org/ajoberstar/reckon/core/CommitMessageScopeParser.java
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,71 @@ | ||
package org.ajoberstar.reckon.core; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Function; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* A functional interface for parsing Git commit messages for Reckon scopes. The implementation can | ||
* decide what convention within the message denotes each scope value. | ||
*/ | ||
@FunctionalInterface | ||
public interface CommitMessageScopeParser { | ||
Optional<Scope> parse(String messageBody, boolean preV1); | ||
|
||
/** | ||
* Returns a parser that checks the message subject for a prefixed like so: | ||
* {@code <scope>(<area>): subject}. If the project is currently pre-v1, a prefix of {@code major: } | ||
* will be downgraded to {@code minor}, unless you use {@code major!: } with an exclamation point. | ||
* | ||
* @return parser that reads scopes from subject prefixes | ||
*/ | ||
static CommitMessageScopeParser subjectPrefix() { | ||
var pattern = Pattern.compile("^(major!|major|minor|patch)(?:\\(.*?\\))?: .+"); | ||
return (msg, preV1) -> { | ||
var matcher = pattern.matcher(msg); | ||
|
||
if (!matcher.find()) { | ||
return Optional.empty(); | ||
} | ||
|
||
Scope scope; | ||
switch (matcher.group(1)) { | ||
// the ! forces use of major, ignoring preV1 checks | ||
case "major!": | ||
scope = Scope.MAJOR; | ||
break; | ||
// otherwise we don't allow pre-v1 to bump to major | ||
case "major": | ||
scope = preV1 ? Scope.MINOR : Scope.MAJOR; | ||
break; | ||
case "minor": | ||
scope = Scope.MINOR; | ||
break; | ||
case "patch": | ||
scope = Scope.PATCH; | ||
break; | ||
default: | ||
throw new AssertionError("Unhandled scope value matched by regex: " + matcher.group("scope")); | ||
}; | ||
return Optional.of(scope); | ||
}; | ||
} | ||
|
||
/** | ||
* Adapter for legacy message parsers always prevent bumping to v1. | ||
* | ||
* @param parser legacy parser function | ||
* @return parser that prevents v1 bumps | ||
*/ | ||
static CommitMessageScopeParser ofLegacy(Function<String, Optional<Scope>> parser) { | ||
return (messageBody, preV1) -> { | ||
return parser.apply(messageBody).map(scope -> { | ||
if (preV1 && scope == Scope.MAJOR) { | ||
return Scope.MINOR; | ||
} else { | ||
return scope; | ||
} | ||
}); | ||
}; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,6 +172,13 @@ public void initRepository() throws IOException, GitAPIException { | |
.setDirectory(repoDir.toFile()) | ||
.call(); | ||
|
||
var config = git.getRepository().getConfig(); | ||
config.setString("user", null, "name", "Some Person"); | ||
config.setString("user", null, "email", "[email protected]"); | ||
config.setString("commit", null, "gpgSign", "false"); | ||
config.setString("tag", null, "gpgSign", "false"); | ||
config.save(); | ||
|
||
var initialBranch = git.getRepository().getBranch(); | ||
|
||
commit(); | ||
|
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 |
---|---|---|
|
@@ -56,6 +56,13 @@ public void setupRepo() throws IOException, GitAPIException { | |
repoDir = Files.createTempDirectory("repo"); | ||
git = Git.init().setDirectory(repoDir.toFile()).call(); | ||
initialBranch = git.getRepository().getBranch(); | ||
|
||
var config = git.getRepository().getConfig(); | ||
config.setString("user", null, "name", "Some Person"); | ||
config.setString("user", null, "email", "[email protected]"); | ||
config.setString("commit", null, "gpgSign", "false"); | ||
config.setString("tag", null, "gpgSign", "false"); | ||
config.save(); | ||
} | ||
|
||
@AfterEach | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.net.URISyntaxException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
@@ -14,9 +15,24 @@ | |
public final class Gits { | ||
private static final SecureRandom random = new SecureRandom(); | ||
|
||
public static void resetConfig(Git git) { | ||
try { | ||
var config = git.getRepository().getConfig(); | ||
config.setString("user", null, "name", "Some Person"); | ||
config.setString("user", null, "email", "[email protected]"); | ||
config.setString("commit", null, "gpgSign", "false"); | ||
config.setString("tag", null, "gpgSign", "false"); | ||
config.save(); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
|
||
public static Git clone(File dir, Git origin) throws GitAPIException { | ||
var uri = origin.getRepository().getDirectory().getAbsolutePath(); | ||
return Git.cloneRepository().setDirectory(dir).setURI(uri).setCloneAllBranches(true).setNoCheckout(false).call(); | ||
var git = Git.cloneRepository().setDirectory(dir).setURI(uri).setCloneAllBranches(true).setNoCheckout(false).call(); | ||
resetConfig(git); | ||
return git; | ||
} | ||
|
||
public static Path repoFile(Git git, String path) throws IOException { | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# DO NOT MODIFY: Generated by Stutter plugin. | ||
java11=7.0.2,7.6.4,8.0.2,8.9,8.10-rc-1 | ||
java17=7.3.3,7.6.4,8.0.2,8.9,8.10-rc-1 | ||
java21=8.4,8.9,8.10-rc-1 | ||
java11=7.0.2,7.6.4,8.0.2,8.11.1 | ||
java17=7.3.3,7.6.4,8.0.2,8.11.1 | ||
java21=8.4,8.11.1 |