Skip to content

Commit

Permalink
fix: fix path issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 6, 2023
1 parent 032eac6 commit 9e5a6fe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
4 changes: 3 additions & 1 deletion unit-picker/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
unit-eval-testing
unit-eval-testing
github.com
gitlab.com
34 changes: 27 additions & 7 deletions unit-picker/src/main/kotlin/cc/unitmesh/eval/picker/CodePicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,58 @@ package cc.unitmesh.eval.picker
import org.archguard.action.checkout.GitSourceSettings
import org.archguard.action.checkout.executeGitCheckout
import org.jetbrains.annotations.TestOnly
import java.nio.file.Files
import java.nio.file.Path

class CodePicker(val config: PickerConfig) {
private val logger = org.slf4j.LoggerFactory.getLogger(javaClass)

fun run() {
// 1. check config.url is a valid url or path
checkoutCode(config.url, config.branch, config.baseDir)
val codeDir = checkoutCode(config.url, config.branch, config.baseDir)

// 2. select files to tree

// 3. generate tree to jsonl
}

@TestOnly
fun checkoutCode(url: String, branch: String, baseDir: String) {
fun checkoutCode(url: String, branch: String, baseDir: String): Path {
if (!gitUrlRegex.matches(url)) {
return
return Path.of(url)
}

val gitDir = gitUrlToPath(url)
val targetDir = Path.of(baseDir, gitDir)
logger.info("targetDir: $targetDir")
if (targetDir.toFile().exists()) {
return
logger.info("targetDir exists: $targetDir")
return targetDir
}

val settings = GitSourceSettings.fromArgs(arrayOf("--repository", url, "--branch", branch))
executeGitCheckout(settings)

// mv settings.repository to targetDir
targetDir.toFile().mkdirs()
val repositoryPath = Path.of(settings.repository)
repositoryPath.toFile().renameTo(targetDir.toFile())
val sourceRepoDir = Path.of(settings.repositoryPath)
try {
Files.createDirectories(targetDir.parent)
} catch (e: Exception) {
logger.info("create dir failed: ${targetDir.parent}")
}

logger.info("targetDir: $targetDir")
moveRepository(sourceRepoDir, targetDir)
return targetDir
}

private fun moveRepository(sourceDir: Path, targetDir: Path) {
try {
Files.move(sourceDir, targetDir)
} catch (e: Exception) {
// Handle the exception appropriately (e.g., log or throw)
e.printStackTrace()
}
}

companion object {
Expand Down

0 comments on commit 9e5a6fe

Please sign in to comment.