Skip to content

Commit dde0c55

Browse files
committed
feat(git): add GitHub repository parsing from project #408
Add parseGitHubRepository function to extract GitHub repository information from IntelliJ project using VcsRepositoryManager for improved repository detection.
1 parent c35528e commit dde0c55

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

core/src/main/kotlin/cc/unitmesh/devti/flow/kanban/impl/GitHubIssue.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cc.unitmesh.devti.flow.kanban.impl
33
import cc.unitmesh.devti.flow.kanban.Kanban
44
import cc.unitmesh.devti.flow.model.SimpleStory
55
import cc.unitmesh.devti.settings.devops.devopsPromptsSettings
6+
import com.intellij.dvcs.repo.VcsRepositoryManager
67
import com.intellij.openapi.project.Project
78
import git4idea.repo.GitRepository
89
import org.kohsuke.github.GitHub
@@ -50,15 +51,15 @@ class GitHubIssue(var repoUrl: String, val token: String) : Kanban {
5051

5152
return SimpleStory(issue.number.toString(), issue.title, issue.body ?: "")
5253
}
53-
54+
5455
/**
5556
* Get recent issue IDs (within last 24 hours)
5657
*/
5758
fun getRecentIssueIds(): List<String> {
5859
return try {
5960
val repository = gitHub.getRepository(repoUrl)
6061
val yesterday = Instant.now().minusSeconds(24 * 60 * 60)
61-
62+
6263
repository.getIssues(GHIssueState.ALL)
6364
.filter { it.createdAt.toInstant().isAfter(yesterday) }
6465
.map { it.number.toString() }
@@ -100,5 +101,21 @@ class GitHubIssue(var repoUrl: String, val token: String) : Kanban {
100101
repository.remotes.firstOrNull { remote ->
101102
remote.urls.any { it.contains("github.com") }
102103
}?.urls?.firstOrNull { it.contains("github.com") }
104+
105+
fun parseGitHubRepository(project: Project): GHRepository? {
106+
val repositoryManager: VcsRepositoryManager = VcsRepositoryManager.getInstance(project)
107+
val repository = repositoryManager.getRepositoryForFile(project.baseDir)
108+
109+
if (repository == null) {
110+
return null
111+
}
112+
113+
if (repository !is GitRepository) {
114+
return null
115+
}
116+
117+
val remoteUrl = parseGitHubRemoteUrl(repository) ?: return null
118+
return getGitHubRepository(project, remoteUrl)
119+
}
103120
}
104121
}

0 commit comments

Comments
 (0)