Skip to content

Commit

Permalink
tagging v0.0.4 for release
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-weiner committed Aug 4, 2020
1 parent b07684a commit de913c4
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 21 deletions.
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate Link: https://paypal.me/michaelw13 <br>
Tags: github-api, github-list, github-table, wordpress-table <br>
Requires at least: 5.0 <br>
Tested up to: 5.5 <br>
Stable tag: 0.0.3 <br>
Stable tag: 0.0.4 <br>
Requires PHP: 7.0.0 <br>
License: GPLv2 or later <br>
License URI: https://www.gnu.org/licenses/gpl-2.0.html <br>
Expand All @@ -18,12 +18,13 @@ The display will default to show all of the publicly available repositories for

### Shortcode Attributes
This shortcode comes with a number of different shortcode modifiers to give you greater control over what is displayed and how it is displayed. All of the possible shortcode modifiers are listed and described below.
* `excl` - A comma separated string to specify slug names of repositories that you would like to exclude from displaying in your table. The default value of ` ` (blank) is used meaning all repositories will be displayed when the parameter is left blank or when it is not included at all. View ***[How do I exclude certain repositories from displaying in a table?](https://github.com/mike-weiner/list-github-repositories#how-do-i-exclude-certain-repositories-from-displaying-in-my-table)*** below if you are unable to find your repository slug name in the URL.
* `num` - A string that contains only an integer value to specify how many repositories you would like to display in the table. The default value of `30` is used when the parameter is left blank or when it is not included at all. This follows the default value set by the Github API. ***Note: The Github API currently has a maximum of 100 repositories per page, so even if you enter a number of 100 only the first 100 repositories will be displayed.***
* `order` - A string that allows you to choose in what order the repositories are displayed. The possible choices are `asc` and `desc`. The default value of `asc` is used when the `sort` parameter is `full_name` (see details on the `sort` parameter below for these scenarios) and `desc` is used for all other scenarios. This follows the default value set by the Github API.
* `sort` - A string allowing you to specify in what way the repositories being displayed are sorted. Options include `created`, `updated`, `pushed`, and `full_name`. The default value of `full_name` is used when the parameter is left blank or when it is not included at all. This follows the default value set by the Github API.
* `user` - A string that takes in the Github username of the user that you would like to display repositories for. The default value of `mike-weiner` is used when the parameter is left blank or when it is not included at all.

You can find more about the Github API and its parameters here: https://developer.github.com/v3/repos/#list-repositories-for-a-user
You can find more about the Github API and its parameters here: [https://developer.github.com/v3/repos/#list-repositories-for-a-user](https://developer.github.com/v3/repos/#list-repositories-for-a-user)

## Installation

Expand Down Expand Up @@ -52,6 +53,16 @@ This plugin makes use of a transient, a form of cache. This means all of your Gi

Don't worry! Your table will update! Give it 15 minutes, come back, refresh the page, and you should see the any changes made!

### How do I exclude certain repositories from displaying in my table?

First you will need to find the slug name(s) for the repository(ies) that you would like to prevent from displaying in your table. To do this, go to Github and navigate to the repository you want to exclude. Examine the URL. Your URL should read something similar to: ***...github.com/[username]/[repository slug name]/...***

You want to copy what you see where `[repository slug name]` is into the `excl` shortcode attribute. For example, this repository's URL is: [https://github.com/mike-weiner/list-github-repositories/](https://github.com/mike-weiner/list-github-repositories/). If I wanted to exclude this repo, I would need to copy `list-github-repositories`. ***Only copy what is between the slashes, even if there is more after your repository slug name.***

Now, go to the page that you have/are going to place the shortcode. Within the brackets of your shortcode include the modifier `excl=""`. Between the double-quotes, paste the slug name of the repository that you want to exclude. So, if I wanted to exclude this repository in my table, my shortcode would look like: `[gitlist excl="list-github-repositories"]`.

If you want to exclude more than one repository, just separate the repository slug names by a comma. For example, if I wanted to exclude more repositories from my table my shortcode would look like: `[gitlist excl="list-github-repositories, example-repo-slug-1, example-repo-slug-2"]`. There are no limits as to how many repositories you can exclude.

### Why are the repositories being displayed not from the correct user?

Navigate to the page where the table is being displayed. Begin editing the page and examine the `[gitlist user=""]` shortcode on the page. Double check that a Github username is entered within the double quotes after `user=` in the shortcode. Please check that this is the correct user name.
Expand All @@ -62,6 +73,17 @@ Navigate to the page where the table is being displayed. Begin editing the page

## Changelog

### 0.0.4
* Released on August 4, 2020
* Added: Shortcode attribute `excl` allows the user to specify repository slug name(s) (separated by comma) to exclude from being displayed in a table
* Added: A new FAQ *`How do I exclude certain repositories from displaying in a table?`* question has been added covering the new `excl` shortcode attribute and how to use it
* Added: A new *Special Thanks* section to the README with a thank you to [@duplaja]((https://github.com/duplaja))
* Fixed: Restored functionality of the `num` parameter, the Github API is still limit is still 100
* Updated: Updated README shortcode attribute descriptions
* Updated: Updated appropriate links to use markdown formatting instead of Github's automatic link detection in the README
* Edited: github-repo-listing.php
* Edited: README.md

### 0.0.3
* Released on August 3, 2020
* Added: Transient cache for all Github display tables you have across your site. Each table will update on the first page refresh every 15 minutes
Expand All @@ -86,6 +108,9 @@ Navigate to the page where the table is being displayed. Begin editing the page

## Upgrade Notice

### 0.0.4
Today's update introduces a new shortcode attribute `excl` that allows you to specify certain repositories to exclude from being displayed in your table! There is also a new *`Special Thanks`* section of the README for those that have provided me with some great resources and help along the way. There are numerous other smaller changes like code optimization, greater commenting, and resource management going on behind the scenes. Enjoy! As always, if you experience any issues please open a new issue on the Github repository and I will be happy to assist.

### 0.0.3
This update introduces a 15 minute cache for displaying updates on your Github display table. This means your Github table will update on the first page refresh after 15 minutes. This was accomplished through using WordPress transients and will help to keep your page load times down.

Expand All @@ -98,4 +123,7 @@ Initial release!
## Arbitrary section

### Github Repository
The Github Repository can be found here: https://github.com/mike-weiner/list-github-repositories/.
The Github Repository can be found here: [https://github.com/mike-weiner/list-github-repositories/](https://github.com/mike-weiner/list-github-repositories/).

### Special Thanks:
A special thank you to user [@duplaja](https://github.com/duplaja) on Github for several helpful repositories, links to the WordPress Codex, and insight that made completing certain functionality successful.
49 changes: 31 additions & 18 deletions github-repo-listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Display a table with information about all of the public repositories for a specific Github user.
* Author: Michael Weiner
* Author URI: https://michaelweiner.org/
* Version: 0.0.3
* Version: 0.0.4
* License: GPL2+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
Expand All @@ -32,15 +32,12 @@ function mw_github_api_call_transient($mw_transient_id, $mw_api_url) {
if (!empty($mw_transient)) { # if the transient exists, we just need to return it
return $mw_transient;
} else {
# delete expired transient from the database
delete_transient($mw_transient_id);

# go to Github, grab json data from Github, and decode it
$mw_github_data = wp_remote_get(esc_html($mw_api_url));

# break early if JSON request ends in error
if (is_wp_error($mw_github_data)) {
return ("<html><div class='mw-github-container'>We're sorry. There appeared to be an error. Please re-evaluate your shortcode.</div></<html>");
return ("error");
}

# read decoded JSON data into an array
Expand All @@ -66,6 +63,7 @@ function mw_git_display_function($attr) {

# array to store shortcode parameters
$mw_git_display_function = shortcode_atts( array(
'excl' => '',
'num' => '30',
'order' => '',
'sort' => '',
Expand All @@ -75,7 +73,11 @@ function mw_git_display_function($attr) {
# strip out ALL spaces as the API URL cannot have any breaks
$mw_git_display_function['user'] = preg_replace("/\s+/", "", $mw_git_display_function['user']);

# check that user attribute is NOT empty
# create array of repos to be ignored from the 'excl' shortcode attribute
$mw_git_display_function['excl'] = preg_replace("/\s+/", "", $mw_git_display_function['excl']); # strip out ALL spaces from the comma separated list of repos to exclude from the display
$mw_repos_to_ignore_arr = explode (",", $mw_git_display_function['excl']); # store slugs of repos to exclude in their own array

# check that user attribute is NOT empty -> if so, set the default to my github username
if ($mw_git_display_function['user'] == '') {
$mw_git_display_function['user'] = 'mike-weiner';
}
Expand All @@ -90,18 +92,17 @@ function mw_git_display_function($attr) {
if (in_array(strtolower($mw_git_display_function['sort']), $mw_github_sort_params)) {
$mw_github_api_url = $mw_github_api_url . "?sort=" . $mw_git_display_function['sort'];

# establish placeholder for sort param for use in transient id
$mw_url_sort_placeholder = $mw_git_display_function['sort'];
$mw_url_sort_placeholder = $mw_git_display_function['sort']; # establish placeholder for sort param for use in transient id

} else {
$mw_url_sort_placeholder = "full_name";
$mw_url_sort_placeholder = "full_name"; # establish placeholder for sort param for use in transient id
}

# check for valid order parameter
if (in_array(strtolower($mw_git_display_function['order']), $mw_github_direction_params)) {
$mw_github_api_url = $mw_github_api_url . "?direction=" . $mw_git_display_function['order'];

# establish placeholder for order param for use in transient id
$mw_url_order_placeholder = $mw_git_display_function['order'];
$mw_url_order_placeholder = $mw_git_display_function['order']; # establish placeholder for order param for use in transient id

} else {
# set placeholder for order param based on default values specified by Github API
Expand All @@ -112,27 +113,34 @@ function mw_git_display_function($attr) {
$mw_url_order_placeholder = "desc";
}
}

# check for valid per_page parameter
if (is_numeric($mw_git_display_function['num'])) {
$mw_github_api_url = $mw_github_api_url . "?per_page=" . abs(intval($mw_git_display_function['num']));
}

# create transient id for this particular shortcode call
$mw_github_transient_id = $mw_prefix . "git-list-" . esc_html($mw_git_display_function['user']) . "-" . esc_html($mw_url_sort_placeholder) . "-" . esc_html($mw_url_order_placeholder) . "-" . esc_html(abs(intval($mw_git_display_function['num'])));

# grab/create transient
$mw_github_transient = mw_github_api_call_transient($mw_github_transient_id, esc_html($mw_github_api_url));

# check if transient is empty -> if so, return early
# check if transient is empty -> if so, return early as the user has no public facing repos
if (empty($mw_github_transient)) {
return "<html><div class='mw-github-container'>We could not find any public repositories for this user!</div></html>";
}

# check if transient is a String (JSON error ocurred) -> if so, return early
if (is_string($mw_github_transient)) {
return ($mw_github_transient);
# check if transient is a String (JSON error ocurred) -> if so, return early as there was an error with the JSON request
if ($mw_github_transient == "error") {
return ("<html><div class='mw-github-container'>We're sorry. There appeared to be an error. Please re-evaluate your shortcode and try refreshing the page in 15 minutes.</div></<html>");
}

# generate HTML
# begin to generate HTML
$mw_html_output = "<html><div class='mw-github-container'><table>";

# columns for HTML table
# this array's keys are the names of the JSON parameters we want to pull out of the array we get back from Github
# this array's values are the table header row values so we can be consistent with capitalization or re-word the column to be different than the JSON parameter name
$mw_html_th_cols = array(
"name" => "Repository",
"description" => "Description"
Expand All @@ -154,11 +162,16 @@ function mw_git_display_function($attr) {
# add row to HTML table data for every repo in github_data_dict
foreach ($mw_github_transient as $mw_repo){

# check that we have not gone over the number of repos the user wants to list & that we are under 100
if (!($mw_repo_count < abs(intval($mw_git_display_function['num']))) && ($mw_repo_count < 100)) {
# check that we have not gone over the number of repos the user wants to list
if (!($mw_repo_count < abs(intval($mw_git_display_function['num'])))) {
break;
}

# check that the current repo was not specified by the user to be skipped using the 'excl' shortcode attribute -> if so, skip to next repo
if (!empty($mw_repos_to_ignore_arr) && in_array($mw_repo['name'], $mw_repos_to_ignore_arr)) {
continue;
}

$mw_html_table_row = "<tr class='mw-github-data-row'>"; # open HTML table row tag

foreach ($mw_html_th_cols as $mw_json_param => $mw_label) { # add every column being requested in html_th_cols
Expand Down

0 comments on commit de913c4

Please sign in to comment.