Skip to content
Ahmed Tarek edited this page Feb 22, 2019 · 8 revisions

How to write Koshry Rules?

Two options:

1. Write a custom rule

2. Use the ready rules from Koshry

Koshry has ready rules to apply on the git diff of your pull request:

Line Rule

  • Use it when you want to apply a condition to all of the added and modified lines in the pull request.
  • if the condition is met, Koshry will add a new issue to the report.
  • The added issue contains the file path, line number, level of issue and the report title.
val rule = lineRule {
    reportTitle = "Don't use android.util.Log, use our custom Logger"
    issueLevel = WARN()
    condition = { file , line -> line.text.contains("android.util.Log") }
}
  • The generated issue will be like this screenshot:
Koshry Line Rule

2. File Rule

  • Use it when you want to apply a condition to all of the added and modified files in the pull request.
  • if the condition is met, Koshry will add a new issue to the report.
  • The added issue contains the file path, level of issue and the report title.
val rule = fileRule {
    reportTitle = "Don't add new Java files, use Kotlin instead."
    issueLevel = ERROR()
    condition = { file ->
        file.isAdded && file.name.endsWith(".java")
    }
}

3. Protected File Rule

  • Protect a list of files to be changed by any pull request author.
  • Exclude some an author or more from this rule if you want.
val rule = protectedFileRule {
    reportTitle = "Files are protected and can't be modified, ask @tarek360 to modify"
    issueLevel = ERROR()
    files {
        filePath = "dependencies.kts"
        filePath = ".circleci/config.yml"
    }
    excludeAuthors {
        author = "tarek360"
    }
}