Skip to content

Commit

Permalink
Add pre-push hook with ktlint check
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonScholz committed Nov 25, 2023
1 parent 51ebf91 commit 74eaa78
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
10 changes: 10 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ plugins {
id("org.jlleitschuh.gradle.ktlint") version "11.6.1" apply false
id("com.github.ben-manes.versions") version "0.50.0" apply false
}

tasks.register("installKtlintGitPrePushHook", Copy::class) {
from("${rootProject.rootDir}/git-hook/pre-push")
into("${rootProject.rootDir}/.git/hooks")
doLast {
exec {
commandLine("chmod", "+x", "${rootProject.rootDir}/.git/hooks/pre-push")
}
}
}
22 changes: 22 additions & 0 deletions git-hook/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
#husky 0.13.4

# This script runs ktlint check before pushing to the remote repository

echo "Running ktlint check ..."
./gradlew ktlintCheck 2> /dev/null
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
echo " "
echo "*********************************************************************"
echo "* "
echo "* ktlint failed "
echo "* "
echo "* Please fix the issues above before pushing. "
echo "* Usually running'ktlintFormat' fixes issues automatically. "
echo "* ./gradlew ktlintFormat "
echo "* "
echo "*********************************************************************"
echo " "
exit $EXIT_CODE
fi
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@ import io.github.simonscholz.qrcode.QrCodeConfig
import io.github.simonscholz.qrcode.QrCodeFactory
import io.github.simonscholz.qrcode.QrPositionalSquaresConfig
import io.github.simonscholz.ui.ImageUI
import org.jdesktop.swingx.graphics.GraphicsUtilities
import java.awt.Color
import java.awt.Image
import java.awt.datatransfer.DataFlavor
import java.awt.datatransfer.Transferable
import java.awt.datatransfer.UnsupportedFlavorException
import java.awt.image.BufferedImage
import java.io.File
import java.io.IOException
import java.util.ArrayList
import javax.imageio.ImageIO
import javax.swing.JOptionPane

Expand Down
20 changes: 12 additions & 8 deletions qr-code-app/src/main/kotlin/io/github/simonscholz/ui/FileUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import io.github.simonscholz.service.ImageService
import org.jdesktop.swingx.graphics.GraphicsUtilities
import java.awt.Image
import java.awt.Toolkit
import java.awt.datatransfer.*
import java.awt.datatransfer.Clipboard
import java.awt.datatransfer.DataFlavor
import java.awt.datatransfer.StringSelection
import java.awt.datatransfer.Transferable
import java.io.File
import java.io.IOException
import javax.imageio.ImageIO
import javax.swing.JFileChooser
import javax.swing.JOptionPane
Expand Down Expand Up @@ -127,26 +129,28 @@ class FileUI(
override fun isDataFlavorSupported(flavor: DataFlavor): Boolean {
return if (flavor === DataFlavor.imageFlavor) {
true
} else flavor === DataFlavor.javaFileListFlavor
} else {
flavor === DataFlavor.javaFileListFlavor
}
}

@Throws(UnsupportedFlavorException::class, IOException::class)
override fun getTransferData(flavor: DataFlavor): Any {
//log.fine("doing get trans data: " + flavor);
// log.fine("doing get trans data: " + flavor);
if (flavor === DataFlavor.imageFlavor) {
return img
}
if (flavor === DataFlavor.javaFileListFlavor) {
if (files == null) {
val file = File.createTempFile(exportName, ".$exportFormat")
//log.fine("writing to: " + file);
// log.fine("writing to: " + file);
ImageIO.write(
GraphicsUtilities.convertToBufferedImage(img),
exportFormat, file,
exportFormat,
file,
)
files = listOf(file).toMutableList()
}
//log.fine("returning: " + files);
// log.fine("returning: " + files);
return files as MutableList<File>
}
return emptyList<File>()
Expand Down

0 comments on commit 74eaa78

Please sign in to comment.