I want to create a NukeBuild script that is capable of creating a GitHub Release for me (the CreateReleaseOnGithub Target in the linked build script). However I'm getting a Oktokit.NotFoundException without much else to go on then a URL to the documentation at https://docs.github.com/rest/releases/releases#create-a-release. Part of the stacktrace before it at my own custom build script calling IReleaseClient.Create(string, string, NewReleaseData):
at Octokit.Connection.HandleErrors(IResponse response) in /_/Octokit/Http/Connection.cs:line 780
at Octokit.Connection.RunRequest(IRequest request, CancellationToken cancellationToken, Func`2 preprocessResponseBody) in /_/Octokit/Http/Connection.cs:line 761
at Octokit.Connection.Run[T](IRequest request, CancellationToken cancellationToken, Func`2 preprocessResponseBody) in /_/Octokit/Http/Connection.cs:line 746
at Octokit.ApiConnection.Post[T](Uri uri, Object data, String accepts, String contentType, CancellationToken cancellationToken)
For reference, consider this the code I'm executing within my Target:
var productInformation = new ProductHeaderValue("MyApp-NukeBuildScript");
GitHubTasks.GitHubClient = new GitHubClient(productInformation)
{
Credentials = new Credentials(GitHubUser, GitHubPassword) // My GitHub credentials I provide as command line arguments when executing the script
};
var releaseData = new NewRelease(Version)
{
Prerelease = true,
Draft = true,
Body = "Test"
};
Release release = await GitHubTasks.GitHubClient.Repository.Release
.Create(Repository.GetGitHubOwner(), Repository.GetGitHubName(), releaseData);
where Repository is a field defined within the class as
[GitRepository] readonly GitRepository Repository;
I suspected I might have a typo in the owner or name arguments, and that this would result in not being able to resolve the repository I want to create the Release in. However in an experiment I've executed the following code in a NukeBuild target:
string branchName = await GitHubTasks.GetDefaultBranch(Repository);
which is a piece of Code I pulled from the NukeBuild source code within the GitHubTasks source. And when I run this code, I successfully get the name of my repository.
So it seems that my problem is not related to the Repository.GetGitHubOwner() or Repository.GetGitHubName() arguments being passed to the Create(string, string, ...) method, which leaves me confused.
Why is my piece of code unable to create a Github Release?
I have not been able to make it work with the 'username + password' overload of the
Credentialsclass.I did manage to get the intergration to work with a Github Personal Access Token.
[Secret]as you are dealing with secret data here. From the root of the repository, runnukeon the commandline to build the script and populate thebuild.schema.jsonfile in the.nukefolder..nukefolder, create a parameters file to store the data, for exampleparameters.secrets.json, with file contents{}(an empty json object). Consider putting this file in gitignore, depending on your situation.nuke :secrets secrets. Provide a password (also save this somewhere, as you'll need it to decrypt the file again later!).<Save and Exit>. This now saves the PAT in encrypted format in that secrets file.secretsprofile:nuke --target MyTarget --profile secrets. You'll be asked the password for decrypting the secrets file (from step 5). Provide it, and the script will now create the Release in Github.