Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
liangfung committed Dec 18, 2024
1 parent 2c666a8 commit f61f185
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions ee/tabby-ui/lib/utils/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@ export function findClosestGitRepository(
return undefined
}

const repos = repositories.filter(repo => {
const filteredRepos = repositories.filter(repo => {
const search = gitUrlParse(repo.url)
const isSameResource =
search.resource === targetSearch.resource || search.protocol === 'file'
return isSameResource && search.name === targetSearch.name
})

// If there're multiple matches, we pick the one with highest alphabetical order
return repos.sort((a, b) => {
const canonicalUrlA = canonicalizeUrl(a.url)
const canonicalUrlB = canonicalizeUrl(b.url)
return canonicalUrlB.localeCompare(canonicalUrlA)
})[0]
if (filteredRepos.length === 0) {
return undefined
} else {
// If there're multiple matches, we pick the one with highest alphabetical order
return filteredRepos.reduce((min, current) => {
const minUrl = canonicalizeUrl(min.url)
const currentUrl = canonicalizeUrl(current.url)
return minUrl > currentUrl ? min : current
})
}
}

export function canonicalizeUrl(url: string): string {
Expand Down

0 comments on commit f61f185

Please sign in to comment.