showable cne devs in credits + github util rewrite
and fully to beta
This commit is contained in:
@@ -4,71 +4,123 @@ package funkin.backend.system.github;
|
||||
import haxe.Json;
|
||||
import haxe.Exception;
|
||||
import haxe.Http;
|
||||
#end
|
||||
|
||||
// TODO: Document further and perhaps make this a Haxelib.
|
||||
class GitHub {
|
||||
/**
|
||||
* Gets all the releases from a specific GitHub repository using the GitHub API.
|
||||
* @param user The user/group that owns the repository
|
||||
* @param user The user/organization that owns the repository
|
||||
* @param repository The repository name
|
||||
* @param onError Error Callback
|
||||
* @return Releases
|
||||
*/
|
||||
public static function getReleases(user:String, repository:String, ?onError:Exception->Void):Array<GitHubRelease> {
|
||||
#if GITHUB_API
|
||||
try {
|
||||
var url = 'https://api.github.com/repos/${user}/${repository}/releases';
|
||||
|
||||
var data = Json.parse(__requestOnGitHubServers(url));
|
||||
var data = Json.parse(__requestOnGitHubServers('https://api.github.com/repos/${user}/${repository}/releases'));
|
||||
if (!(data is Array))
|
||||
throw __parseGitHubException(data);
|
||||
|
||||
|
||||
return data;
|
||||
} catch(e) {
|
||||
if (onError != null)
|
||||
onError(e);
|
||||
}
|
||||
#end
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the contributors list from a specific GitHub repository using the GitHub API.
|
||||
* @param user The user/group that owns the repository
|
||||
* @param user The user/organization that owns the repository
|
||||
* @param repository The repository name
|
||||
* @param onError Error Callback
|
||||
* @return Contributors List
|
||||
*/
|
||||
public static function getContributors(user:String, repository:String, ?onError:Exception->Void):Array<GitHubContributor> {
|
||||
#if GITHUB_API
|
||||
try {
|
||||
var url = 'https://api.github.com/repos/${user}/${repository}/contributors';
|
||||
|
||||
var data = Json.parse(__requestOnGitHubServers(url));
|
||||
var data = Json.parse(__requestOnGitHubServers('https://api.github.com/repos/${user}/${repository}/contributors'));
|
||||
if (!(data is Array))
|
||||
throw __parseGitHubException(data);
|
||||
|
||||
|
||||
return data;
|
||||
} catch(e) {
|
||||
if (onError != null)
|
||||
onError(e);
|
||||
}
|
||||
#end
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a specific GitHub user/group using the GitHub API.
|
||||
* @param user The user/group to get
|
||||
* @return User/Group
|
||||
* Gets a specific GitHub organization using the GitHub API.
|
||||
* @param org The organization to get
|
||||
* @param onError Error Callback
|
||||
* @return Organization
|
||||
*/
|
||||
public static function getUser(user:String, ?onError:Exception->Void):GitHubUser {
|
||||
public static function getOrganization(org:String, ?onError:Exception->Void):GitHubOrganization {
|
||||
#if GITHUB_API
|
||||
try {
|
||||
var data = Json.parse(__requestOnGitHubServers('https://api.github.com/orgs/$org'));
|
||||
if (Reflect.hasField(data, "documentation_url"))
|
||||
throw __parseGitHubException(data);
|
||||
|
||||
return data;
|
||||
} catch(e) {
|
||||
if (onError != null)
|
||||
onError(e);
|
||||
}
|
||||
#end
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the members list from a specific GitHub organization using the GitHub API.
|
||||
* NOTE: Members use Contributors' structure!
|
||||
* @param org The organization to get the members from
|
||||
* @param onError Error Callback
|
||||
* @return Members List
|
||||
*/
|
||||
public static function getOrganizationMembers(org:String, ?onError:Exception->Void):Array<GitHubContributor> {
|
||||
#if GITHUB_API
|
||||
try {
|
||||
var data = Json.parse(__requestOnGitHubServers('https://api.github.com/orgs/$org/members'));
|
||||
if (Reflect.hasField(data, "documentation_url"))
|
||||
throw __parseGitHubException(data);
|
||||
|
||||
return data;
|
||||
} catch(e) {
|
||||
if (onError != null)
|
||||
onError(e);
|
||||
}
|
||||
#end
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a specific GitHub user/organization using the GitHub API.
|
||||
* NOTE: If organization, it will be returned with the structure of a normal user; use `getOrganization` if you specifically want an organization!
|
||||
* @param user The user/organization to get
|
||||
* @param onError Error Callback
|
||||
* @return User/Organization
|
||||
*/
|
||||
public static function getUser(user:String, ?onError:Exception->Void):GitHubUser {
|
||||
#if GITHUB_API
|
||||
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);
|
||||
}
|
||||
#end
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -80,13 +132,14 @@ class GitHub {
|
||||
* @return Filtered releases.
|
||||
*/
|
||||
public static inline function filterReleases(releases:Array<GitHubRelease>, keepPrereleases:Bool = true, keepDrafts:Bool = false)
|
||||
return [for(release in releases) if (release != null && (!release.prerelease || (release.prerelease && keepPrereleases)) && (!release.draft || (release.draft && keepDrafts))) release];
|
||||
return #if GITHUB_API [for(release in releases) if (release != null && (!release.prerelease || (release.prerelease && keepPrereleases)) && (!release.draft || (release.draft && keepDrafts))) release] #else releases #end;
|
||||
|
||||
public static function __requestOnGitHubServers(url:String) {
|
||||
var r = null;
|
||||
#if GITHUB_API
|
||||
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"));
|
||||
@@ -100,13 +153,15 @@ class GitHub {
|
||||
}
|
||||
|
||||
h.request(false);
|
||||
#end
|
||||
return r;
|
||||
}
|
||||
public static function __requestBytesOnGitHubServers(url:String) {
|
||||
var r = null;
|
||||
#if GITHUB_API
|
||||
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"));
|
||||
@@ -120,6 +175,7 @@ class GitHub {
|
||||
}
|
||||
|
||||
h.request(false);
|
||||
#end
|
||||
return r;
|
||||
}
|
||||
private static function isRedirect(status:Int):Bool {
|
||||
@@ -132,6 +188,7 @@ class GitHub {
|
||||
return false;
|
||||
}
|
||||
private static function __parseGitHubException(obj:Dynamic):GitHubException {
|
||||
#if GITHUB_API
|
||||
var msg:String = "(No message)";
|
||||
var url:String = "(No API url)";
|
||||
if (Reflect.hasField(obj, "message"))
|
||||
@@ -139,70 +196,8 @@ class GitHub {
|
||||
if (Reflect.hasField(obj, "documentation_url"))
|
||||
url = Reflect.field(obj, "documentation_url");
|
||||
return new GitHubException(msg, url);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
import haxe.Json;
|
||||
import haxe.Exception;
|
||||
|
||||
class GitHub {
|
||||
/**
|
||||
* Gets all the releases from a specific GitHub repository using the GitHub API.
|
||||
* @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 {
|
||||
#else
|
||||
return null;
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters all releases gotten by `getReleases`
|
||||
* @param releases Releases
|
||||
* @param keepPrereleases Whenever to keep Pre-Releases.
|
||||
* @param keepDrafts Whenever to keep Drafts.
|
||||
* @return Filtered releases.
|
||||
*/
|
||||
public static inline function filterReleases(releases:Array<GitHubRelease>, keepPrereleases:Bool = true, keepDrafts:Bool = false)
|
||||
return releases;
|
||||
|
||||
public static function __requestOnGitHubServers(url:String) {
|
||||
return null;
|
||||
}
|
||||
public static function __requestBytesOnGitHubServers(url:String) {
|
||||
return null;
|
||||
}
|
||||
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
|
||||
case 301 | 302 | 307 | 308 :
|
||||
trace("Redirected with status code: " + status);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#end
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package funkin.backend.system.github;
|
||||
|
||||
// Also used by Organizations for members!
|
||||
typedef GitHubContributor = {
|
||||
var login:String;
|
||||
var id:Int;
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package funkin.backend.system.github;
|
||||
|
||||
import funkin.backend.system.github.GitHubUser.GitHubUserType;
|
||||
|
||||
typedef GitHubOrganization = {
|
||||
var login:String;
|
||||
var id:Int;
|
||||
var node_id:String;
|
||||
var url:String;
|
||||
var repos_url:String;
|
||||
var events_url:String;
|
||||
var hooks_url:String;
|
||||
var issues_url:String;
|
||||
var members_url:String;
|
||||
var public_members_url:String;
|
||||
var avatar_url:String;
|
||||
var description:String;
|
||||
var name:String;
|
||||
var company:String;
|
||||
var blog:String;
|
||||
var location:String;
|
||||
var email:String;
|
||||
var twitter_username:String;
|
||||
var is_verified:Bool;
|
||||
var has_organization_projects:Bool;
|
||||
var has_repository_projects:Bool;
|
||||
var public_repos:Int;
|
||||
var public_gists:Int;
|
||||
var followers:Int;
|
||||
var following:Int;
|
||||
var html_url:String;
|
||||
var created_at:String;
|
||||
var updated_at:String;
|
||||
var archived_at:String;
|
||||
var type:GitHubUserType;
|
||||
}
|
||||
Reference in New Issue
Block a user