Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#if UNITY_2019_4_OR_NEWER

using StansAssets.Foundation.Editor;
using UnityEditor;
using UnityEngine.UIElements;

namespace StansAssets.Plugins.Editor
Expand Down
28 changes: 28 additions & 0 deletions com.stansassets.plugins-dev-kit/Editor/Utility/GitHubRelease.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Linq;

namespace StansAssets.Plugins.Editor
{
public class GitHubRelease
{
public string Name { get; private set; }
public string Tag { get; private set; }

public void ReadJson (string json)
{
Name = FindValueByKey ("name", json);
Tag = FindValueByKey ("tag_name", json);
}

string FindValueByKey (string key, string json)
{
// number of characters from the 1st char of the given key to the 1st char of corresponding value
int offsetBeforeValue = key.Length + 5;
string lookForString = $"\"{key}\"";
int position = json.IndexOf (lookForString) + offsetBeforeValue;
var value = (position > offsetBeforeValue)
? new string(json.Skip (position).TakeWhile (c => c != '"').ToArray ())
: string.Empty;
return value;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions com.stansassets.plugins-dev-kit/Editor/Utility/GitHubUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using UnityEngine.Networking;

namespace StansAssets.Plugins.Editor
{
public static class GitHubUtility
{
public static void GetLatestRelease (string url, Action<GitHubRelease> callback)
{
var release = new GitHubRelease ();
var rq = UnityWebRequest.Get (GetReleaseInfoURL (url));
rq.SendWebRequest ().completed += obj => {
release.ReadJson (rq.downloadHandler.text);
callback (release);
};
}

public static string GetReleaseInfoURL (string repositoryURL)
{
if (repositoryURL.Contains ("github.com")) {
return repositoryURL.Replace (@".git", @"/releases/latest")
.Replace (@"ssh://git@github.com:", @"https://api.github.com/repos/");
}
else if (repositoryURL.Contains ("npmjs.org")) {
throw new NotImplementedException ();
}

throw new NotImplementedException ();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.