Skip to content

Commit

Permalink
fix: create the file for checking commits
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasfara committed Dec 27, 2021
1 parent 62e9500 commit 6c3e298
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/main/kotlin/it/nicolasfarabegoli/gradle/ConventionalCommits.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package it.nicolasfarabegoli.gradle

import org.gradle.api.Plugin
import org.gradle.api.Project
import java.io.File
import java.text.MessageFormat

/**
* Plugin for checking if commits are _Conventional Commits_ compliant.
Expand All @@ -16,7 +18,14 @@ class ConventionalCommits : Plugin<Project> {
}

override fun apply(project: Project) {
project.createExtension<ConventionalCommitsExtension>("conventionalCommits", project)
project.logger.debug("Create the file '.git/commit-msg' with default rules")
val extension = project.createExtension<ConventionalCommitsExtension>("conventionalCommits", project)
val regex = buildRegex(extension.scopes.get())
project.logger.debug("Use the following regex for check commits: $regex")

val scriptPath = File(project.rootDir.path + File.separator + ".git" + File.separator, "hooks")
if (!scriptPath.exists()) scriptPath.mkdirs()
val scriptContent = MessageFormat.format(scriptContent, regex)
project.logger.debug("script content: $scriptContent")
scriptPath.resolve("commit-msg").writeText(scriptContent)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
package it.nicolasfarabegoli.gradle

import org.gradle.api.Project
import org.gradle.api.provider.ListProperty
import org.gradle.kotlin.dsl.listProperty

open class ConventionalCommitsExtension(private val project: Project)
open class ConventionalCommitsExtension(project: Project) {

/**
* List of scopes admitted in the project.
* If an empty list is given, all scopes are admitted.
* By default, any scope is admitted.
*/
val scopes: ListProperty<String> = project.objects.listProperty()
}

0 comments on commit 6c3e298

Please sign in to comment.