protected override void TraceListenedExecute() { GitHubAuth auth = null; if (string.IsNullOrEmpty(GitHubAuthToken)) { Log.LogMessage( MessageImportance.Low, $"No value for '{nameof(GitHubAuthToken)}'. " + "Accessing GitHub API anonymously."); } else { auth = new GitHubAuth(GitHubAuthToken, GitHubUser); } using (var client = new GitHubClient(auth)) { DependencyUpdateResults updateResults = UpdateToRemote(client); MadeChanges = updateResults.ChangesDetected(); SuggestedCommitMessage = updateResults.GetSuggestedCommitMessage(); if (MadeChanges) { Log.LogMessage( MessageImportance.Normal, $"Suggested commit message: '{SuggestedCommitMessage}'"); } else { Log.LogMessage(MessageImportance.Normal, "No changes performed."); } } }
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 override bool Execute() { string contents = System.IO.File.ReadAllText(ManifestFile); var model = OrchestratedBuildModel.Parse(XElement.Parse(contents)); if (string.IsNullOrEmpty(CommitMessage)) { CommitMessage = $"{model.Identity} orchestrated build manifest"; } var gitHubAuth = new GitHubAuth(GitHubAuthToken, GitHubUser, GitHubEmail); using (var gitHubClient = new GitHubClient(gitHubAuth)) { var client = new BuildManifestClient(gitHubClient); var location = new BuildManifestLocation( new GitHubProject(VersionsRepo, VersionsRepoOwner), $"heads/{VersionsRepoBranch}", VersionsRepoPath); var pushTask = client.PushNewBuildAsync( location, model, CreateUploadRequests(SupplementaryFiles), CommitMessage); pushTask.Wait(); } return(!Log.HasLoggedErrors); }
public static async Task ExecuteGitOperationsWithRetryAsync( Options options, Func <GitHubClient, Task> execute, int maxTries = 10, int retryMillisecondsDelay = 5000) { GitHubAuth githubAuth = new GitHubAuth(options.GitAuthToken, options.GitUser, options.GitEmail); using (GitHubClient client = new GitHubClient(githubAuth)) { for (int i = 0; i < maxTries; i++) { try { await execute(client); break; } catch (HttpRequestException ex) when(i < (maxTries - 1)) { Console.WriteLine($"Encountered exception interacting with GitHub: {ex.Message}"); Console.WriteLine($"Trying again in {retryMillisecondsDelay}ms. {maxTries - i - 1} tries left."); await Task.Delay(retryMillisecondsDelay); } } } }
public static void Main(string[] args) { DebugHelper.HandleDebugSwitch(ref args); List <BuildInfo> buildInfos = new List <BuildInfo>(); buildInfos.Add(BuildInfo.Get("CoreFx", s_config.CoreFxVersionUrl, fetchLatestReleaseFile: false)); buildInfos.Add(BuildInfo.Get("CoreClr", s_config.CoreClrVersionUrl, fetchLatestReleaseFile: false)); buildInfos.Add(BuildInfo.Get("Roslyn", s_config.RoslynVersionUrl, fetchLatestReleaseFile: false)); buildInfos.Add(BuildInfo.Get("CoreSetup", s_config.CoreSetupVersionUrl, fetchLatestReleaseFile: false)); IEnumerable <IDependencyUpdater> updaters = GetUpdaters(); GitHubAuth gitHubAuth = new GitHubAuth(s_config.Password, s_config.UserName, s_config.Email); DependencyUpdater dependencyUpdater = new DependencyUpdater( gitHubAuth, s_config.GitHubProject, s_config.GitHubUpstreamOwner, s_config.GitHubUpstreamBranch, s_config.UserName, s_config.GitHubPullRequestNotifications); if (args.Length > 0 && string.Equals("--Update", args[0], StringComparison.OrdinalIgnoreCase)) { dependencyUpdater.Update(updaters, buildInfos); } else { dependencyUpdater.UpdateAndSubmitPullRequestAsync(updaters, buildInfos); } }
public GitHubClient(GitHubAuth auth) { _auth = auth; _httpClient = new HttpClient(); _httpClient.DefaultRequestHeaders.Add("Accept", "application/vnd.github.v3+json"); _httpClient.DefaultRequestHeaders.Add("Authorization", $"token {auth.AuthToken}"); _httpClient.DefaultRequestHeaders.Add("User-Agent", auth.User); }
public GitHubWriteVersionUpdater( GitHubAuth gitHubAuth, string versionsRepoOwner = null, string versionsRepo = null) : this( gitHubAuth, new GitHubProject(versionsRepo ?? "versions", versionsRepoOwner)) { }
public void ShouldNotSignIn() { var user = new User("*****@*****.**", "123456", ServerType.Gmail); var login = new GitHubAuth(); _ = login.SignIn(user); var information = login.GetUserInformation(); Assert.Null(information); }
public GitHubClient(GitHubAuth auth) { Auth = auth; _httpClient = X509Helper.GetHttpClientWithCertRevocation(); _httpClient.DefaultRequestHeaders.Add("Accept", "application/vnd.github.v3+json"); _httpClient.DefaultRequestHeaders.Add("User-Agent", auth?.User ?? DefaultUserAgent); if (auth?.AuthToken != null) { _httpClient.DefaultRequestHeaders.Add("Authorization", $"token {auth.AuthToken}"); } }
public UsersController(GitHubAuth ghAuth, CoreAuth coreAuth, GitHubClient client, SymmetricAlgorithm encAlgo, ModRepoContext context) { githubAuthSettings = ghAuth; coreAuthSettings = coreAuth; this.client = client; stateEncAlgo = encAlgo; repoContext = context; UpdateCurrentRandomData(); }
public override bool Execute() { GitHubAuth auth = new GitHubAuth(GitHubPassword); GitHubWriteVersionUpdater repoUpdater = new GitHubWriteVersionUpdater(auth); repoUpdater.UpdateBuildInfoAsync( Name, Version, VersionsRepoPath).Wait(); return(true); }
public override bool Execute() { string versionsRepoPath = $"build-info/dotnet/cli/{BranchName}"; GitHubAuth auth = new GitHubAuth(GitHubPassword); GitHubVersionsRepoUpdater repoUpdater = new GitHubVersionsRepoUpdater(auth); repoUpdater.UpdateBuildInfoAsync( Directory.GetFiles(PackagesDirectory, "*.nupkg"), versionsRepoPath).Wait(); return(true); }
public GitHubWriteVersionUpdater(GitHubAuth gitHubAuth, GitHubProject project) { if (gitHubAuth == null) { throw new ArgumentNullException(nameof(gitHubAuth)); } _gitHubAuth = gitHubAuth; if (project == null) { throw new ArgumentNullException(nameof(project)); } _project = project; }
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(); } }
public override bool Execute() { GitHubAuth auth = null; if (!string.IsNullOrEmpty(GitHubAuthToken)) { auth = new GitHubAuth(GitHubAuthToken, GitHubUser); } using (GitHubClient = new GitHubClient(auth)) { Trace.Listeners.MsBuildListenedInvoke(Log, TraceListenedExecute); } return(!Log.HasLoggedErrors); }
public bool ExecuteTask(IVersionsRepoUpdaterFactory versionsRepoUpdaterFactory) { Trace.Listeners.MsBuildListenedInvoke(Log, () => { var gitHubAuth = new GitHubAuth(GitHubAuthToken, GitHubUser, GitHubEmail); var updater = versionsRepoUpdaterFactory.CreateGitHubVersionsRepoUpdater(gitHubAuth, VersionsRepoOwner, VersionsRepo); updater.UpdateBuildInfoAsync( ShippedNuGetPackage.Select(item => item.ItemSpec), VersionsRepoPath) .Wait(); }); return(true); }
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 static Task CreatePullRequest(DependencyUpdateResults updateResults) { string commitMessage = $"Update {s_config.BranchTagPrefix} SDK to {updateResults.UsedBuildInfos.Single().LatestReleaseVersion}"; GitHubAuth gitHubAuth = new GitHubAuth(s_config.Password, s_config.UserName, s_config.Email); PullRequestCreator prCreator = new PullRequestCreator( gitHubAuth, new GitHubProject(s_config.GitHubProject, gitHubAuth.User), new GitHubBranch(s_config.GitHubUpstreamBranch, new GitHubProject(s_config.GitHubProject, s_config.GitHubUpstreamOwner)), s_config.UserName, new SingleBranchNamingStrategy($"UpdateDependencies-{s_config.BranchTagPrefix}") ); return(prCreator.CreateOrUpdateAsync(commitMessage, commitMessage, string.Empty)); }
public override bool Execute() { MsBuildTraceListener[] listeners = Trace.Listeners.AddMsBuildTraceListeners(Log); var gitHubAuth = new GitHubAuth(GitHubAuthToken, GitHubUser, GitHubEmail); var updater = new VersionsRepoUpdater(gitHubAuth, VersionsRepoOwner, VersionsRepo); updater.UpdateBuildInfoAsync( ShippedNuGetPackage.Select(item => item.ItemSpec), VersionsRepoPath) .Wait(); Trace.Listeners.RemoveMsBuildTraceListeners(listeners); return(true); }
public override bool Execute() { GitHubAuth gitHubAuth = null; if (!string.IsNullOrEmpty(GitHubAuthToken)) { gitHubAuth = new GitHubAuth(GitHubAuthToken, GitHubUser, GitHubEmail); } using (var gitHubClient = new GitHubClient(gitHubAuth)) { var client = new BuildManifestClient(gitHubClient); OrchestratedBuildModel manifest = client.FetchManifestAsync( new GitHubProject(VersionsRepo, VersionsRepoOwner), VersionsRepoRef, VersionsRepoPath) .Result; OrchestratedBuild = CreateItem(manifest.Identity); EndpointModel[] orchestratedFeeds = manifest.Endpoints .Where(e => e.IsOrchestratedBlobFeed) .ToArray(); if (orchestratedFeeds.Length != 1) { throw new Exception( "Invalid manifest. Expected 1 orchestrated blob feed, " + $"found {orchestratedFeeds.Length}."); } EndpointModel feed = orchestratedFeeds[0]; IEnumerable <ITaskItem> packageItems = feed.Artifacts.Packages.Select(CreateItem); IEnumerable <ITaskItem> blobItems = feed.Artifacts.Blobs.Select(CreateItem); OrchestratedBlobFeed = new[] { new TaskItem("Endpoint", feed.Attributes) }; OrchestratedBlobFeedArtifacts = packageItems.Concat(blobItems).ToArray(); IEnumerable <ITaskItem> buildItems = manifest.Builds.Select(CreateItem); OrchestratedBuildConstituents = buildItems.ToArray(); } return(!Log.HasLoggedErrors); }
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() { if (string.IsNullOrEmpty(CommitMessage)) { string semaphores = string.Join(", ", SemaphoreNames); string identity = OrchestratedIdentitySummary ?? VersionsRepoPath; CommitMessage = $"Update {identity}: {semaphores}"; } var gitHubAuth = new GitHubAuth(GitHubAuthToken, GitHubUser, GitHubEmail); using (var gitHubClient = new GitHubClient(gitHubAuth)) { var client = new BuildManifestClient(gitHubClient); PushChangeAsync(client).Wait(); } return(!Log.HasLoggedErrors); }
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); }
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(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 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); } } }
public VstsAdapterClient( GitHubAuth auth, string vstsInstanceName, string apiVersionOverride = null) { Auth = auth; VstsInstanceName = vstsInstanceName; _httpClient = X509Helper.GetHttpClientWithCertRevocation(); _httpClient.DefaultRequestHeaders.Add( "Accept", $"application/json;api-version={apiVersionOverride ?? DefaultVstsApiVersion}"); if (auth?.AuthToken != null) { _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( "Basic", ClientHelpers.ToBase64($":{auth.AuthToken}")); } }
private IGitHubClient CreateClient(out GitHubProject origin) { PullRequestServiceType type; if (!Enum.TryParse(PullRequestServiceType, true, out type)) { string options = string.Join(", ", Enum.GetNames(typeof(PullRequestServiceType))); throw new ArgumentException( $"{nameof(PullRequestServiceType)} '{PullRequestServiceType}' is not valid. " + $"Options are {options}"); } var auth = new GitHubAuth( PullRequestAuthToken, PullRequestUser, PullRequestEmail); switch (type) { case VersionTools.PullRequestServiceType.GitHub: origin = new GitHubProject(ProjectRepoName, PullRequestUser); return(new GitHubClient(auth)); case VersionTools.PullRequestServiceType.Vsts: if (string.IsNullOrEmpty(VstsInstanceName)) { throw new ArgumentException($"{nameof(VstsInstanceName)} is required but not set."); } origin = new GitHubProject(ProjectRepoName, ProjectRepoOwner); return(new VstsAdapterClient(auth, VstsInstanceName, VstsApiVersionOverride)); default: throw new ArgumentOutOfRangeException( nameof(PullRequestServiceType), type, "Enum value invalid."); } }