Skip to content

Instantly share code, notes, and snippets.

@tarek360
Last active February 13, 2019 07:08
Show Gist options
  • Save tarek360/8c0c51c8525724b364405276c859dfee to your computer and use it in GitHub Desktop.
Save tarek360/8c0c51c8525724b364405276c859dfee to your computer and use it in GitHub Desktop.
Custom Koshry rule to avoid adding new JPG files to your git repo and ask the pull request author to use WebP instead.
import io.github.tarek360.rules.core.Issue
import io.github.tarek360.rules.core.Level
import io.github.tarek360.rules.core.Report
import io.github.tarek360.rules.core.Rule
class NoJpgRule : Rule() {
override fun run(): Report? {
val report = Report(msgTitle = "No more JPG files, Use WebP.")
gitDiff.getAddedFiles().forEach { file ->
if (file.path.endsWith(".jpg")) {
report.issues.add(Issue(msg = "File: ${file.path}", level = Level.ERROR()))
}
}
return report.takeIf {
report.issues.isNotEmpty()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment