Merge remote-tracking branch 'upstream/main'

This commit is contained in:
lunarcleint
2024-02-04 00:58:19 -07:00
94 changed files with 1323 additions and 394 deletions
+80 -6
View File
@@ -9,8 +9,8 @@ import haxe.Http;
class GitHub {
/**
* Gets all the releases from a specific GitHub repository using the GitHub API.
* @param user
* @param repository
* @param user The user/group that owns the repository
* @param repository The repository name
* @return Releases
*/
public static function getReleases(user:String, repository:String, ?onError:Exception->Void):Array<GitHubRelease> {
@@ -29,6 +29,12 @@ class GitHub {
return [];
}
/**
* Gets the contributors list from a specific GitHub repository using the GitHub API.
* @param user The user/group that owns the repository
* @param repository The repository name
* @return Contributors List
*/
public static function getContributors(user:String, repository:String, ?onError:Exception->Void):Array<GitHubContributor> {
try {
var url = 'https://api.github.com/repos/${user}/${repository}/contributors';
@@ -45,6 +51,27 @@ class GitHub {
return [];
}
/**
* Gets a specific GitHub user/group using the GitHub API.
* @param user The user/group to get
* @return User/Group
*/
public static function getUser(user:String, ?onError:Exception->Void):GitHubUser {
try {
var url = 'https://api.github.com/users/$user';
var data = Json.parse(__requestOnGitHubServers(url));
if (Reflect.hasField(data, "documentation_url"))
throw __parseGitHubException(data);
return data;
} catch(e) {
if (onError != null)
onError(e);
}
return null;
}
/**
* Filters all releases gotten by `getReleases`
* @param releases Releases
@@ -58,29 +85,52 @@ class GitHub {
public static function __requestOnGitHubServers(url:String) {
var h = new Http(url);
h.setHeader("User-Agent", "request");
var r = null;
h.onStatus = function(s) {
if(isRedirect(s))
r = __requestOnGitHubServers(h.responseHeaders.get("Location"));
};
h.onData = function(d) {
r = d;
if(r == null) r = d;
}
h.onError = function(e) {
throw e;
}
h.request(false);
return r;
}
public static function __requestBytesOnGitHubServers(url:String) {
var h = new Http(url);
h.setHeader("User-Agent", "request");
var r = null;
h.onStatus = function(s) {
if(isRedirect(s))
r = __requestBytesOnGitHubServers(h.responseHeaders.get("Location"));
};
h.onBytes = function(d) {
r = d;
if(r == null) r = d;
}
h.onError = function(e) {
throw e;
}
h.request(false);
return r;
}
private static function isRedirect(status:Int):Bool {
switch (status) {
// 301: Moved Permanently, 302: Found (Moved Temporarily), 307: Temporary Redirect, 308: Permanent Redirect - Nex_isDumb
case 301 | 302 | 307 | 308 :
trace("Redirected with status code: " + status);
return true;
}
return false;
}
private static function __parseGitHubException(obj:Dynamic):GitHubException {
var msg:String = "(No message)";
var url:String = "(No API url)";
@@ -99,18 +149,33 @@ import haxe.Exception;
class GitHub {
/**
* Gets all the releases from a specific GitHub repository using the GitHub API.
* @param user
* @param repository
* @param user The user/group that owns the repository
* @param repository The repository name
* @return Releases
*/
public static function getReleases(user:String, repository:String, ?onError:Exception->Void):Array<GitHubRelease> {
return [];
}
/**
* Gets the contributors list from a specific GitHub repository using the GitHub API.
* @param user The user/group that owns the repository
* @param repository The repository name
* @return Contributors List
*/
public static function getContributors(user:String, repository:String, ?onError:Exception->Void):Array<GitHubContributor> {
return [];
}
/**
* Gets a specific GitHub user/group using the GitHub API.
* @param user The user/group to get
* @return User/Group
*/
public static function getUser(user:String, ?onError:Exception->Void):GitHubUser {
return null;
}
/**
* Filters all releases gotten by `getReleases`
* @param releases Releases
@@ -130,5 +195,14 @@ class GitHub {
private static function __parseGitHubException(obj:Dynamic):GitHubException {
return null;
}
private static function isRedirect(status:Int):Bool {
switch (status) {
// 301: Moved Permanently, 302: Found (Moved Temporarily), 307: Temporary Redirect, 308: Permanent Redirect - Nex_isDumb
case 301 | 302 | 307 | 308 :
trace("Redirected with status code: " + status);
return true;
}
return false;
}
}
#end
@@ -20,7 +20,7 @@ class ScriptsMacro {
"flixel.addons.plugin", "flixel.addons.text", "flixel.addons.tile", "flixel.addons.transition",
"flixel.addons.util",
// OTHER LIBRARIES & STUFF
"away3d", "flx3d",
#if THREE_D_SUPPORT "away3d", "flx3d", #end
#if VIDEO_CUTSCENES "hxvlc.flixel", "hxvlc.openfl", #end
// BASE HAXE
"DateTools", "EReg", "Lambda", "StringBuf", "haxe.crypto", "haxe.display", "haxe.exceptions", "haxe.extern", "scripting"