diff --git a/source/funkin/backend/system/github/GitHub.hx b/source/funkin/backend/system/github/GitHub.hx index 27ba825bd..bf6df6c71 100644 --- a/source/funkin/backend/system/github/GitHub.hx +++ b/source/funkin/backend/system/github/GitHub.hx @@ -7,6 +7,29 @@ import haxe.Exception; // TODO: Document further and perhaps make this a Haxelib. class GitHub { + /** + * Gets the latest 30 commits from a specific GitHub repository using the GitHub API. + * @param user The user/organization that owns the repository + * @param repository The repository name + * @param onError Error Callback + * @return Commits + */ + public static function getLatestCommits(user:String, repository:String, ?onError:Exception->Void):Array { + #if GITHUB_API + try { + var data = Json.parse(HttpUtil.requestText('https://api.github.com/repos/${user}/${repository}/commits')); + if (!(data is Array)) + throw __parseGitHubException(data); + + return data; + } catch(e) { + if (onError != null) + onError(e); + } + #end + return []; + } + /** * Gets all the releases from a specific GitHub repository using the GitHub API. * @param user The user/organization that owns the repository @@ -52,6 +75,33 @@ class GitHub { #end return []; } + + /** + * Gets the commit count from a specific GitHub repository using the GitHub API. + * @param user The user/organization that owns the repository + * @param repository The repository name + * @param onError Error Callback + * @return Releases + */ + public static function getCommitCount(user:String, repository:String, ?onError:Exception->Void):Int { + #if GITHUB_API + try { + var commitCount = 0; + var data = getContributors(user, repository, onError); + if (!(data is Array)) + throw __parseGitHubException(data); + for (contribution in data) { + commitCount += contribution.contributions; + } + return commitCount; + } catch(e) { + if (onError != null) + onError(e); + } + #end + return 0; + } + /** * Gets a specific GitHub organization using the GitHub API. @@ -146,4 +196,4 @@ class GitHub { return null; #end } -} \ No newline at end of file +}