Created
December 19, 2023 14:41
-
-
Save MahmoudMabrok/609018eb414e44fc982836ff578f1915 to your computer and use it in GitHub Desktop.
Prepare files for code review
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tasks.register("addSpaceToEndOfLines") { | |
description = "Add space to the end of each line in .kt files and commit changes to Git" | |
doLast { | |
println("Starting magic") | |
project.exec { | |
commandLine("git", "checkout", "-b" , "refactor/submitCode") | |
} | |
println("Checked out new branch") | |
// Set the directory containing Kotlin files | |
val kotlinDir = file("src/main/") | |
// Get all .kt files in the directory | |
val kotlinFiles = fileTree(kotlinDir).matching { include("**/*.kt") } | |
// Iterate over each Kotlin file | |
println("processing to files ${kotlinFiles.files.size}") | |
for (file in kotlinFiles) { | |
// Read the content of the Kotlin file | |
val originalContent = file.readText() | |
// Add a space to the end of each line | |
val modifiedContent = originalContent.replace(Regex("$", RegexOption.MULTILINE), " ") | |
// Write the modified content back to the same file | |
file.writeText(modifiedContent) | |
} | |
println("Adding files") | |
project.exec { | |
commandLine("git", "add", ".") | |
} | |
println("Committing") | |
project.exec { | |
commandLine("git", "commit", "-m", "refactor: prepare files for code review") | |
} | |
println("Push to remote") | |
project.exec { | |
commandLine("git", "push" , "fork") | |
} | |
println("Gradle task 'addSpaceToEndOfLines' completed successfully ") | |
} | |
} |
How to use
- add script to gradle.kts
- use above steps
- replace
fork
with remote name, normally be 'origin'
Modifications
- you can choose which folder you need by modifying
val kotlinDir = file("src/main/")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
open gradle tab on top right,
then choose excuse gradle task,
it will show you task search for the new one.