Skip to content

Commit

Permalink
Rebase & improvement
Browse files Browse the repository at this point in the history
Signed-off-by: the-johnwick <[email protected]>
  • Loading branch information
the-johnwick committed Oct 2, 2024
1 parent 7ef5c33 commit b5c0318
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion pkg/server/gitproviders/gitprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ import (
"github.com/google/uuid"
)

type GitProviderWithId struct {
GitProvider gitprovider.GitProvider
Id string
}

func (s *GitProviderService) GetGitProviderForUrl(repoUrl string) (gitprovider.GitProvider, string, error) {
gitProviders, err := s.configStore.List()
if err != nil {
return nil, "", err
}

var selectedProvider []GitProviderWithId

for _, p := range gitProviders {
gitProvider, err := s.GetGitProvider(p.Id)
if err != nil {
Expand All @@ -28,10 +35,26 @@ func (s *GitProviderService) GetGitProviderForUrl(repoUrl string) (gitprovider.G

canHandle, _ := gitProvider.CanHandle(repoUrl)
if canHandle {
return gitProvider, p.Id, nil
_, err = gitProvider.GetRepositoryContext(gitprovider.GetRepositoryContext{
Url: repoUrl,
})
if err == nil {
userName := strings.ToLower(p.Username)
repo := strings.ToLower(repoUrl)
if strings.Contains(repo, userName) {
return gitProvider, p.Id, nil
} else {
selectedProvider = append(selectedProvider, GitProviderWithId{
GitProvider: gitProvider,
Id: p.Id,
})
}
}
}
}

return selectedProvider[0].GitProvider, selectedProvider[0].Id, nil

u, err := url.Parse(repoUrl)

Check failure on line 58 in pkg/server/gitproviders/gitprovider.go

View workflow job for this annotation

GitHub Actions / lint

unreachable: unreachable code (govet)
if err != nil {
return nil, "", nil
Expand Down Expand Up @@ -69,6 +92,7 @@ func (s *GitProviderService) GetConfigForUrl(repoUrl string) (*gitprovider.GitPr
if canHandle {
return p, nil
}

}

supportedGitProviders := config.GetSupportedGitProviders()
Expand Down

0 comments on commit b5c0318

Please sign in to comment.