private void TraceListenedExecute() { var auth = new GitHubAuth(GitHubAuthToken, GitHubUser, GitHubEmail); using (GitHubClient client = new GitHubClient(auth)) { var origin = new GitHubProject(ProjectRepoName, GitHubUser); var upstreamBranch = new GitHubBranch( ProjectRepoBranch, new GitHubProject(ProjectRepoName, ProjectRepoOwner)); string body = Body ?? string.Empty; if (NotifyGitHubUsers != null) { body += PullRequestCreator.NotificationString(NotifyGitHubUsers.Select(item => item.ItemSpec)); } var prCreator = new PullRequestCreator(client.Auth, GitHubAuthor); prCreator.CreateOrUpdateAsync( CommitMessage, CommitMessage + $" ({ProjectRepoBranch})", body, upstreamBranch, origin, new PullRequestOptions { ForceCreate = AlwaysCreateNewPullRequest, MaintainersCanModify = MaintainersCanModifyPullRequest, TrackDiscardedCommits = TrackDiscardedCommits }).Wait(); } }
public async Task PostGitHubPullRequestAsync( string title, string description, GitHubBranch headBranch, GitHubBranch baseBranch) { string createPrBody = JsonConvert.SerializeObject(new { title = title, body = description, head = $"{headBranch.Project.Owner}:{headBranch.Name}", @base = baseBranch.Name }, Formatting.Indented); string pullUrl = $"https://api.github.com/repos/{baseBranch.Project.Segments}/pulls"; var bodyContent = new StringContent(createPrBody); using (HttpResponseMessage response = await _httpClient.PostAsync(pullUrl, bodyContent)) { response.EnsureSuccessStatusCode(); Trace.TraceInformation($"Created pull request."); Trace.TraceInformation($"Pull request page: {await GetPullRequestUrlAsync(response)}"); } }
private async Task AddUpdatedFile( List <GitObject> updatedFiles, IGitHubClient client, GitHubBranch branch, string repo, string filePath, string updatedContent) { string gitPath = string.Join('/', Options.GitOptions.Path, repo, filePath); string currentContent = await client.GetGitHubFileContentsAsync(gitPath, branch); if (currentContent == updatedContent) { Logger.WriteMessage($"File '{filePath}' has not changed."); } else { Logger.WriteMessage($"File '{filePath}' has changed."); updatedFiles.Add(new GitObject { Path = gitPath, Type = GitObject.TypeBlob, Mode = GitObject.ModeFile, Content = updatedContent }); } }
private async Task <GitObject[]> GetUpdatedVerionInfo(GitHubClient client, GitHubBranch branch) { List <GitObject> versionInfo = new List <GitObject>(); foreach (string fromImage in Manifest.GetExternalFromImages()) { string currentDigest = DockerHelper.GetImageDigest(fromImage, Options.IsDryRun); string versionFile = $"{Options.GitPath}/{fromImage.Replace(':', '/')}.txt"; string lastDigest = await client.GetGitHubFileContentsAsync(versionFile, branch); if (lastDigest == currentDigest) { Logger.WriteMessage($"Image has not changed: {fromImage}"); continue; } Logger.WriteMessage($"Image has changed: {fromImage}"); Logger.WriteMessage($"Updating `{versionFile}` with `{currentDigest}`"); versionInfo.Add(new GitObject { Path = versionFile, Type = GitObject.TypeBlob, Mode = GitObject.ModeFile, Content = currentDigest }); } return(versionInfo.ToArray()); }
public async Task PostGitHubPullRequestAsync( string title, string description, GitHubBranch headBranch, GitHubBranch baseBranch, bool maintainersCanModify) { EnsureAuthenticated(); string createPrBody = JsonConvert.SerializeObject(new { title = title, body = description, head = $"{headBranch.Project.Owner}:{headBranch.Name}", @base = baseBranch.Name, maintainer_can_modify = maintainersCanModify }, Formatting.Indented); string pullUrl = $"https://api.github.com/repos/{baseBranch.Project.Segments}/pulls"; var bodyContent = new StringContent(createPrBody); using (HttpResponseMessage response = await _httpClient.PostAsync(pullUrl, bodyContent)) { await EnsureSuccessfulAsync(response); Trace.TraceInformation($"Created pull request."); Trace.TraceInformation($"Pull request page: {await GetPullRequestUrlAsync(response)}"); } }
public async Task PostGitHubPullRequestAsync( string title, string description, GitHubBranch headBranch, GitHubBranch baseBranch, // Ignored: GitHub-only feature. bool maintainersCanModify) { EnsureAuthenticated(); string createPrBody = JsonConvert.SerializeObject(new { title = title, description = description, sourceRefName = $"refs/heads/{headBranch.Name}", targetRefName = $"refs/heads/{baseBranch.Name}" }, Formatting.Indented); string pullUrl = $"{GitApiBaseUrl(baseBranch.Project)}pullrequests"; var bodyContent = new StringContent(createPrBody, Encoding.UTF8, "application/json"); using (HttpResponseMessage response = await _httpClient.PostAsync(pullUrl, bodyContent)) { await EnsureSuccessfulAsync(response); Trace.TraceInformation("Created pull request."); Trace.TraceInformation($"Pull request page: {await GetPullRequestUrlAsync(response)}"); } }
private async static Task AddUpdatedFile( List <GitObject> updatedFiles, GitHubClient client, GitHubBranch branch, string filePath, string updatedContent) { if (updatedContent.Contains("\r\n")) { updatedContent = updatedContent.Replace("\r\n", "\n"); } filePath = filePath.Replace('\\', '/'); string currentContent = await client.GetGitHubFileContentsAsync(filePath, branch); if (currentContent == updatedContent) { Console.WriteLine($"File '{filePath}' has not changed."); } else { Console.WriteLine($"File '{filePath}' has changed."); updatedFiles.Add(new GitObject { Path = filePath, Type = GitObject.TypeBlob, Mode = GitObject.ModeFile, Content = updatedContent }); } }
public override bool Execute() { Trace.Listeners.MsBuildListenedInvoke(Log, () => { var updater = new LocalVersionsRepoUpdater(); if (!string.IsNullOrEmpty(GitHubAuthToken)) { updater.GitHubAuth = new GitHubAuth(GitHubAuthToken, GitHubUser); } GitHubBranch branch = null; if (!string.IsNullOrEmpty(VersionsRepo)) { branch = new GitHubBranch( VersionsRepoBranch, new GitHubProject( VersionsRepo, VersionsRepoOwner)); } updater .UpdateBuildInfoFilesAsync( ShippedNuGetPackage.Select(i => i.ItemSpec), VersionsRepoLocalBaseDir, VersionsRepoPath, branch) .Wait(); }); return(true); }
public async Task <string> GetGitHubFileContentsAsync( string path, GitHubBranch branch) { GitHubContents file = await GetGitHubFileAsync(path, branch); return(FromBase64(file.Content)); }
private void DeleteOldFileData(GitHubBranch branch) { lock (thisLock) { List <GitHubFile> fileList = _context.GitHubFiles.Where(f => f.BranchId == branch.BranchId).ToList(); foreach (GitHubFile f in fileList) { _context.GitHubFiles.Remove(f); } _context.SaveChanges(); } }
public async Task <GitHubContents> GetGitHubFileAsync( string path, GitHubBranch branch) { string url = $"https://api.github.com/repos/{branch.Project.Segments}/contents/{path}?ref=heads/{branch.Name}"; Trace.TraceInformation($"Getting contents of '{path}' using '{url}'"); using (HttpResponseMessage response = await _httpClient.GetAsync(url)) { return(await DeserializeSuccessfulAsync <GitHubContents>(response)); } }
private async Task <List <GitHubBranch> > GetBranchData(GitHubRepository repo) { string AccessToken = await HttpContext.GetTokenAsync("access_token"); string[] repoData = repo.FullName.Split('/'); List <GitHubBranch> branchList = new List <GitHubBranch>(); var github = new GitHubClient(new ProductHeaderValue("AspNetCoreGitHubAuth"), new InMemoryCredentialStore(new Credentials(AccessToken))); IReadOnlyList <Branch> branches = await github.Repository.Branch.GetAll(repoData[0], repoData[1]); foreach (Branch b in branches) { GitHubBranch branch; lock (thisLock) { branch = _context.GitHubBranches.Where(br => br.Name == b.Name).Where(br => br.RepositoryId == repo.RepositoryId).SingleOrDefault(); } if (branch == null) { branch = new GitHubBranch(); branch.Name = b.Name; branch.RepositoryId = repo.RepositoryId; branch.Sha = b.Commit.Sha; branch.ApiUrl = b.Commit.Url; branch.IsMaster = false; lock (thisLock) { _context.GitHubBranches.Add(branch); _context.SaveChanges(); } await GetBranchFiles(repoData[0], repoData[1], branch); } else if (branch.Sha != b.Commit.Sha) { branch.Sha = b.Commit.Sha; branch.ApiUrl = b.Commit.Url; lock (thisLock) { _context.GitHubBranches.Add(branch); _context.SaveChanges(); } DeleteOldFileData(branch); await GetBranchFiles(repoData[0], repoData[1], branch); } branchList.Add(branch); } return(branchList); }
private static async Task CreatePullRequestAsync(GitHubClient client, GitRepo gitRepo, Config config) { GitHubProject project = new GitHubProject(gitRepo.Name, gitRepo.Owner); GitHubProject forkedProject = new GitHubProject(gitRepo.Name, Options.GitUser); GitHubBranch baseBranch = new GitHubBranch(gitRepo.Branch, project); GitHubBranch headBranch = new GitHubBranch( $"{gitRepo.Name}-{gitRepo.Branch}{config.WorkingBranchSuffix}", forkedProject); IEnumerable <GitObject> changes = await GetUpdatedFiles(config.SourcePath, client, baseBranch); if (!changes.Any()) { return; } GitReference currentRef = await client.GetReferenceAsync(project, $"heads/{baseBranch.Name}"); string parentSha = currentRef.Object.Sha; GitTree tree = await client.PostTreeAsync(forkedProject, parentSha, changes.ToArray()); GitCommit commit = await client.PostCommitAsync(forkedProject, config.CommitMessage, tree.Sha, new[] { parentSha }); string workingReference = $"heads/{headBranch.Name}"; if (await BranchExists(client, forkedProject, workingReference)) { await client.PatchReferenceAsync(forkedProject, workingReference, commit.Sha, force : true); } else { await client.PostReferenceAsync(forkedProject, workingReference, commit.Sha); } GitHubPullRequest pullRequestToUpdate = await client.SearchPullRequestsAsync( project, headBranch.Name, await client.GetMyAuthorIdAsync()); if (pullRequestToUpdate == null) { await client.PostGitHubPullRequestAsync( $"[{gitRepo.Branch}] {config.PullRequestTitle}", config.PullRequestDescription, headBranch, baseBranch, maintainersCanModify : true); } }
public static void Main(string[] args) { HandleDebugSwitch(ref args); bool onlyUpdate = args.Length > 0 && string.Equals("--Update", args[0], StringComparison.OrdinalIgnoreCase); List <BuildInfo> buildInfos = new List <BuildInfo>(); buildInfos.Add(GetBuildInfo("CoreSetup", s_config.CoreSetupVersionFragment, fetchLatestReleaseFile: false)); if (s_config.HasRoslynVersionFragment) { buildInfos.Add(GetBuildInfo("Roslyn", s_config.RoslynVersionFragment, fetchLatestReleaseFile: false)); } IEnumerable <IDependencyUpdater> updaters = GetUpdaters(); var dependencyBuildInfos = buildInfos.Select(buildInfo => new BuildDependencyInfo( buildInfo, upgradeStableVersions: true, disabledPackages: Enumerable.Empty <string>())); DependencyUpdateResults updateResults = DependencyUpdateUtils.Update(updaters, dependencyBuildInfos); if (!onlyUpdate && updateResults.ChangesDetected()) { GitHubAuth gitHubAuth = new GitHubAuth(s_config.Password, s_config.UserName, s_config.Email); GitHubProject origin = new GitHubProject(s_config.GitHubProject, s_config.UserName); GitHubBranch upstreamBranch = new GitHubBranch( s_config.GitHubUpstreamBranch, new GitHubProject(s_config.GitHubProject, s_config.GitHubUpstreamOwner)); string suggestedMessage = updateResults.GetSuggestedCommitMessage(); string body = string.Empty; if (s_config.GitHubPullRequestNotifications.Any()) { body += PullRequestCreator.NotificationString(s_config.GitHubPullRequestNotifications); } new PullRequestCreator(gitHubAuth) .CreateOrUpdateAsync( suggestedMessage, suggestedMessage + $" ({upstreamBranch.Name})", body, upstreamBranch, origin, new PullRequestOptions()) .Wait(); } }
private async Task <ImageArtifactDetails> GetImageInfoForSubscriptionAsync(Subscription subscription, ManifestInfo manifest) { string imageDataJson; using (IGitHubClient gitHubClient = _gitHubClientFactory.GetClient(Options.GitOptions.ToGitHubAuth(), Options.IsDryRun)) { GitHubProject project = new GitHubProject(subscription.ImageInfo.Repo, subscription.ImageInfo.Owner); GitHubBranch branch = new GitHubBranch(subscription.ImageInfo.Branch, project); GitFile repo = subscription.Manifest; imageDataJson = await gitHubClient.GetGitHubFileContentsAsync(subscription.ImageInfo.Path, branch); } return(ImageInfoHelper.LoadFromContent(imageDataJson, manifest, skipManifestValidation: true)); }
public async Task <string> GetGitHubFileContentsAsync( string path, GitHubBranch branch) { try { GitHubContents file = await GetGitHubFileAsync(path, branch.Project, $"heads/{branch.Name}"); return(ClientHelpers.FromBase64(file.Content)); } catch (HttpFailureResponseException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound) { return(null); } }
public override async Task ExecuteAsync() { Logger.WriteHeading("UPDATING VERSIONS"); // Hookup a TraceListener in order to capture details from Microsoft.DotNet.VersionTools Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); DockerHelper.PullBaseImages(Manifest, Options); GitHubAuth githubAuth = new GitHubAuth(Options.GitAuthToken, Options.GitUsername, Options.GitEmail); using (GitHubClient client = new GitHubClient(githubAuth)) { for (int i = 0; i < MaxTries; i++) { try { GitHubProject project = new GitHubProject(Options.GitRepo, Options.GitOwner); GitHubBranch branch = new GitHubBranch(Options.GitBranch, project); GitObject[] gitObjects = await GetUpdatedVerionInfo(client, branch); if (gitObjects.Any()) { string masterRef = $"heads/{Options.GitBranch}"; GitReference currentMaster = await client.GetReferenceAsync(project, masterRef); string masterSha = currentMaster.Object.Sha; GitTree tree = await client.PostTreeAsync(project, masterSha, gitObjects); string commitMessage = "Update Docker image digests"; GitCommit commit = await client.PostCommitAsync( project, commitMessage, tree.Sha, new[] { masterSha }); // Only fast-forward. Don't overwrite other changes: throw exception instead. await client.PatchReferenceAsync(project, masterRef, commit.Sha, force : false); } break; } catch (HttpRequestException ex) when(i < (MaxTries - 1)) { Logger.WriteMessage($"Encountered exception committing build-info update: {ex.Message}"); Logger.WriteMessage($"Trying again in {RetryMillisecondsDelay}ms. {MaxTries - i - 1} tries left."); await Task.Delay(RetryMillisecondsDelay); } } } }
private async Task <RepoData[]> GetImageInfoForSubscriptionAsync(Subscription subscription) { string imageDataJson; using (IGitHubClient gitHubClient = this.gitHubClientFactory.GetClient(Options.GitOptions.ToGitHubAuth(), Options.IsDryRun)) { GitHubProject project = new GitHubProject(Options.GitOptions.Repo, Options.GitOptions.Owner); GitHubBranch branch = new GitHubBranch(Options.GitOptions.Branch, project); GitRepo repo = subscription.RepoInfo; string imageInfoPath = $"{Options.GitOptions.Path}/image-info.{repo.Owner}-{repo.Name}-{repo.Branch}.json"; imageDataJson = await gitHubClient.GetGitHubFileContentsAsync(imageInfoPath, branch); } return(JsonConvert.DeserializeObject <RepoData[]>(imageDataJson)); }
public static void Main(string[] args) { DebugHelper.HandleDebugSwitch(ref args); bool onlyUpdate; ParseArgs(args, out onlyUpdate); List <BuildInfo> buildInfos = new List <BuildInfo>(); buildInfos.Add(GetBuildInfo("CoreFx", s_config.CoreFxVersionUrl, fetchLatestReleaseFile: false)); buildInfos.Add(GetBuildInfo("CoreClr", s_config.CoreClrVersionUrl, fetchLatestReleaseFile: false)); buildInfos.Add(GetBuildInfo("Standard", s_config.StandardVersionUrl, fetchLatestReleaseFile: false)); IEnumerable <IDependencyUpdater> updaters = GetUpdaters(); var dependencyBuildInfos = buildInfos.Select(buildInfo => new DependencyBuildInfo( buildInfo, upgradeStableVersions: true, disabledPackages: Enumerable.Empty <string>())); DependencyUpdateResults updateResults = DependencyUpdateUtils.Update(updaters, dependencyBuildInfos); if (!onlyUpdate && updateResults.ChangesDetected()) { GitHubAuth gitHubAuth = new GitHubAuth(s_config.Password, s_config.UserName, s_config.Email); GitHubProject origin = new GitHubProject(s_config.GitHubProject, s_config.UserName); GitHubBranch upstreamBranch = new GitHubBranch( s_config.GitHubUpstreamBranch, new GitHubProject(s_config.GitHubProject, s_config.GitHubUpstreamOwner)); string suggestedMessage = updateResults.GetSuggestedCommitMessage(); string body = string.Empty; if (s_config.GitHubPullRequestNotifications.Any()) { body += PullRequestCreator.NotificationString(s_config.GitHubPullRequestNotifications); } new PullRequestCreator(gitHubAuth, origin, upstreamBranch) .CreateOrUpdateAsync( suggestedMessage, suggestedMessage + $" ({upstreamBranch.Name})", body) .Wait(); } }
private static void CreatePullRequest(DependencyUpdateResults updateResults) { GitHubAuth gitHubAuth = new GitHubAuth(config.Password, config.UserName, config.Email); GitHubProject origin = new GitHubProject(config.GitHubProject, config.UserName); GitHubBranch upstreamBranch = new GitHubBranch(config.GitHubUpstreamBranch, new GitHubProject(config.GitHubProject, config.GitHubUpstreamOwner)); string commitMessage = updateResults.GetSuggestedCommitMessage(); string body = string.Empty; if (config.GitHubPullRequestNotifications.Any()) { body += PullRequestCreator.NotificationString(config.GitHubPullRequestNotifications); } new PullRequestCreator(gitHubAuth, origin, upstreamBranch) .CreateOrUpdateAsync(commitMessage, commitMessage + $" ({upstreamBranch.Name})", body) .Wait(); }
public override bool Execute() { MsBuildTraceListener[] listeners = Trace.Listeners.AddMsBuildTraceListeners(Log); try { IDependencyUpdater[] updaters = GetDependencyUpdaters().ToArray(); BuildInfo[] buildInfos = GetBuildInfos().ToArray(); var updater = new DependencyUpdater(); DependencyUpdateResults updateResults = updater.Update(updaters, buildInfos); if (updateResults.ChangesDetected()) { var gitHubAuth = new GitHubAuth(GitHubAuthToken, GitHubUser, GitHubEmail); var origin = new GitHubProject(ProjectRepoName, GitHubUser); var upstreamBranch = new GitHubBranch( ProjectRepoBranch, new GitHubProject(ProjectRepoName, ProjectRepoOwner)); string suggestedMessage = updateResults.GetSuggestedCommitMessage(); string body = string.Empty; if (NotifyGitHubUsers != null) { body += PullRequestCreator.NotificationString(NotifyGitHubUsers.Select(item => item.ItemSpec)); } var prCreator = new PullRequestCreator(gitHubAuth, origin, upstreamBranch, GitHubAuthor); prCreator.CreateOrUpdateAsync( suggestedMessage, suggestedMessage + $" ({ProjectRepoBranch})", body, forceCreate: AlwaysCreateNewPullRequest).Wait(); } } finally { Trace.Listeners.RemoveMsBuildTraceListeners(listeners); } return(true); }
public static async Task <GitReference> PushChangesAsync(IGitHubClient client, IGitOptionsHost options, string commitMessage, Func <GitHubBranch, Task <IEnumerable <GitObject> > > getChanges) { GitOptions gitOptions = options.GitOptions; GitHubProject project = new GitHubProject(gitOptions.Repo, gitOptions.Owner); GitHubBranch branch = new GitHubBranch(gitOptions.Branch, project); IEnumerable <GitObject> changes = await getChanges(branch); if (!changes.Any()) { return(null); } string masterRef = $"heads/{gitOptions.Branch}"; GitReference currentMaster = await client.GetReferenceAsync(project, masterRef); string masterSha = currentMaster.Object.Sha; if (!options.IsDryRun) { GitTree tree = await client.PostTreeAsync(project, masterSha, changes.ToArray()); GitCommit commit = await client.PostCommitAsync( project, commitMessage, tree.Sha, new[] { masterSha }); // Only fast-forward. Don't overwrite other changes: throw exception instead. return(await client.PatchReferenceAsync(project, masterRef, commit.Sha, force : false)); } else { Logger.WriteMessage($"The following files would have been updated at {gitOptions.Owner}/{gitOptions.Repo}/{gitOptions.Branch}:"); Logger.WriteMessage(); foreach (GitObject gitObject in changes) { Logger.WriteMessage($"{gitObject.Path}:"); Logger.WriteMessage(gitObject.Content); Logger.WriteMessage(); } return(null); } }
private static async Task CreatePullRequestAsync() { // Replace slashes with hyphens for use in naming the branch string versionSourceNameForBranch = Options.VersionSourceName.Replace("/", "-"); GitHubAuth gitHubAuth = new GitHubAuth(Options.GitHubPassword, Options.GitHubUser, Options.GitHubEmail); PullRequestCreator prCreator = new PullRequestCreator(gitHubAuth, Options.GitHubUser); string branchSuffix = $"UpdateDependencies-{Options.GitHubUpstreamBranch}-From-{versionSourceNameForBranch}"; PullRequestOptions prOptions = new PullRequestOptions() { BranchNamingStrategy = new SingleBranchNamingStrategy(branchSuffix) }; string commitMessage = $"[{Options.GitHubUpstreamBranch}] Update dependencies from {Options.VersionSourceName}"; GitHubProject upstreamProject = new GitHubProject(Options.GitHubProject, Options.GitHubUpstreamOwner); GitHubBranch upstreamBranch = new GitHubBranch(Options.GitHubUpstreamBranch, upstreamProject); using (GitHubClient client = new GitHubClient(gitHubAuth)) { GitHubPullRequest pullRequestToUpdate = await client.SearchPullRequestsAsync( upstreamProject, upstreamBranch.Name, await client.GetMyAuthorIdAsync()); if (pullRequestToUpdate == null || pullRequestToUpdate.Head.Ref != $"{upstreamBranch.Name}-{branchSuffix}") { await prCreator.CreateOrUpdateAsync( commitMessage, commitMessage, string.Empty, upstreamBranch, new GitHubProject(Options.GitHubProject, gitHubAuth.User), prOptions); } else { UpdateExistingPullRequest(gitHubAuth, prOptions, commitMessage, upstreamBranch); } } }
private async Task <IEnumerable <GitObject> > FilterUpdatedGitObjectsAsync( IEnumerable <GitObject> gitObjects, IGitHubClient gitHubClient, GitHubBranch branch) { List <GitObject> updatedGitObjects = new(); foreach (GitObject gitObject in gitObjects) { string currentContent = await gitHubClient.GetGitHubFileContentsAsync(gitObject.Path, branch); if (currentContent == gitObject.Content) { _loggerService.WriteMessage($"File '{gitObject.Path}' has not changed."); } else { _loggerService.WriteMessage($"File '{gitObject.Path}' has changed."); updatedGitObjects.Add(gitObject); } } return(updatedGitObjects); }
private static async Task CreatePullRequest() { var gitHubAuth = new GitHubAuth(_config.GithubToken, _config.GithubUsername, _config.GithubEmail); var origin = new GitHubProject(_config.GithubProject, _config.GithubUsername); var upstreamBranch = new GitHubBranch(_config.GithubUpstreamBranch, new GitHubProject(_config.GithubProject, _config.GithubUpstreamOwner)); var commitMessage = $"Updating external dependencies to '{ await GetOrchestratedBuildId() }'"; var body = string.Empty; if (_config.GitHubPullRequestNotifications.Any()) { body += PullRequestCreator.NotificationString(_config.GitHubPullRequestNotifications); } body += $"New versions:{Environment.NewLine}"; foreach (var updatedVersion in _config.UpdatedVersionsList) { body += $" {updatedVersion}{Environment.NewLine}"; } await new PullRequestCreator(gitHubAuth, origin, upstreamBranch) .CreateOrUpdateAsync(commitMessage, commitMessage + $" ({upstreamBranch.Name})", body); }
private static async Task CreatePullRequestAsync() { GitHubAuth gitHubAuth = new GitHubAuth(Options.GitHubPassword, Options.GitHubUser, Options.GitHubEmail); PullRequestCreator prCreator = new PullRequestCreator(gitHubAuth, Options.GitHubUser); PullRequestOptions prOptions = new PullRequestOptions() { BranchNamingStrategy = new SingleBranchNamingStrategy($"UpdateDependencies-{Options.GitHubUpstreamBranch}") }; string commitMessage = $"[{Options.GitHubUpstreamBranch}] Update dependencies from dotnet/core-sdk"; GitHubProject upstreamProject = new GitHubProject(Options.GitHubProject, Options.GitHubUpstreamOwner); GitHubBranch upstreamBranch = new GitHubBranch(Options.GitHubUpstreamBranch, upstreamProject); using (GitHubClient client = new GitHubClient(gitHubAuth)) { GitHubPullRequest pullRequestToUpdate = await client.SearchPullRequestsAsync( upstreamProject, upstreamBranch.Name, await client.GetMyAuthorIdAsync()); if (pullRequestToUpdate == null) { await prCreator.CreateOrUpdateAsync( commitMessage, commitMessage, string.Empty, upstreamBranch, new GitHubProject(Options.GitHubProject, gitHubAuth.User), prOptions); } else { UpdateExistingPullRequest(gitHubAuth, prOptions, commitMessage, upstreamBranch); } } }
private void TraceListenedExecute() { // GitHub and VSTS have different dev flow conventions. GitHubProject origin; using (IGitHubClient client = CreateClient(out origin)) { var upstreamBranch = new GitHubBranch( ProjectRepoBranch, new GitHubProject(ProjectRepoName, ProjectRepoOwner)); string body = Body ?? string.Empty; if (NotifyGitHubUsers != null) { body += PullRequestCreator.NotificationString(NotifyGitHubUsers.Select(item => item.ItemSpec)); } var options = new PullRequestOptions { ForceCreate = AlwaysCreateNewPullRequest, MaintainersCanModify = MaintainersCanModifyPullRequest, TrackDiscardedCommits = TrackDiscardedCommits }; var prCreator = new PullRequestCreator(client.Auth, PullRequestAuthor); prCreator.CreateOrUpdateAsync( CommitMessage, CommitMessage + $" ({ProjectRepoBranch})", body, upstreamBranch, origin, options, client).Wait(); } }
public Task PostGitHubPullRequestAsync(string title, string description, GitHubBranch headBranch, GitHubBranch baseBranch, bool maintainersCanModify) { EnsureNotDryRun(); return(_innerClient.PostGitHubPullRequestAsync(title, description, headBranch, baseBranch, maintainersCanModify)); }
public Task <string> GetGitHubFileContentsAsync(string path, GitHubBranch branch) => RetryHelper.GetWaitAndRetryPolicy <Exception>(_loggerService) .ExecuteAsync(() => _innerClient.GetGitHubFileContentsAsync(path, branch));
public Task <string> GetGitHubFileContentsAsync(string path, GitHubBranch branch) => _innerClient.GetGitHubFileContentsAsync(path, branch);
private async static Task <GitObject[]> GetUpdatedFiles(string sourcePath, GitHubClient client, GitHubBranch branch) { List <GitObject> updatedFiles = new List <GitObject>(); foreach (string file in GetFiles(sourcePath)) { await AddUpdatedFile(updatedFiles, client, branch, file, File.ReadAllText(file)); } return(updatedFiles.ToArray()); }