Пример #1
0
        /// <summary>
        /// Edits an existing <see cref="Release"/> for the specified repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/releases/#edit-a-release">API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="id">The id of the release</param>
        /// <param name="data">A description of the release to edit</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        public Task<Release> Edit(long repositoryId, int id, ReleaseUpdate data)
        {
            Ensure.ArgumentNotNull(data, "data");

            var endpoint = ApiUrls.Releases(repositoryId, id);
            return ApiConnection.Patch<Release>(endpoint, data);
        }
Пример #2
0
        /// <summary>
        /// Edits an existing <see cref="Release"/> for the specified repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/releases/#edit-a-release">API documentation</a> for more information.
        /// </remarks>
        /// <param name="owner">The repository's owner</param>
        /// <param name="name">The repository's name</param>
        /// <param name="id">The id of the release</param>
        /// <param name="data">A description of the release to edit</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        public Task<Release> Edit(string owner, string name, int id, ReleaseUpdate data)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(data, "data");

            var endpoint = ApiUrls.Releases(owner, name, id);
            return ApiConnection.Patch<Release>(endpoint, data);
        }
Пример #3
0
        /// <summary>
        /// Creates a new <see cref="Release"/> for the specified repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/releases/#create-a-release">API documentation</a> for more information.
        /// </remarks>
        /// <param name="owner">The repository's owner.</param>
        /// <param name="name">The repository's name.</param>
        /// <param name="data">A description of the release to create.</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>The created <see cref="Release"/>.</returns>
        public Task<Release> CreateRelease(string owner, string name, ReleaseUpdate data)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "repository");
            Ensure.ArgumentNotNull(data, "data");

            var endpoint = ApiUrls.Releases(owner, name);
            return ApiConnection.Post<Release>(endpoint, data, "application/vnd.github.manifold-preview");
        }
Пример #4
0
        /// <summary>
        /// Creates a new <see cref="Release"/> for the specified repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/releases/#create-a-release">API documentation</a> for more information.
        /// </remarks>
        /// <param name="owner">The repository's owner</param>
        /// <param name="name">The repository's name</param>
        /// <param name="data">A description of the release to create</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>The created <see cref="Release"/>.</returns>
        public Task <Release> CreateRelease(string owner, string name, ReleaseUpdate data)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "repository");
            Ensure.ArgumentNotNull(data, "data");

            var endpoint = ApiUrls.Releases(owner, name);

            return(ApiConnection.Post <Release>(endpoint, data, "application/vnd.github.v3"));
        }
Пример #5
0
		private ReleaseUpdate BuildReleaseData()
		{
			var release = new ReleaseUpdate(_tagName);
			if (_releaseNotesFile != null)
			{
				release.Body = File.ReadAllText(_releaseNotesFile);
			}

			return release;
		}
Пример #6
0
        public async Task ReturnsReleasesWithNullPublishDate()
        {
            // create a release without a publish date
            var releaseWithNoUpdate = new ReleaseUpdate("0.1") { Draft = true };
            await _releaseClient.Create(_repositoryOwner, _repositoryName, releaseWithNoUpdate);

            var releases = await _releaseClient.GetAll(_repositoryOwner, _repositoryName);

            Assert.True(releases.Count == 1);
            Assert.False(releases.First().PublishedAt.HasValue);
        }
Пример #7
0
        public async Task CanChangeBodyOfRelease()
        {
            var releaseWithNoUpdate = new ReleaseUpdate("0.1") { Draft = true };
            var release = await _releaseClient.Create(_repositoryOwner, _repositoryName, releaseWithNoUpdate);

            var editRelease = release.ToUpdate();
            editRelease.Body = "**This is an updated release";
            editRelease.Draft = false;

            var updatedRelease = await _releaseClient.Edit(_repositoryOwner, _repositoryName, release.Id, editRelease);

            Assert.Equal(release.Id, updatedRelease.Id);
            Assert.False(updatedRelease.Draft);
            Assert.Equal("**This is an updated release", updatedRelease.Body);
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            var releaseUpdate = new ReleaseUpdate();

            bool isDirty = false;

            if (!string.IsNullOrEmpty(Title))
            {
                releaseUpdate.Name = Title;
                isDirty = true;
            }

            if (!string.IsNullOrEmpty(Description))
            {
                releaseUpdate.Body = Description;
                isDirty = true;
            }

            if (IsPrelease.HasValue)
            {
                releaseUpdate.Prerelease = IsPrelease.Value;
                isDirty = true;
            }

            if (IsDraft.HasValue)
            {
                releaseUpdate.Draft = IsDraft.Value;
                isDirty = true;
            }

            if (isDirty)
            {
                var result = GitHub.Release.Edit(Owner, Repository, ReleaseId, releaseUpdate).Result;
                WriteObject(result);
                return;
            }

            WriteVerbose("Nothing to update.");
        }
        public async Task CanUploadAndRetrieveAnAsset()
        {
            var releaseWithNoUpdate = new ReleaseUpdate("0.1") { Draft = true };
            var release = await _releaseClient.CreateRelease(_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);
        }
Пример #10
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);
            }
        }
Пример #11
0
        /// <summary>
        /// Edits an existing <see cref="Release"/> for the specified repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/releases/#edit-a-release">API documentation</a> for more information.
        /// </remarks>
        /// <param name="owner">The repository's owner</param>
        /// <param name="name">The repository's name</param>
        /// <param name="id">The id of the release</param>
        /// <param name="data">A description of the release to edit</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>The updated <see cref="Release"/>.</returns>
        public Task<Release> Edit(string owner, string name, int id, ReleaseUpdate data)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(data, "data");

            var endpoint = ApiUrls.Releases(owner, name, id);
            return ApiConnection.Patch<Release>(endpoint, data);
        }
Пример #12
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);
        }
Пример #13
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);
        }
Пример #14
0
        public async Task CanChangeCommitIshOfRelease()
        {
            var releaseWithNoUpdate = new ReleaseUpdate("0.1") { Draft = true };
            var release = await _releaseClient.Create(_repositoryOwner, _repositoryName, releaseWithNoUpdate);

            Assert.Equal("master", release.TargetCommitish);

            var newHead = await github.CreateTheWorld(_repository);

            var editRelease = release.ToUpdate();
            editRelease.Draft = false;
            editRelease.TargetCommitish = newHead.Object.Sha;

            var updatedRelease = await _releaseClient.Edit(_repositoryOwner, _repositoryName, release.Id, editRelease);

            Assert.Equal(release.Id, updatedRelease.Id);
            Assert.False(updatedRelease.Draft);
            Assert.Equal(newHead.Object.Sha, updatedRelease.TargetCommitish);
        }
Пример #15
0
        public void CreateRelease()
        {
            if(string.IsNullOrWhiteSpace(Settings.TagName))
                throw new ArgumentException("Must provide a tagname!");

            if (string.IsNullOrWhiteSpace(Settings.RepositoryName))
                throw new ArgumentException("Must provide a repository name!");

            if (string.IsNullOrWhiteSpace(Settings.ReleaseName))
                throw new ArgumentException("Must provide a release name!");

            if (string.IsNullOrWhiteSpace(Settings.Owner))
                throw new ArgumentException("Must provide an owner!");

            var releaseData = new ReleaseUpdate(Settings.TagName)
            {
                Body = Settings.Body,
                Prerelease = Settings.Prerealease,
                Draft = Settings.Draft,
                Name = Settings.ReleaseName,
                TargetCommitish = Settings.TargetCommitish
            };

            var release = 
                _releasesClient.Create(Settings.Owner, Settings.RepositoryName, releaseData).Result;


            if (FileSettings.FilePath != null)
            {
                _releasesClient.UploadAsset(release, new ReleaseAssetUpload
                {
                    FileName = FileSettings.FileName,
                    ContentType = FileSettings.ContentType,
                    RawData = _fileSystem
                                .GetFile(FileSettings.FilePath)
                                .Open(FileMode.Open, FileAccess.Read, FileShare.None)
                }).Wait();
            }
        }
        public void PublishRelease(string releaseNotesOutput)
        {
            string organisation;
            string repository;
            GetRepository(arguments, out organisation, out repository);

            var releaseUpdate = new ReleaseUpdate(arguments.Version)
            {
                Name = arguments.Version,
                Body = releaseNotesOutput
            };
            var release = gitHubClientFactory().Release.CreateRelease(organisation, repository, releaseUpdate);
            release.Wait();
        }
Пример #17
0
        /// <summary>
        /// Edits an existing <see cref="Release"/> for the specified repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/releases/#edit-a-release">API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The Id of the repository</param>
        /// <param name="id">The id of the release</param>
        /// <param name="data">A description of the release to edit</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        public Task<Release> Edit(int repositoryId, int id, ReleaseUpdate data)
        {
            Ensure.ArgumentNotNull(data, "data");

            var endpoint = ApiUrls.Releases(repositoryId, id);
            return ApiConnection.Patch<Release>(endpoint, data);
        }
Пример #18
0
        private static ReleaseUpdate CreateReleaseUpdate(string name, string body, bool prerelease, string targetCommitish)
        {
            var releaseUpdate = new ReleaseUpdate(name)
            {
                Draft = true,
                Body = body,
                Name = name,
                Prerelease = prerelease
            };

            if (!string.IsNullOrEmpty(targetCommitish))
            {
                releaseUpdate.TargetCommitish = targetCommitish;
            }

            return releaseUpdate;
        }
Пример #19
0
        private static async Task PublishRelease(GitHubClient github, string owner, string repository, string tagName)
        {
            var releases = await github.Release.GetAll(owner, repository);
            var release = releases.FirstOrDefault(r => r.TagName == tagName);

            if (release == null)
            {
                return;
            }

            var releaseUpdate = new ReleaseUpdate { TagName = tagName, Draft = false };

            await github.Release.Edit(owner, repository, release.Id, releaseUpdate);
        }