Пример #1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            if (!File.Exists(Filename))
            {
                throw new FileNotFoundException(Filename);
            }

            Release release = GitHub.Release.Get(Owner, Repository, ReleaseId).Result;

            if (release == null)
            {
                WriteError(new KeyNotFoundException(ReleaseId.ToString()), ErrorCategory.ObjectNotFound);
                return;
            }

            var fileStream = File.OpenRead(Filename);
            var releaseAssetUpload = new ReleaseAssetUpload
            {
                ContentType = ContentType,
                FileName = Path.GetFileName(Filename),
                RawData = fileStream
            };

            WriteObject(GitHub.Release.UploadAsset(release, releaseAssetUpload).Result);
        }
Пример #2
0
    async Task PublishRelease(string owner, string repo, string token, string tag, string description, string artifactPath, bool prerelease)
    {
        var tokenAuth    = new Octokit.Credentials(token);
        var githubClient = new Octokit.GitHubClient(new Octokit.ProductHeaderValue("vc-build"))
        {
            Credentials = tokenAuth
        };
        var newRelease = new Octokit.NewRelease(tag)
        {
            Name       = tag,
            Prerelease = prerelease,
            Draft      = false,
            Body       = description
        };
        var release = await githubClient.Repository.Release.Create(owner, repo, newRelease);

        using (var artifactStream = File.OpenRead(artifactPath))
        {
            var assetUpload = new Octokit.ReleaseAssetUpload()
            {
                FileName    = Path.GetFileName(artifactPath),
                ContentType = "application/zip",
                RawData     = artifactStream
            };
            var asset = await githubClient.Repository.Release.UploadAsset(release, assetUpload);
        }
    }
Пример #3
0
        public Task <ReleaseAsset> UploadAsset(Release release, ReleaseAssetUpload data, CancellationToken cancellationToken = default)
        {
            Ensure.ArgumentNotNull(release, nameof(release));
            Ensure.ArgumentNotNull(data, nameof(data));

            var endpoint = release.UploadUrl.ExpandUriTemplate(new { name = data.FileName });

            if (data.Timeout.HasValue)
            {
                return(ApiConnection.Post <ReleaseAsset>(
                           endpoint,
                           data.RawData,
                           AcceptHeaders.StableVersion,
                           data.ContentType,
                           data.Timeout.GetValueOrDefault(),
                           cancellationToken));
            }

            return(ApiConnection.Post <ReleaseAsset>(
                       endpoint,
                       data.RawData,
                       AcceptHeaders.StableVersion,
                       data.ContentType,
                       cancellationToken));
        }
Пример #4
0
        /// <summary>
        /// Uploads a <see cref="ReleaseAsset"/> for the specified release.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/releases/#upload-a-release-asset">API documentation</a> for more information.
        /// </remarks>
        /// <param name="release">The <see cref="Release"/> to attach the uploaded asset to.</param>
        /// <param name="data">Description of the asset with its data.</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>The created <see cref="ReleaseAsset"/>.</returns>
        public Task<ReleaseAsset> UploadAsset(Release release, ReleaseAssetUpload data)
        {
            Ensure.ArgumentNotNull(release, "release");
            Ensure.ArgumentNotNull(data, "data");

            var endpoint = release.UploadUrl.ExpandUriTemplate(new {name = data.FileName});
            return ApiConnection.Post<ReleaseAsset>(
                endpoint,
                data.RawData,
                "application/vnd.github.manifold-preview",
                data.ContentType);
        }
Пример #5
0
        /// <summary>
        /// Uploads a <see cref="ReleaseAsset"/> for the specified release.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/releases/#upload-a-release-asset">API documentation</a> for more information.
        /// </remarks>
        /// <param name="release">The <see cref="Release"/> to attach the uploaded asset to</param>
        /// <param name="data">Description of the asset with its data</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>The created <see cref="ReleaseAsset"/>.</returns>
        public Task <ReleaseAsset> UploadAsset(Release release, ReleaseAssetUpload data)
        {
            Ensure.ArgumentNotNull(release, "release");
            Ensure.ArgumentNotNull(data, "data");

            var endpoint = release.UploadUrl.ExpandUriTemplate(new { name = data.FileName });

            return(ApiConnection.Post <ReleaseAsset>(
                       endpoint,
                       data.RawData,
                       "application/vnd.github.v3",
                       data.ContentType));
        }
        public async Task CanDownloadBinaryAsset()
        {
            var releaseWithNoUpdate = new NewRelease("0.1") { Draft = true };
            var release = await _releaseClient.Create(_context.RepositoryOwner, _context.RepositoryName, releaseWithNoUpdate);

            var stream = Helper.LoadFixture("hello-world.zip");

            var newAsset = new ReleaseAssetUpload("hello-world.zip"
                , "application/octet-stream"
                , stream
                , null);

            var result = await _releaseClient.UploadAsset(release, newAsset);

            Assert.True(result.Id > 0);

            var asset = await _releaseClient.GetAsset(_context.RepositoryOwner, _context.RepositoryName, result.Id);

            Assert.Equal(result.Id, asset.Id);

            var response = await _github.Connection.Get<object>(new Uri(asset.Url), new Dictionary<string, string>(), "application/octet-stream");

            var textContent = string.Empty;

            using (var zipstream = new MemoryStream((byte[])response.Body))
            using (var archive = new ZipArchive(zipstream))
            {
                var enttry = archive.Entries[0];
                var data = new byte[enttry.Length];
                await enttry.Open().ReadAsync(data, 0, data.Length);
                textContent = Encoding.ASCII.GetString(data);
            }

            Assert.Contains("This is a plain text file.", textContent);
        }
        public async Task CanDownloadAnAsset()
        {
            var releaseWithNoUpdate = new NewRelease("0.1") { Draft = true };
            var release = await _releaseClient.Create(_context.RepositoryOwner, _context.RepositoryName, releaseWithNoUpdate);

            var stream = Helper.LoadFixture("hello-world.txt");

            var newAsset = new ReleaseAssetUpload("hello-world.txt", "text/plain", stream, null);

            var result = await _releaseClient.UploadAsset(release, newAsset);

            Assert.True(result.Id > 0);

            var asset = await _releaseClient.GetAsset(_context.RepositoryOwner, _context.RepositoryName, result.Id);

            Assert.Equal(result.Id, asset.Id);

            var response = await _github.Connection.Get<object>(new Uri(asset.Url), new Dictionary<string, string>(), "application/octet-stream");

            Assert.Contains("This is a plain text file.", Encoding.ASCII.GetString((byte[])response.Body));
        }
        public async Task CanUploadAndRetrieveAnAsset()
        {
            var releaseWithNoUpdate = new NewRelease("0.1") { Draft = true };
            var release = await _releaseClient.Create(_context.RepositoryOwner, _context.RepositoryName, releaseWithNoUpdate);

            var stream = Helper.LoadFixture("hello-world.txt");

            var newAsset = new ReleaseAssetUpload("hello-world.txt", "text/plain", stream, null);

            var result = await _releaseClient.UploadAsset(release, newAsset);

            Assert.True(result.Id > 0);

            var assets = await _releaseClient.GetAllAssets(_context.RepositoryOwner, _context.RepositoryName, release.Id);

            Assert.Equal(1, assets.Count);
            var asset = assets[0];
            Assert.Equal(result.Id, asset.Id);
            Assert.NotNull(asset.Url);
            Assert.NotNull(asset.BrowserDownloadUrl);
        }
Пример #9
0
        private static async Task CreateRelease(GitHubClient github, string owner, string repository, string milestone, string targetCommitish, string asset)
        {
            var releaseNotesBuilder = new ReleaseNotesBuilder(new DefaultGitHubClient(github, owner, repository), owner, repository, milestone);

            var result = await releaseNotesBuilder.BuildReleaseNotes();

            var releaseUpdate = new ReleaseUpdate(milestone)
            {
                Draft = true,
                Body = result,
                Name = milestone
            };
            if (!string.IsNullOrEmpty(targetCommitish))
                releaseUpdate.TargetCommitish = targetCommitish;

            var release = await github.Release.Create(owner, repository, releaseUpdate);

            if (File.Exists(asset))
            {
                var upload = new ReleaseAssetUpload { FileName = Path.GetFileName(asset), ContentType = "application/octet-stream", RawData = File.Open(asset, FileMode.Open) };

                await github.Release.UploadAsset(release, upload);
            }
        }
Пример #10
0
        public async Task CanDownloadAnAsset()
        {
            var releaseWithNoUpdate = new ReleaseUpdate("0.1") { Draft = true };
            var release = await _releaseClient.Create(_repositoryOwner, _repositoryName, releaseWithNoUpdate);

            var stream = Helper.LoadFixture("hello-world.txt");

            var newAsset = new ReleaseAssetUpload
            {
                ContentType = "text/plain",
                FileName = "hello-world.txt",
                RawData = stream
            };

            var result = await _releaseClient.UploadAsset(release, newAsset);

            Assert.True(result.Id > 0);

            var asset = await _releaseClient.GetAsset(_repositoryOwner, _repositoryName, result.Id);

            Assert.Equal(result.Id, asset.Id);

            var response = await _github.Connection.Get<object>(new Uri(asset.Url), new Dictionary<string, string>(), "application/octet-stream");

            Assert.Equal("This is a plain text file.", response.Body);
        }
Пример #11
0
 static Task UploadFileToGithub(Release githubRelease, string filePath, string filePublishName, string contentType)
 {
     var buildZipAssetWindows = new ReleaseAssetUpload()
     {
         FileName = filePublishName,
         ContentType = contentType,
         RawData = File.OpenRead(filePath)
     };
     return github.Release.UploadAsset(githubRelease, buildZipAssetWindows);
 }
Пример #12
0
        private static async Task AddAssets(GitHubClient github, IList<string> assets, Release release)
        {
            if (assets != null)
            {
                foreach (var asset in assets)
                {
                    if (!File.Exists(asset))
                    {
                        continue;
                    }

                    var upload = new ReleaseAssetUpload
                    {
                        FileName = Path.GetFileName(asset),
                        ContentType = "application/octet-stream",
                        RawData = File.Open(asset, FileMode.Open)
                    };

                    await github.Release.UploadAsset(release, upload);
                }
            }
        }
Пример #13
0
        public static void Publish(string projectInfoFilename, string releaseBasePath, string releaseVersion, string userFriendlyDate, string isoDate, string user, string pw)
        {
            if (projectInfoFilename == null) {
                throw new ArgumentNullException("projectInfoFilename");
            }
            if (releaseVersion == null) {
                throw new ArgumentNullException("releaseVersion");
            }
            if (userFriendlyDate == null) {
                throw new ArgumentNullException("userFriendlyDate");
            }
            if (isoDate == null) {
                throw new ArgumentNullException("isoDate");
            }
            if (user == null) {
                throw new ArgumentNullException("user");
            }
            if (pw == null) {
                throw new ArgumentNullException("pw");
            }

            var nsMap = new XmlNamespaceManager(new NameTable());
            nsMap.AddNamespace("local", "http://local/");

            var doc = new XmlDocument();
            doc.Load(projectInfoFilename);
            string projectName;
            var node = doc.DocumentElement.SelectSingleNode("/local:project/local:id[@service = 'Github']/text()", nsMap);
            if (node != null) {
                projectName = node.Value;
            } else {
                projectName = doc.DocumentElement.SelectSingleNode("/local:project/local:id/text()", nsMap).Value;
            }

            var version = versionStructure.Match(releaseVersion);
            if (!version.Success) {
                throw new ArgumentException(string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                          "The release version \"{0}\" does not match the format requirements.",
                                                          releaseVersion));
            }

            bool isPrerelease = (version.Groups.Count > 2) && !string.IsNullOrWhiteSpace(version.Groups[2].Value);
            string releaseName = CreateReleaseName(version, isPrerelease);
            //string status = DetermineStatus(version, isPrerelease);
            string releaseDesc = CompileReleaseNotes(doc, nsMap);

            var github = new GitHubClient(new ProductHeaderValue(typeof(Worker).Assembly.FullName));
            github.Credentials = new Credentials(user, pw);
            var releaseClient = github.Release;

            var releaseData = new NewRelease(releaseName);
            releaseData.Body = releaseDesc;
            releaseData.Prerelease = isPrerelease;
            releaseData.Name = releaseName;

            var releaseTask = github.Release.Create(user, projectName, releaseData);
            releaseTask.RunSynchronously();
            var release = releaseTask.Result;

            var files = ExtractReleaseFiles(doc, nsMap, releaseBasePath, releaseVersion, userFriendlyDate).ToArray();
            foreach (ReleaseFileInfo f in files) {
                var asset = new ReleaseAssetUpload(f.DestName, f.MimeType, f.Data, null);
                var uploadTask = github.Release.UploadAsset(release, asset);
                uploadTask.RunSynchronously();
            }
        }
Пример #14
0
        private static async Task AttachToRelease(GitHubClient github, string owner, string repository, string milestone, string asset)
        {
            if (!File.Exists(asset))
                return;

            var releases = await github.Release.GetAll(owner, repository);
            var release = releases.FirstOrDefault(r => r.Name == milestone);
            if (release == null)
                return;

            var upload = new ReleaseAssetUpload { FileName = Path.GetFileName(asset), ContentType = "application/octet-stream", RawData = File.Open(asset, FileMode.Open) };

            await github.Release.UploadAsset(release, upload);
        }
Пример #15
0
        public async Task CanUploadAndRetrieveAnAsset()
        {
            var releaseWithNoUpdate = new ReleaseUpdate("0.1") { Draft = true };
            var release = await _releaseClient.Create(_repositoryOwner, _repositoryName, releaseWithNoUpdate);

            var stream = Helper.LoadFixture("hello-world.txt");

            var newAsset = new ReleaseAssetUpload
            {
                ContentType = "text/plain", FileName = "hello-world.txt", RawData = stream
            };

            var result = await _releaseClient.UploadAsset(release, newAsset);

            Assert.True(result.Id > 0);

            var assets = await _releaseClient.GetAssets(_repositoryOwner, _repositoryName, release.Id);

            Assert.Equal(1, assets.Count);
            var asset = assets[0];
            Assert.Equal(result.Id, asset.Id);
            Assert.NotNull(asset.Url);
        }
Пример #16
0
        public async Task CanEditAnAssetLabel()
        {
            var releaseWithNoUpdate = new ReleaseUpdate("0.1") { Draft = true };
            var release = await _releaseClient.Create(_repositoryOwner, _repositoryName, releaseWithNoUpdate);

            var stream = Helper.LoadFixture("hello-world.txt");

            var newAsset = new ReleaseAssetUpload
            {
                ContentType = "text/plain",
                FileName = "hello-world.txt",
                RawData = stream
            };

            var result = await _releaseClient.UploadAsset(release, newAsset);
            var asset = await _releaseClient.GetAsset(_repositoryOwner, _repositoryName, result.Id);

            var updateAsset = asset.ToUpdate();
            updateAsset.Label = "some other thing";

            var updatedAsset = await _releaseClient.EditAsset(_repositoryOwner, _repositoryName, result.Id, updateAsset);

            Assert.Equal("some other thing", updatedAsset.Label);
        }
Пример #17
0
        public async Task CanEditAnAssetLabelWithRepositoryId()
        {
            var releaseWithNoUpdate = new NewRelease("0.1") { Draft = true };
            var release = await _releaseClient.Create(_context.Repository.Id, releaseWithNoUpdate);

            var stream = Helper.LoadFixture("hello-world.txt");

            var newAsset = new ReleaseAssetUpload("hello-world.txt", "text/plain", stream, null);

            var result = await _releaseClient.UploadAsset(release, newAsset);
            var asset = await _releaseClient.GetAsset(_context.Repository.Id, result.Id);

            var updateAsset = asset.ToUpdate();
            updateAsset.Label = "some other thing";

            var updatedAsset = await _releaseClient.EditAsset(_context.Repository.Id, result.Id, updateAsset);

            Assert.Equal("some other thing", updatedAsset.Label);
        }
Пример #18
0
        /// <summary>
        /// Uploads a <see cref="ReleaseAsset"/> for the specified release.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/releases/#upload-a-release-asset">API documentation</a> for more information.
        /// </remarks>
        /// <param name="release">The <see cref="Release"/> to attach the uploaded asset to</param>
        /// <param name="data">Description of the asset with its data</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>The created <see cref="ReleaseAsset"/>.</returns>
        public Task<ReleaseAsset> UploadAsset(Release release, ReleaseAssetUpload data)
        {
            Ensure.ArgumentNotNull(release, "release");
            Ensure.ArgumentNotNull(data, "data");

            var endpoint = release.UploadUrl.ExpandUriTemplate(new { name = data.FileName });

            if (data.Timeout.HasValue)
            {
                return ApiConnection.Post<ReleaseAsset>(
                    endpoint,
                    data.RawData,
                    "application/vnd.github.v3",
                    data.ContentType,
                    data.Timeout.GetValueOrDefault());
            }

            return ApiConnection.Post<ReleaseAsset>(
                endpoint,
                data.RawData,
                "application/vnd.github.v3",
                data.ContentType);
        }
Пример #19
0
        public async Task CanDeleteAssetWithRepositoryId()
        {
            var releaseWithNoUpdate = new NewRelease("0.1") { Draft = true };
            var release = await _releaseClient.Create(_context.Repository.Id, releaseWithNoUpdate);

            var stream = Helper.LoadFixture("hello-world.txt");

            var newAsset = new ReleaseAssetUpload("hello-world.txt", "text/plain", stream, null);

            var result = await _releaseClient.UploadAsset(release, newAsset);
            var asset = await _releaseClient.GetAsset(_context.Repository.Id, result.Id);

            Assert.NotNull(asset);

            Assert.ThrowsAsync<NotFoundException>(async () => await _releaseClient.DeleteAsset(_context.Repository.Id, result.Id));
        }
Пример #20
0
        static async Task UploadRelease()
        {
            // get last master commit to tag
            /*var masterBranch = await github.Repository.GetBranch(repoOwner, repoName, "master");
            var lastCommit = masterBranch.Commit.Sha;

            // create tag
            var tagName = "v" + localVersion.ToString();
            var tag = new NewTag
            {
                Message = "Tagging a new release of Jackett",
                Tag = tagName,
                Object = lastCommit,
                Type = TaggedType.Commit,
                Tagger = new SignatureResponse("DistributionBot", "*****@*****.**", DateTime.UtcNow)
            };
            var tagResult = await github.GitDatabase.Tag.Create(repoOwner, repoName, tag);*/

            // create release entry
            var newRelease = new NewRelease("v" + localVersion.ToString());
            newRelease.Name = "Beta Release";
            newRelease.Body = "";
            newRelease.Draft = true;
            newRelease.Prerelease = false;

            var releaseResult = await github.Release.Create(repoOwner, repoName, newRelease);


            var buildZipAsset = new ReleaseAssetUpload()
            {
                FileName = string.Format("Jackett.v{0}.zip", localVersion),
                ContentType = "application/zip",
                RawData = File.OpenRead(buildZipFile)
            };
            var buildZipAssetResult = await github.Release.UploadAsset(releaseResult, buildZipAsset);

            var installFileAsset = new ReleaseAssetUpload()
            {
                FileName = string.Format("Jackett.v{0}.Windows.Installer.exe", localVersion),
                ContentType = "application/octet-stream",
                RawData = File.OpenRead(installFile)
            };
            var installFileAssetResult = await github.Release.UploadAsset(releaseResult, installFileAsset);

        }
Пример #21
0
 private ReleaseAssetUpload BuildAssetUpload(ITaskItem item)
 {
     var data = new ReleaseAssetUpload();
     data.ContentType = item.GetMetadata("ContentType");
     if (data.ContentType == null) data.ContentType = "application/octet-stream";
     data.FileName = Path.GetFileName(item.ItemSpec);
     data.RawData = File.OpenRead(item.ItemSpec);
     return data;
 }