async Task <PullRequest> HasOpenPullRequest(string owner, string name) { var pullRequests = await Wrap.RateLimiting(client, c => c.PullRequest.GetAllForRepository(owner, name, new ApiOptions() { PageSize = 100 })); foreach (var pullRequest in pullRequests) { var files = await Wrap.RateLimiting(client, c => c.PullRequest.Files(owner, name, pullRequest.Number)); var updatesPaketToLatestVersion = files.FirstOrDefault(f => f.FileName == ".paket/paket.exe" && supportedPaketVersions.Contains(f.Sha) || f.FileName == ".paket/paket.bootstrapper.exe" && supportedPaketVersions.Contains(f.Sha)); if (updatesPaketToLatestVersion != null) { return(pullRequest); } } return(null); }
async Task <Reference> CreateNewReferenceWithPatch(Repository repository) { // first, create a new blob in the repository which is the new file contents var blob = new NewBlob() { Content = await GetNewExecutableBase64(), Encoding = EncodingType.Base64 }; var newBlob = await Wrap.RateLimiting(client, c => c.Git.Blob.Create(repository.Id, blob)); // we create the new reference for the PR branch var defaultRef = $"heads/{repository.DefaultBranch}"; var defaultBranch = await Wrap.RateLimiting(client, c => c.Git.Reference.Get(repository.Id, defaultRef)); var initialSha = defaultBranch.Object.Sha; var newRef = $"heads/bootstrapper"; var newReference = await Wrap.RateLimiting(client, c => c.Git.Reference.Create(repository.Id, new NewReference(newRef, initialSha))); var currentTree = await Wrap.RateLimiting(client, c => c.Git.Tree.Get(repository.Id, initialSha)); // update the paket subdirectory to assign the new blob to whatever executable var paketTreeNode = currentTree.Tree.FirstOrDefault(t => t.Path == ".paket"); var paketTree = await Wrap.RateLimiting(client, c => c.Git.Tree.Get(repository.Id, paketTreeNode.Sha)); var executables = paketTree.Tree.Where(t => t.Path.EndsWith(".exe")); if (executables.Count() == 0) { Console.WriteLine($"TODO: oh gosh, we're not able to find executables in the .paket directory"); return(null); } var executable = executables.ElementAt(0); var newPaketTree = new NewTree { BaseTree = paketTree.Sha, }; newPaketTree.Tree.Add(new NewTreeItem() { Mode = executable.Mode, Sha = newBlob.Sha, Path = executable.Path, Type = executable.Type.Value }); var updatedPaketTree = await Wrap.RateLimiting(client, c => c.Git.Tree.Create(repository.Id, newPaketTree)); // update the root tree to use this new .paket directory var newRootTree = new NewTree { BaseTree = currentTree.Sha }; newRootTree.Tree.Add(new NewTreeItem() { Mode = paketTreeNode.Mode, Sha = updatedPaketTree.Sha, Path = paketTreeNode.Path, Type = paketTreeNode.Type.Value }); var updatedRootTree = await Wrap.RateLimiting(client, c => c.Git.Tree.Create(repository.Id, newRootTree)); // create a new commit using the updated tree var newCommit = new NewCommit($"Updated {executable.Path} to address TLS 1.0 and 1.1 deprecation", updatedRootTree.Sha, initialSha); var commit = await Wrap.RateLimiting(client, c => c.Git.Commit.Create(repository.Id, newCommit)); // then update the bootstrapper ref to this new commit var updatedReference = await Wrap.RateLimiting(client, c => c.Git.Reference.Update(repository.Id, newRef, new ReferenceUpdate(commit.Sha))); return(updatedReference); }