How can I check github releases in c#?
Asked Answered
B

2

5

Something like this.

void UpdateCheck()
{
    if (GithubApi.GetCurrentRelease().Version > CurrentVersion)
}

How can I do this?

I found some API, https://github.com/octokit/octokit.net

but I can't find this function.

Blagoveshchensk answered 5/9, 2014 at 4:39 Comment(0)
L
7

Using Octokit.net you should be able to get started using this example from the documentation:

Get All

To retrieve all releases for a repository:

var releases = client.Release.GetAll("octokit", "octokit.net");
var latest = releases[0];
Console.WriteLine(
    "The latest release is tagged at {0} and is named {1}", 
    latest.TagName, 
    latest.Name); 

Alternatively, you could use the API directly:

List releases for a repository

Information about published releases are available to everyone. Only users with push access will receive listings for draft releases.

GET /repos/:owner/:repo/releases
Luttrell answered 5/9, 2014 at 12:26 Comment(0)
J
5

I updated Chris code with the latest changes to octokit.net as the documentation by Octokit is a bit unclear. The code will not work without the await/async keywords.

using System;
using Octokit;

private async System.Threading.Tasks.Task CheckGitHubNewerVersion()
{
    //Get all releases from GitHub
    //Source: https://octokitnet.readthedocs.io/en/latest/getting-started/
    GitHubClient client = new GitHubClient(new ProductHeaderValue("SomeName"));
    IReadOnlyList<Release> releases = await client.Repository.Release.GetAll("Username", "Repository");
    
    //Setup the versions
    Version latestGitHubVersion = new Version(releases[0].TagName);
    Version localVersion = new Version("X.X.X"); //Replace this with your local version. 
                                                 //Only tested with numeric values.
    
    //Compare the Versions
    //Source: https://mcmap.net/q/143549/-compare-version-numbers-without-using-split-function
    int versionComparison = localVersion.CompareTo(latestGitHubVersion);
    if (versionComparison < 0)
    {
        //The version on GitHub is more up to date than this local release.
    }
    else if (versionComparison > 0)
    {
        //This local version is greater than the release version on GitHub.
    }
    else
    {
        //This local Version and the Version on GitHub are equal.
    }
 }

Here is the NuGet

Install-Package Octokit
Jehu answered 26/11, 2020 at 21:46 Comment(1)
Note: if TagName includes more than just dot-separated numbers like 'v1.0.0' or '3.10.3-rc2', you can't construct Version objects unless you remove the other characters. Also note that Version("1.0.0") < Version("1.0.0.0") for some reason.Peculate

© 2022 - 2024 — McMap. All rights reserved.