Skip to content

Instantly share code, notes, and snippets.

@nikialeksey
Created December 27, 2018 18:25
Show Gist options
  • Save nikialeksey/1990cd30e4781f01a07d89c1ee8e0c1f to your computer and use it in GitHub Desktop.
Save nikialeksey/1990cd30e4781f01a07d89c1ee8e0c1f to your computer and use it in GitHub Desktop.
Fail if the commit does not have CHANGELOG tag
dependencies {
testImplementation 'org.eclipse.jgit:org.eclipse.jgit:5.2.0.201812061821-r'
}
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