Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GitHub.hx #376

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
52 changes: 51 additions & 1 deletion source/funkin/backend/system/github/GitHub.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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<GitHubRelease> {
#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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -146,4 +196,4 @@ class GitHub {
return null;
#end
}
}
}