Page 1 of 1

Using GitHub API on Extension Websites?

Posted: Fri Apr 19, 2019 5:41 am
by SamBrishes
Hellow,

Both extension websites plugins.bludit.com and themes.bludit.com could use the GitHub API, to fetch the latest release of the respective plugins and themes. It could also read some other metadata informations to show off some additional data and stuff.

This would allow developers to change and edit there extensions at anytime without fork and pull-request to the respective GitHub repositories (bludit/plugins-repository or bludit/themes-repository). The GitHub API itself is also very well documented and really easy to use. I wrote a small helper function on my own, which I'm using on any GitHub-connected app / website:

Code: Select all

function pytesNET_GitHub($path){
	$url  = "https://api.github.com/repos/" . trim($path, "/");
	$url .= "?client_id=" . GITHUB_ID . "&client_secret=" . GITHUB_SECRET;

	// cURL
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_HEADER, false);
	curl_setopt($curl, CURLOPT_TIMEOUT, 60);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
	curl_setopt($curl, CURLOPT_HTTPHEADER, array(
		"Accept: application/vnd.github.v3+json",
		"Content-Type: application/json",
		"User-Agent: " . GITHUB_AUTH
	));
	$content = curl_exec($curl);
	$response = curl_getinfo($curl, CURLINFO_HTTP_CODE);
	curl_close($curl);

	// Response
	if($response != 200){
		return false;
	}
	return json_decode($content, true);
}
This would save many clicks on the "Merge Pull Request" button. ;)

Sincerely,
Sam.