private CloneOptions CloneSshAgent() { CloneOptions options = new CloneOptions(); SshAgentCredentials credentials = new SshAgentCredentials { Username = "******" }; var handler = new LibGit2Sharp.Handlers.CredentialsHandler((url, usernameFromUrl, types) => credentials); options.CredentialsProvider = handler; return(options); }
public async Task <string> Request() { // Credentials LibGit2Sharp.Handlers.CredentialsHandler credsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials { Username = opts.GitTokenUser, Password = opts.GitToken, }; // Clone var cloneOpts = new CloneOptions { CredentialsProvider = credsProvider, BranchName = opts.ManifestBaseBranch, RecurseSubmodules = true }; var repoDir = Path.Combine(opts.WorkDir, opts.ManifestRepoName); Repository.Clone(opts.ManifestUri.ToString(), repoDir, cloneOpts); using (var repo = new Repository(repoDir)) { // Branch for PR var branch = repo.CreateBranch(opts.ManifestDeployBranch); branch = Commands.Checkout(repo, opts.ManifestDeployBranch); // Update manifest referenceUpdater.Update(); // Add Commands.Stage(repo, "*"); // Commit opts.GitCommitMsg = TemplateUtil.Apply(opts, opts.GitCommitMsgTemplate); var author = new Signature(opts.GitUser, opts.GitEmail, DateTime.Now); var committer = author; var commit = repo.Commit(opts.GitCommitMsg, author, committer); // Push var pushOpts = new PushOptions { CredentialsProvider = credsProvider }; repo.Branches.Update(branch, b => b.Remote = "origin", b => b.UpstreamBranch = branch.CanonicalName); repo.Network.Push(branch, pushOpts); } return(await deployRequestCreator.Create()); }
public CloneOptions cloningSSHAuthentication() { var sshDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".ssh"); CloneOptions options = new CloneOptions(); SshUserKeyCredentials credentials = new SshUserKeyCredentials { Username = "******", PublicKey = Path.Combine(sshDir, "id_rsa.pub"), PrivateKey = Path.Combine(sshDir, "id_rsa"), Passphrase = "ce n'est rien..." }; var handler = new LibGit2Sharp.Handlers.CredentialsHandler((url, usernameFromUrl, types) => credentials); options.CredentialsProvider = handler; return(options); }
private static PushOptions GetOptions(LibGit2Sharp.Handlers.CredentialsHandler credentialsProvider) => new PushOptions { CredentialsProvider = credentialsProvider };