Esempio n. 1
0
        public static async Task PublishRelease(GitHubReleaseSettings settings)
        {
            var releaseTag       = settings.Tag;
            var client           = GetAuthenticatedClient(settings.Token);
            var existingReleases = await client.Repository.Release.GetAll(settings.RepositoryOwner, settings.RepositoryName);

            if (existingReleases.Any(r => r.TagName == releaseTag))
            {
                // Release already present
                return;
            }

            var newRelease = new NewRelease(releaseTag)
            {
                TargetCommitish = settings.CommitSha,
                Name            = releaseTag,
                Body            = settings.ReleaseNotes,
                Draft           = true,
                Prerelease      = settings.Prerelease ?? false
            };
            var releaseCreationResult = await client.Repository.Release.Create(settings.RepositoryOwner, settings.RepositoryName, newRelease);

            var createdRelease = await client.Repository.Release.Get(settings.RepositoryOwner, settings.RepositoryName, releaseCreationResult.Id);

            if (settings.ArtifactPaths != null)
            {
                foreach (var artifactPath in settings.ArtifactPaths)
                {
                    using (var artifactStream = File.OpenRead(artifactPath))
                    {
                        var fileName    = Path.GetFileName(artifactPath);
                        var assetUpload = new ReleaseAssetUpload
                        {
                            FileName    = fileName,
                            ContentType = "application/octet-stream",
                            RawData     = artifactStream,
                        };

                        await client.Repository.Release.UploadAsset(createdRelease, assetUpload);
                    }
                }
            }

            var updatedRelease = createdRelease.ToUpdate();

            updatedRelease.Draft = false;
            await client.Repository.Release.Edit(settings.RepositoryOwner, settings.RepositoryName, createdRelease.Id, updatedRelease);
        }
Esempio n. 2
0
 public static GitHubReleaseSettings ResetArtifactPaths(this GitHubReleaseSettings toolSettings)
 {
     toolSettings = toolSettings.NewInstance();
     toolSettings.ArtifactPaths = null;
     return(toolSettings);
 }
Esempio n. 3
0
 public static GitHubReleaseSettings SetArtifactPaths(this GitHubReleaseSettings toolSettings, string[] artifactPaths)
 {
     toolSettings = toolSettings.NewInstance();
     toolSettings.ArtifactPaths = artifactPaths;
     return(toolSettings);
 }
Esempio n. 4
0
 public static GitHubReleaseSettings TogglePrerelease(this GitHubReleaseSettings toolSettings)
 {
     toolSettings            = toolSettings.NewInstance();
     toolSettings.Prerelease = !toolSettings.Prerelease;
     return(toolSettings);
 }
Esempio n. 5
0
 public static GitHubReleaseSettings ResetPrerelease(this GitHubReleaseSettings toolSettings)
 {
     toolSettings            = toolSettings.NewInstance();
     toolSettings.Prerelease = null;
     return(toolSettings);
 }
Esempio n. 6
0
 public static GitHubReleaseSettings SetPrerelease(this GitHubReleaseSettings toolSettings, bool?prerelease)
 {
     toolSettings            = toolSettings.NewInstance();
     toolSettings.Prerelease = prerelease;
     return(toolSettings);
 }
Esempio n. 7
0
 public static GitHubReleaseSettings ResetRepositoryName(this GitHubReleaseSettings toolSettings)
 {
     toolSettings = toolSettings.NewInstance();
     toolSettings.RepositoryName = null;
     return(toolSettings);
 }
Esempio n. 8
0
 public static GitHubReleaseSettings SetRepositoryName(this GitHubReleaseSettings toolSettings, string repositoryName)
 {
     toolSettings = toolSettings.NewInstance();
     toolSettings.RepositoryName = repositoryName;
     return(toolSettings);
 }
Esempio n. 9
0
 public static GitHubReleaseSettings SetRepositoryOwner(this GitHubReleaseSettings toolSettings, string repositoryOwner)
 {
     toolSettings = toolSettings.NewInstance();
     toolSettings.RepositoryOwner = repositoryOwner;
     return(toolSettings);
 }
Esempio n. 10
0
 public static GitHubReleaseSettings ResetCommitSha(this GitHubReleaseSettings toolSettings)
 {
     toolSettings           = toolSettings.NewInstance();
     toolSettings.CommitSha = null;
     return(toolSettings);
 }
Esempio n. 11
0
 public static GitHubReleaseSettings SetCommitSha(this GitHubReleaseSettings toolSettings, string commitSha)
 {
     toolSettings           = toolSettings.NewInstance();
     toolSettings.CommitSha = commitSha;
     return(toolSettings);
 }
Esempio n. 12
0
 public static GitHubReleaseSettings ResetToken(this GitHubReleaseSettings toolSettings)
 {
     toolSettings       = toolSettings.NewInstance();
     toolSettings.Token = null;
     return(toolSettings);
 }
Esempio n. 13
0
 public static GitHubReleaseSettings SetToken(this GitHubReleaseSettings toolSettings, string token)
 {
     toolSettings       = toolSettings.NewInstance();
     toolSettings.Token = token;
     return(toolSettings);
 }
Esempio n. 14
0
 public static GitHubReleaseSettings SetTag(this GitHubReleaseSettings toolSettings, string tag)
 {
     toolSettings     = toolSettings.NewInstance();
     toolSettings.Tag = tag;
     return(toolSettings);
 }
Esempio n. 15
0
 public static GitHubReleaseSettings ResetReleaseNotes(this GitHubReleaseSettings toolSettings)
 {
     toolSettings = toolSettings.NewInstance();
     toolSettings.ReleaseNotes = null;
     return(toolSettings);
 }
Esempio n. 16
0
 public static GitHubReleaseSettings SetReleaseNotes(this GitHubReleaseSettings toolSettings, string releaseNotes)
 {
     toolSettings = toolSettings.NewInstance();
     toolSettings.ReleaseNotes = releaseNotes;
     return(toolSettings);
 }