From 4e7d27a53c84466562d366256b960433bafc469b Mon Sep 17 00:00:00 2001 From: eric sciple Date: Mon, 15 Jun 2020 13:13:47 -0400 Subject: [PATCH] remove temporary logic when resolving action download info (#550) --- src/Runner.Worker/ActionManager.cs | 67 +-------------------------- src/Test/L0/Worker/ActionManagerL0.cs | 4 +- 2 files changed, 4 insertions(+), 67 deletions(-) diff --git a/src/Runner.Worker/ActionManager.cs b/src/Runner.Worker/ActionManager.cs index 347eb3d0d..b9720610d 100644 --- a/src/Runner.Worker/ActionManager.cs +++ b/src/Runner.Worker/ActionManager.cs @@ -546,56 +546,6 @@ namespace GitHub.Runner.Worker } } - // This implementation is temporary and will be removed when we switch to a REST API call to the service to resolve the download info - private async Task RepoExistsAsync(IExecutionContext executionContext, WebApi.ActionDownloadInfo actionDownloadInfo, string token) - { - var apiUrl = GetApiUrl(executionContext); - var repoUrl = $"{apiUrl}/repos/{actionDownloadInfo.NameWithOwner}"; - for (var attempt = 1; attempt <= 3; attempt++) - { - executionContext.Debug($"Checking whether repo exists: {repoUrl}"); - try - { - using (var httpClientHandler = HostContext.CreateHttpClientHandler()) - using (var httpClient = new HttpClient(httpClientHandler)) - { - httpClient.DefaultRequestHeaders.Authorization = CreateAuthHeader(token); - httpClient.DefaultRequestHeaders.UserAgent.AddRange(HostContext.UserAgents); - using (var response = await httpClient.GetAsync(repoUrl)) - { - if (response.IsSuccessStatusCode) - { - return true; - } - else if (response.StatusCode == HttpStatusCode.NotFound) - { - return false; - } - else - { - // Throw - response.EnsureSuccessStatusCode(); - } - } - } - } - catch (Exception ex) - { - if (attempt < 3) - { - executionContext.Debug($"Failed checking whether repo '{actionDownloadInfo.NameWithOwner}' exists: {ex.Message}"); - } - else - { - executionContext.Error($"Failed checking whether repo '{actionDownloadInfo.NameWithOwner}' exists: {ex.Message}"); - throw; - } - } - } - - return false; // Never reaches here - } - // This implementation is temporary and will be replaced with a REST API call to the service to resolve private async Task> GetDownloadInfoAsync(IExecutionContext executionContext, List actions) { @@ -659,23 +609,10 @@ namespace GitHub.Runner.Worker // Add secret HostContext.SecretMasker.AddValue(actionDownloadInfo.Authentication?.Token); - // Temporary code: Fix token and download URL - if (runnerSettings.IsHostedServer) + // Default auth token + if (string.IsNullOrEmpty(actionDownloadInfo.Authentication?.Token)) { actionDownloadInfo.Authentication = new WebApi.ActionDownloadAuthentication { Token = defaultAccessToken }; - actionDownloadInfo.TarballUrl = actionDownloadInfo.TarballUrl.Replace("", apiUrl); - actionDownloadInfo.ZipballUrl = actionDownloadInfo.ZipballUrl.Replace("", apiUrl); - } - else if (await RepoExistsAsync(executionContext, actionDownloadInfo, defaultAccessToken)) - { - actionDownloadInfo.Authentication = new WebApi.ActionDownloadAuthentication { Token = defaultAccessToken }; - actionDownloadInfo.TarballUrl = actionDownloadInfo.TarballUrl.Replace("", apiUrl); - actionDownloadInfo.ZipballUrl = actionDownloadInfo.ZipballUrl.Replace("", apiUrl); - } - else - { - actionDownloadInfo.TarballUrl = actionDownloadInfo.TarballUrl.Replace("", "https://api.github.com"); - actionDownloadInfo.ZipballUrl = actionDownloadInfo.ZipballUrl.Replace("", "https://api.github.com"); } } diff --git a/src/Test/L0/Worker/ActionManagerL0.cs b/src/Test/L0/Worker/ActionManagerL0.cs index 85851a55a..58ffea5aa 100644 --- a/src/Test/L0/Worker/ActionManagerL0.cs +++ b/src/Test/L0/Worker/ActionManagerL0.cs @@ -3607,8 +3607,8 @@ runs: { NameWithOwner = action.NameWithOwner, Ref = action.Ref, - TarballUrl = $"/repos/{action.NameWithOwner}/tarball/{action.Ref}", - ZipballUrl = $"/repos/{action.NameWithOwner}/zipball/{action.Ref}", + TarballUrl = $"https://api.github.com/repos/{action.NameWithOwner}/tarball/{action.Ref}", + ZipballUrl = $"https://api.github.com/repos/{action.NameWithOwner}/zipball/{action.Ref}", }; } return Task.FromResult(result);