From bc06df93e67cd52164a0dac13dac3df917b93db8 Mon Sep 17 00:00:00 2001 From: artem Date: Thu, 3 Oct 2019 12:56:05 +0300 Subject: [PATCH] create releases informer --- github-embed.php | 32 +++++++++++++++++++++++++++++++ templates/repository_releases.php | 10 ++++++++++ 2 files changed, 42 insertions(+) create mode 100644 templates/repository_releases.php diff --git a/github-embed.php b/github-embed.php index 060084c..ecdb02e 100644 --- a/github-embed.php +++ b/github-embed.php @@ -170,6 +170,8 @@ class github_embed { // Issues / Milestones if ( preg_match( '#https?://github.com/([^/]*)/([^/]*)/graphs/contributors/?$#i', $url, $matches ) && ! empty( $matches[2] ) ) { return $this->oembed_github_repo_contributors( $matches[1], $matches[2], $echos ); + } elseif ( preg_match( '#https?://github.com/([^/]*)/([^/]*)/releases.*$#i', $url, $matches ) && ! empty( $matches[2] ) ) { + return $this->oembed_github_repo_releases( $matches[1], $matches[2], $echos ); } elseif ( preg_match( '#https?://github.com/([^/]*)/([^/]*)/issues.*$#i', $url, $matches ) && ! empty( $matches[2] ) ) { if ( preg_match( '#issues.?milestone=([0-9]*)#i', $url, $milestones ) ) { $milestone = $milestones[1]; @@ -208,6 +210,36 @@ class github_embed { return ob_get_clean(); } + /** + * Retrieve the information from github for a repo, and his releases + * + */ + private function oembed_github_repo_releases( $owner, $repository, $ret=false ) { + $data = [ + 'owner_slug' => $owner, + 'repo_slug' => $repository, + ]; + $data['repo'] = $this->api->get_repo( $owner, $repository ); + $data['commits'] = $this->api->get_repo_releases( $owner, $repository ); + $data['logo_class'] = apply_filters( 'wp_github_oembed_logo_class', 'github-logo-mark' ); + + $response = new stdClass(); + $response->type = 'rich'; + $response->width = '10'; + $response->height = '10'; + $response->version = '1.0'; + $response->title = $data['repo']->description; + $response->html = $this->process_template( + 'repository_releases.php', $data ); + + if ($ret){ + return $response; + } + header( 'Content-Type: application/json' ); + echo json_encode( $response ); + die(); + } + /** * Retrieve a list of contributors for a project * diff --git a/templates/repository_releases.php b/templates/repository_releases.php new file mode 100644 index 0000000..5145a16 --- /dev/null +++ b/templates/repository_releases.php @@ -0,0 +1,10 @@ +
+

+ + + description !=null ? $data['repo']->description : $data['repo']->name) ?> + +
+ Download name;?> +

+