예제 #1
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);
        }
    }
예제 #2
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="repositoryId">The Id of the repository</param>
        /// <param name="data">A description of the release to create</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        public Task <Release> Create(long repositoryId, NewRelease data)
        {
            Ensure.ArgumentNotNull(data, nameof(data));

            var endpoint = ApiUrls.Releases(repositoryId);

            return(ApiConnection.Post <Release>(endpoint, data, AcceptHeaders.StableVersion));
        }
예제 #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> Create(string owner, string name, NewRelease 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");
        }
예제 #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>
        public Task<Release> Create(string owner, string name, NewRelease data)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(data, "data");

            var endpoint = ApiUrls.Releases(owner, name);
            return ApiConnection.Post<Release>(endpoint, data, AcceptHeaders.StableVersion);
        }
        /// <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> Create(string owner, string name, NewRelease 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, AcceptHeaders.StableVersion);
        }
예제 #6
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> Create(string owner, string name, NewRelease 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"));
        }
예제 #7
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);

        }
예제 #8
0
        private static NewRelease CreateNewRelease(string name, string body, bool prerelease, string targetCommitish)
        {
            var newRelease = new NewRelease(name)
            {
                Draft = true,
                Body = body,
                Name = name,
                Prerelease = prerelease
            };

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

            return newRelease;
        }
예제 #9
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="repositoryId">The Id of the repository</param>
        /// <param name="data">A description of the release to create</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        public Task<Release> Create(int repositoryId, NewRelease data)
        {
            Ensure.ArgumentNotNull(data, "data");

            var endpoint = ApiUrls.Releases(repositoryId);
            return ApiConnection.Post<Release>(endpoint, data, AcceptHeaders.StableVersion);
        }
예제 #10
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();
            }
        }