Created
December 27, 2018 18:25
-
-
Save nikialeksey/1990cd30e4781f01a07d89c1ee8e0c1f to your computer and use it in GitHub Desktop.
Fail if the commit does not have CHANGELOG tag
This file contains hidden or 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
dependencies { | |
testImplementation 'org.eclipse.jgit:org.eclipse.jgit:5.2.0.201812061821-r' | |
} |
This file contains hidden or 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
import org.eclipse.jgit.storage.file.FileRepositoryBuilder | |
import org.hamcrest.core.IsEqual | |
import org.junit.Assert | |
import org.junit.Test | |
import java.io.File | |
import java.util.* | |
class CommitVerifier { | |
@Test | |
fun changelogPresents() { | |
val repository = FileRepositoryBuilder().setGitDir(File("../.git")) | |
.setMustExist(true) | |
.build() | |
val currentCommit = repository.parseCommit(repository.resolve("HEAD")) | |
if (currentCommit.parentCount == 1) { // not merge commit | |
val currentMessage = currentCommit.fullMessage | |
var wasChangeLogInfo = false | |
Scanner(currentMessage).use { scanner -> | |
while (scanner.hasNextLine()) { | |
val line = scanner.nextLine() | |
if (line.trimStart().startsWith("CHANGELOG:")) { | |
wasChangeLogInfo = true | |
} | |
} | |
} | |
Assert.assertThat( | |
"Your last commit does not have the CHANGELOG tag. Please, add it", | |
wasChangeLogInfo, | |
IsEqual.equalTo(true) | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment