Dutchskull / Aspire.PolyRepo

This library for DotNet Aspire enables poly repo support and the addition of Git repositories to your Aspire projects. It simplifies multi-repository management and streamlines dependency handling, making it easier to work with multiple repositories in a Aspire project.
18 stars 3 forks source link

Could not load file or assembly 'LibGit2Sharp' and "remote authentication required but no callback set" #22

Open tobey74 opened 3 weeks ago

tobey74 commented 3 weeks ago

Hi, I am trying to follow your examples from your readme to add projects from git repos to my Aspire AppHost. I have tried adding both repos from the organization I am part of and from my own GitHub account but both fails.

First I got this error:

System.IO.FileNotFoundException
  HResult=0x80070002
  Message=Could not load file or assembly 'LibGit2Sharp, 
  Version=0.30.0.0, Culture=neutral, 
  PublicKeyToken=7cbde695407f0333'. 
The system cannot find the file specified.

So I added the package manually to my AppHost project:

Install-Package LibGit2Sharp -Version 0.30.0

But then builder.AddRepository throws exception remote authentication required but no callback set

LibGit2Sharp.LibGit2SharpException
  HResult=0x80131500
  Message=remote authentication required but no callback set
  Source=LibGit2Sharp
  StackTrace:
   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
   at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result)
   at LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir, GitCloneOptions& opts)
   at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options)
   at Dutchskull.Aspire.PolyRepo.ProcessCommandExecutor.CloneGitRepository(String gitUrl, String resolvedRepositoryPath, String branch)
   at Dutchskull.Aspire.PolyRepo.RepositoryConfigExtensions.CloneRepository(RepositoryConfig repositoryConfig)
   at Dutchskull.Aspire.PolyRepo.RepositoryConfigExtensions.SetupRepository(RepositoryConfig gitRepositoryConfig)
   at Dutchskull.Aspire.PolyRepo.RepositoryConfigExtensions.InitializeRepository(Action`1 configureGitRepository, String repositoryUrl)
   at Dutchskull.Aspire.PolyRepo.ProjectResourceBuilderExtensions.AddRepository(IDistributedApplicationBuilder builder, String name, String repositoryUrl, Action`1 configureGitRepositoryBuilderAction)
   at Program.<Main>$(String[] args) in C:\Dev\Repos\Pida\src\Pida.AppHost\Program.cs:line 41

I get this error no matter if I try adding repo from my private GitHub or the organization I am part of but here example with my own GitHub account and repo:

var myRepo = builder.AddRepository(
    "my-movies-api",
    "https://github.com/PrivateGitHubAccount/my-movies.git",
    c => c.WithDefaultBranch("main").WithTargetPath("c:/dev/git"));

Or with organization

var myOrgRepo = builder.AddRepository(
    "api",
    "https://github.com/OurOrganization/some-project.git",
    c => c.WithDefaultBranch("main").WithTargetPath("c:/dev/git"));

I cannot see a way how to authenticate with GitHub or provide som Credentials?

I do have my GitHub credentials stored as environment variables like GHP_TOKEN and GHP_USER.

WhiteOlivierus commented 3 weeks ago

Thank you for posting an issue, I will be investigating this.

WhiteOlivierus commented 2 weeks ago

@tobey74 I have made a fix for this, I haven't had the time to test this. This will probably come some time next week. Or if you might have some time please check if this works.

tobey74 commented 2 weeks ago

@WhiteOlivierus Hi Olivier, I have tried connecting to GitHub with your updated code but without luck I'm sorry :) Your latest NuGet push failed so I tried cloning your code locally but even then I cannot find a way to assign the GitConfigBuilder with my Username and Password set to a RepositoryConfigBuilder because the GitConfig is not exposed but is private. Also, you create always a new GitConfig object on line 27 when the RepositoryConfigBuilder is build. So for the moment I don't see a way to provide the GitHub credentials - I have tried making the WithGitConfig public on line 64 but still no luck with cloning my repo.

WhiteOlivierus commented 2 weeks ago

Thanks for checking in! I’m still working on this, but since I’m handling it in my spare time, it may take a little longer. For the next three weeks, I’ll be able to respond but won’t have time to actively work on it.

That said, I’ve made some good progress. I’ve added authentication to the sample to ensure it can be accessed, and it’s now passing through the entire pipeline. So it might actually work! I still need to add a test case for this, but I haven’t had the time yet—coming soon!

tobey74 commented 2 weeks ago

Absolutely no rush from my side Olivier, I'm just looking forward to follow your project extending Aspire :)