-
Notifications
You must be signed in to change notification settings - Fork 4
/
Octokit.cs
38 lines (36 loc) · 1.39 KB
/
Octokit.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Octokit;
using System.Reflection;
using System.Net;
namespace ERPHelper
{
public class Octokit
{
public async Task<GitHubRelease> GetLatest()
{
GitHubRelease release = new GitHubRelease();
try
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
GitHubClient client = new GitHubClient(new ProductHeaderValue("erp-helper"));
Release latestRelease = await client.Repository.Release.GetLatest("swhitley", "ERPHelper");
Version latestGitHubVersion = new Version(latestRelease.TagName.Replace("v", ""));
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
Version localVersion = new Version(version.Substring(0, version.LastIndexOf(".")));
release.UpdateAvailable = localVersion.CompareTo(latestGitHubVersion) != 0 ? true : false;
release.Description = latestRelease.Body;
release.Version = latestGitHubVersion.ToString();
}
catch
{
// ignore exception
}
return release;
}
}
}