opencode-repos 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/scanner.ts ADDED
@@ -0,0 +1,126 @@
1
+ import { $ } from "bun"
2
+ import { dirname } from "node:path"
3
+
4
+ export interface LocalRepoInfo {
5
+ path: string
6
+ remote: string
7
+ branch: string
8
+ }
9
+
10
+ export async function scanLocalRepos(searchPaths: string[]): Promise<LocalRepoInfo[]> {
11
+ const allGitDirs: string[] = []
12
+
13
+ const fdResults = await Promise.all(
14
+ searchPaths.map(async (searchPath) => {
15
+ try {
16
+ const result = await $`fd -H -t d '^.git$' --max-depth 4 ${searchPath}`.text()
17
+ return result.split("\n").filter(Boolean)
18
+ } catch {
19
+ return []
20
+ }
21
+ })
22
+ )
23
+
24
+ for (const gitDirs of fdResults) {
25
+ allGitDirs.push(...gitDirs)
26
+ }
27
+
28
+ const results = await Promise.all(
29
+ allGitDirs.map(async (gitDir) => {
30
+ const repoPath = dirname(gitDir)
31
+ try {
32
+ const [remote, branch] = await Promise.all([
33
+ $`git -C ${repoPath} remote get-url origin`.text(),
34
+ $`git -C ${repoPath} branch --show-current`.text(),
35
+ ])
36
+
37
+ if (!remote.trim()) return null
38
+
39
+ return {
40
+ path: repoPath,
41
+ remote: remote.trim(),
42
+ branch: branch.trim() || "main",
43
+ }
44
+ } catch {
45
+ return null
46
+ }
47
+ })
48
+ )
49
+
50
+ return results.filter((r): r is LocalRepoInfo => r !== null)
51
+ }
52
+
53
+ export function matchRemoteToSpec(remote: string): string | null {
54
+ let normalized = remote.replace(/\.git$/, "")
55
+
56
+ const sshMatch = normalized.match(/git@github\.com:(.+)/)
57
+ if (sshMatch) {
58
+ return sshMatch[1]
59
+ }
60
+
61
+ const httpsMatch = normalized.match(/https:\/\/github\.com\/(.+)/)
62
+ if (httpsMatch) {
63
+ return httpsMatch[1]
64
+ }
65
+
66
+ return null
67
+ }
68
+
69
+ export interface LocalFindResult {
70
+ path: string
71
+ remote: string
72
+ branch: string
73
+ spec: string
74
+ }
75
+
76
+ export async function findLocalRepoByName(
77
+ searchPaths: string[],
78
+ query: string
79
+ ): Promise<LocalFindResult[]> {
80
+ const results: LocalFindResult[] = []
81
+ const queryLower = query.toLowerCase()
82
+ const queryParts = queryLower.split("/")
83
+ const repoName = queryParts.length > 1 ? queryParts[1] : queryParts[0]
84
+
85
+ for (const searchPath of searchPaths) {
86
+ try {
87
+ const fdResult = await $`fd -H -t d '^.git$' --max-depth 4 ${searchPath}`.text()
88
+ const gitDirs = fdResult.split("\n").filter(Boolean)
89
+
90
+ for (const gitDir of gitDirs) {
91
+ const repoPath = dirname(gitDir)
92
+ const dirName = repoPath.split("/").pop()?.toLowerCase() || ""
93
+
94
+ if (!dirName.includes(repoName)) continue
95
+
96
+ try {
97
+ const remote = await $`git -C ${repoPath} remote get-url origin`.text()
98
+ if (!remote.trim()) continue
99
+
100
+ const spec = matchRemoteToSpec(remote.trim())
101
+ if (!spec) continue
102
+
103
+ if (queryParts.length > 1) {
104
+ const specLower = spec.toLowerCase()
105
+ if (!specLower.includes(queryLower)) continue
106
+ }
107
+
108
+ const branch = await $`git -C ${repoPath} branch --show-current`.text()
109
+
110
+ results.push({
111
+ path: repoPath,
112
+ remote: remote.trim(),
113
+ branch: branch.trim() || "main",
114
+ spec,
115
+ })
116
+ } catch {
117
+ continue
118
+ }
119
+ }
120
+ } catch {
121
+ continue
122
+ }
123
+ }
124
+
125
+ return results
126
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "esModuleInterop": true,
7
+ "strict": true,
8
+ "skipLibCheck": true,
9
+ "declaration": true,
10
+ "outDir": "./dist",
11
+ "rootDir": "./",
12
+ "types": ["bun-types"]
13
+ },
14
+ "include": ["*.ts", "src/**/*.ts"],
15
+ "exclude": ["node_modules", "dist"]
16
+ }