From daa85ca8d87e0efc15a472935915437ab2cb2026 Mon Sep 17 00:00:00 2001 From: "Nebula S. Nova" <78160470+NebulaStellaNova@users.noreply.github.com> Date: Sun, 1 Sep 2024 10:14:08 -0400 Subject: [PATCH 1/2] Update GitHub.hx Add getCommits (Will be used on the main menu) --- source/funkin/backend/system/github/GitHub.hx | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/source/funkin/backend/system/github/GitHub.hx b/source/funkin/backend/system/github/GitHub.hx index 27ba825bd..22d5e3e93 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 all the 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 getCommits(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 @@ -146,4 +169,4 @@ class GitHub { return null; #end } -} \ No newline at end of file +} From de7101e5e22bf1276b3262607e77b4ac0134834e Mon Sep 17 00:00:00 2001 From: "Nebula S. Nova" <78160470+NebulaStellaNova@users.noreply.github.com> Date: Sun, 1 Sep 2024 10:29:48 -0400 Subject: [PATCH 2/2] Update GitHub.hx --- source/funkin/backend/system/github/GitHub.hx | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/source/funkin/backend/system/github/GitHub.hx b/source/funkin/backend/system/github/GitHub.hx index 22d5e3e93..bf6df6c71 100644 --- a/source/funkin/backend/system/github/GitHub.hx +++ b/source/funkin/backend/system/github/GitHub.hx @@ -8,13 +8,13 @@ import haxe.Exception; // TODO: Document further and perhaps make this a Haxelib. class GitHub { /** - * Gets all the commits from a specific GitHub repository using the GitHub API. + * 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 getCommits(user:String, repository:String, ?onError:Exception->Void):Array { + 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')); @@ -75,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.