public static ReleaseAsset Mapped(Octokit.ReleaseAsset asset) { return(new ReleaseAsset { Url = asset.Url, Id = asset.Id, NodeId = asset.NodeId, Name = asset.Name, Label = asset.Label, State = asset.State, ContentType = asset.ContentType, Size = asset.Size, DownloadCount = asset.DownloadCount, CreatedAt = asset.CreatedAt, UpdatedAt = asset.UpdatedAt, BrowserDownloadUrl = asset.BrowserDownloadUrl, Uploader = Author.Mapped(asset.Uploader), }); }
private async Task ProcessAsset(Octokit.ReleaseAsset releaseAsset, string branch, int updateId) { var operatingSystem = Parser.ParseOS(releaseAsset.Name); if (!operatingSystem.HasValue) { return; } var runtime = Parser.ParseRuntime(releaseAsset.Name); var arch = Parser.ParseArchitecture(releaseAsset.Name); var installer = Parser.ParseInstaller(releaseAsset.Name); // Calculate the hash of the zip file. var releaseZip = Path.Combine(_config.DataDirectory, branch.ToString().ToLower(), releaseAsset.Name); string releaseHash; if (!File.Exists(releaseZip)) { Directory.CreateDirectory(Path.GetDirectoryName(releaseZip)); using var fileStream = File.OpenWrite(releaseZip); using var artifactStream = await _httpClient.GetStreamAsync(releaseAsset.BrowserDownloadUrl); await artifactStream.CopyToAsync(fileStream); } using (var stream = File.OpenRead(releaseZip)) using (var sha = SHA256.Create()) { releaseHash = BitConverter.ToString(sha.ComputeHash(stream)).Replace("-", "").ToLower(); } File.Delete(releaseZip); // Add to database. var updateFile = new UpdateFileEntity { UpdateId = updateId, OperatingSystem = operatingSystem.Value, Architecture = arch, Runtime = runtime, Filename = releaseAsset.Name, Url = releaseAsset.BrowserDownloadUrl, Hash = releaseHash, Installer = installer }; await _updateFileService.Insert(updateFile).ConfigureAwait(false); }
/// <summary> /// Constructor /// </summary> /// <param name="client">Octokit object used for interacting with the GitHub REST API</param> /// <param name="repo">Reference to the Octokit object describing the GitHub asset</param> public Asset(GitHubClient client, Octokit.ReleaseAsset asset) { _client = client; _asset = asset; }
async Task<string> DownloadUpdateAsync(ReleaseAsset asset) { var url = asset.BrowserDownloadUrl; var data = await fileDownloader.DownloadBytesAsync(url); var localFilePath = fileManager.WriteBytesToTemporaryFile(asset.Name, data); return localFilePath; }
async Task UpdateFromAssetAsync(ReleaseAsset asset) { var localFilePath = await DownloadUpdateAsync(asset); var temporaryDirectory = ExtractUpdate(localFilePath); StartUpdate(temporaryDirectory); }
async Task UpdateFromAssetAsync(ReleaseAsset asset) { var localFilePath = await DownloadUpdateToDiskAsync(asset); processManager.LaunchFile( localFilePath, "update"); }
private ITaskItem TaskItemFor(Release release, ReleaseAsset asset) { var item = new TaskItem(); // I don't think there's a way, via the API, to get something like this: // https://github.com/git-tfs/msbuild-tasks/releases/download/v0.0.9/GitTfsTasks-0.0.9.zip item.ItemSpec = "https://github.com/" + Repository + "/releases/download/" + TagName + "/" + asset.Name; item.MaybeSetMetadata("ContentType", asset.ContentType); item.MaybeSetMetadata("Id", asset.Id.ToString()); item.MaybeSetMetadata("Label", asset.Label); item.MaybeSetMetadata("Name", asset.Name); item.MaybeSetMetadata("State", asset.State); return item; }