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); }
private static async Task CreatePullRequestAsync(IEnumerable <IDependencyInfo> buildInfos) { 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"; await prCreator.CreateOrUpdateAsync( commitMessage, commitMessage, string.Empty, new GitHubBranch(Options.GitHubUpstreamBranch, new GitHubProject(Options.GitHubProject, Options.GitHubUpstreamOwner)), new GitHubProject(Options.GitHubProject, gitHubAuth.User), prOptions); }
public static void Main(string[] args) { DebugHelper.HandleDebugSwitch(ref args); bool onlyUpdate = args.Length > 0 && string.Equals("--Update", args[0], StringComparison.OrdinalIgnoreCase); List <BuildInfo> buildInfos = new List <BuildInfo>(); buildInfos.Add(BuildInfo.Get("Roslyn", s_config.RoslynVersionUrl, fetchLatestReleaseFile: false)); buildInfos.Add(BuildInfo.Get("CoreSetup", s_config.CoreSetupVersionUrl, 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 (updateResults.ChangesDetected() && !onlyUpdate) { 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(); } }
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>(s_config.VersionFragments.Select <KeyValuePair <string, string>, BuildInfo>(fragment => GetBuildInfo(fragment.Key, fragment.Value, fetchLatestReleaseFile: false))); IEnumerable <IDependencyUpdater> updaters = GetUpdaters().ToArray(); var dependencyBuildInfos = buildInfos.Select(buildInfo => new BuildDependencyInfo( buildInfo, upgradeStableVersions: true, disabledPackages: Enumerable.Empty <string>())).ToArray(); 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 static async Task CreatePullRequestAsync(DependencyUpdateResults updateResults) { 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 sdkVersion = updateResults.UsedInfos.GetBuildVersion(SdkBuildInfoName); string commitMessage = $"Update {Options.GitHubUpstreamBranch} SDK to {sdkVersion}"; await prCreator.CreateOrUpdateAsync( commitMessage, commitMessage, string.Empty, new GitHubBranch(Options.GitHubUpstreamBranch, new GitHubProject(Options.GitHubProject, Options.GitHubUpstreamOwner)), new GitHubProject(Options.GitHubProject, gitHubAuth.User), prOptions); }
private async Task CreatePullRequestAsync(DependencyUpdateResults updateResults) { var gitHubAuth = new GitHubAuth(GitHubPassword, GitHubUser, GitHubEmail); var prCreator = new PullRequestCreator(gitHubAuth, GitHubUser); var prOptions = new PullRequestOptions() { BranchNamingStrategy = new SingleBranchNamingStrategy($"UpdateDependencies-{GitHubUpstreamBranch}") }; var runtimeVersion = updateResults.UsedInfos.First().SimpleVersion; var commitMessage = $"Update aspnetcore on {GitHubUpstreamBranch} to {runtimeVersion}"; await prCreator.CreateOrUpdateAsync( commitMessage, commitMessage, string.Empty, new GitHubBranch(GitHubUpstreamBranch, new GitHubProject(GitHubProject, GitHubUpstreamOwner)), new GitHubProject(GitHubProject, gitHubAuth.User), prOptions); }
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 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(); } }
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 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); }
protected override void TraceListenedExecute() { // Use the commit sha of versions repo master (not just "master") for stable upgrade. var gitHubAuth = new GitHubAuth(GitHubAuthToken, GitHubUser, GitHubEmail); var client = new GitHubClient(gitHubAuth); string masterSha = client .GetReferenceAsync(new GitHubProject("versions", "dotnet"), "heads/master") .Result.Object.Sha; foreach (ITaskItem item in DependencyBuildInfo) { if (!string.IsNullOrEmpty(item.GetMetadata(CurrentRefMetadataName))) { item.SetMetadata(CurrentRefMetadataName, masterSha); } string autoUpgradeBranch = item.GetMetadata(AutoUpgradeBranchMetadataName); if (!string.IsNullOrEmpty(autoUpgradeBranch)) { item.SetMetadata(CurrentBranchMetadataName, autoUpgradeBranch); } } DependencyUpdateResults updateResults = DependencyUpdateUtils.Update( CreateUpdaters().ToArray(), CreateBuildInfoDependencies().ToArray()); // Update CurrentRef and CurrentBranch for each applicable build info used. if (!string.IsNullOrEmpty(CurrentRefXmlPath)) { foreach (BuildInfo info in updateResults.UsedBuildInfos) { ITaskItem infoItem = FindDependencyBuildInfo(info.Name); if (!string.IsNullOrEmpty(infoItem.GetMetadata(CurrentRefMetadataName))) { UpdateProperty( CurrentRefXmlPath, $"{info.Name}{CurrentRefMetadataName}", masterSha); } string autoUpgradeBranch = infoItem.GetMetadata(AutoUpgradeBranchMetadataName); if (!string.IsNullOrEmpty(autoUpgradeBranch)) { UpdateProperty( CurrentRefXmlPath, $"{info.Name}{CurrentBranchMetadataName}", autoUpgradeBranch); } } } if (updateResults.ChangesDetected()) { 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(); } else { Log.LogMessage("No update required: no changes detected."); } }
public static void Run([TimerTrigger("0 0 9 * * 1-5")] TimerInfo myTimer, ILogger log) { log.LogInformation($"DescriptionsScraper function started. Time: {DateTime.UtcNow}"); try { PermissionsAppConfig permsAppConfig = PermissionsAppConfig.ReadFromJsonFile("local.settings.json"); log.LogInformation($"Authenticating into the Web API... Time: {DateTime.UtcNow}"); var authResult = AuthService.GetAuthentication(permsAppConfig); if (authResult == null) { log.LogInformation($"Failed to get authentication into the Web API. Time: {DateTime.UtcNow}"); return; } log.LogInformation($"Successfully authenticated into the Web API. Time: {DateTime.UtcNow}"); _scopesDescriptions = new Dictionary <string, List <Dictionary <string, object> > >(); if (permsAppConfig.ApiVersions?.Length > 0) { _uniqueScopes = new HashSet <string>(); foreach (string apiVersion in permsAppConfig.ApiVersions) { log.LogInformation($"Fetching Service Principal permissions descriptions for {apiVersion}. Time: {DateTime.UtcNow}"); PopulateScopesDescriptions(permsAppConfig, authResult, apiVersion); log.LogInformation($"Finished fetching Service Principal permissions descriptions for {apiVersion}. Time: {DateTime.UtcNow}"); } } if (!_scopesDescriptions.Any()) { log.LogInformation($"{nameof(_scopesDescriptions)} dictionary returned empty data. " + $"Exiting function DescriptionsScraper Time: {DateTime.UtcNow}"); return; } var servicePrincipalScopes = JsonConvert.SerializeObject(_scopesDescriptions, Formatting.Indented) .Replace("\r", string.Empty); // Hack to avoid whitespace diff with GitHub source document (formatted with only \n) // Fetch permissions descriptions from GitHub repo var gitHubAppConfig = new GitHubRepoAppConfig { GitHubAppId = permsAppConfig.GitHubAppId, GitHubOrganization = permsAppConfig.GitHubOrganization, GitHubAppName = permsAppConfig.GitHubAppName, GitHubRepoName = permsAppConfig.GitHubRepoName, ReferenceBranch = permsAppConfig.ReferenceBranch, FileContentPath = permsAppConfig.FileContentPath, WorkingBranch = permsAppConfig.WorkingBranch, Reviewers = permsAppConfig.Reviewers, PullRequestTitle = permsAppConfig.PullRequestTitle, PullRequestBody = permsAppConfig.PullRequestBody, PullRequestLabels = permsAppConfig.PullRequestLabels, PullRequestAssignees = permsAppConfig.PullRequestAssignees, CommitMessage = permsAppConfig.CommitMessage, TreeItemMode = Enums.TreeItemMode.Blob }; log.LogInformation($"Fetching permissions descriptions from GitHub repository '{gitHubAppConfig.GitHubRepoName}', branch '{permsAppConfig.ReferenceBranch}'. " + $"Time: {DateTime.UtcNow}"); // Fetch permissions descriptions from repo. var repoScopes = BlobContentReader.ReadRepositoryBlobContentAsync(gitHubAppConfig, permsAppConfig.GitHubAppKey).GetAwaiter().GetResult(); log.LogInformation($"Finished fetching permissions descriptions from GitHub repository '{gitHubAppConfig.GitHubRepoName}', branch '{permsAppConfig.ReferenceBranch}'. " + $"Time: {DateTime.UtcNow}"); log.LogInformation($"Comparing scopes from the Service Principal and the GitHub repository '{gitHubAppConfig.GitHubRepoName}', branch '{permsAppConfig.ReferenceBranch}' " + $"for new updates... Time: {DateTime.UtcNow}"); // Compare GitHub permissions descriptions to Service Principal permissions descriptions if (servicePrincipalScopes.Equals(repoScopes, StringComparison.OrdinalIgnoreCase)) { log.LogInformation($"No permissions descriptions update required. Exiting function 'DescriptionsScraper'. Time: {DateTime.UtcNow}"); return; } // Save the new Service Principal scopes gitHubAppConfig.FileContent = servicePrincipalScopes; log.LogInformation($"Writing updated Service Principal permissions descriptions into GitHub repository '{gitHubAppConfig.GitHubRepoName}', " + $"branch '{gitHubAppConfig.WorkingBranch}'. Time: {DateTime.UtcNow}"); // Write permissions descriptions to repo. BlobContentWriter.WriteToRepositoryAsync(gitHubAppConfig, permsAppConfig.GitHubAppKey).GetAwaiter().GetResult(); log.LogInformation($"Finished updating Service Principal permissions descriptions into GitHub repository '{gitHubAppConfig.GitHubRepoName}', " + $"branch '{gitHubAppConfig.WorkingBranch}'. Time: {DateTime.UtcNow}"); // Create PR log.LogInformation($"Creating PR for updated Service Principal permissions descriptions in GitHub repository '{gitHubAppConfig.GitHubRepoName}'" + $" from branch '{gitHubAppConfig.WorkingBranch}' into branch '{gitHubAppConfig.ReferenceBranch}'. Time: {DateTime.UtcNow}"); PullRequestCreator.CreatePullRequestAsync(gitHubAppConfig, permsAppConfig.GitHubAppKey).GetAwaiter().GetResult(); log.LogInformation($"Finished creating PR for updated Service Principal permissions descriptions in GitHub repository '{gitHubAppConfig.GitHubRepoName}'" + $" from branch '{gitHubAppConfig.WorkingBranch}' into branch '{gitHubAppConfig.ReferenceBranch}'. Time: {DateTime.UtcNow}"); log.LogInformation($"Exiting function DescriptionsScraper. Time: {DateTime.UtcNow}"); } catch (ApiException ex) { if (ex.ApiError.Errors != null) { foreach (var item in ex.ApiError.Errors) { log.LogInformation($"Exception occurred: {item.Message} Time: {DateTime.UtcNow}"); } return; } log.LogInformation($"Exception occurred: {ex.ApiError.Message} Time: {DateTime.UtcNow}"); } catch (Exception ex) { log.LogInformation($"Exception occurred: {ex.InnerException?.Message ?? ex.Message} Time: {DateTime.UtcNow}"); log.LogInformation($"Exception stack trace: {ex.StackTrace}"); } }