{$changelog["milestone"]["title"]}"; // Creates paragraph for description if ( ! empty( $changelog["milestone"]["description"] ) ) { $display .= "

{$changelog["milestone"]["description"]}

"; } // Creates paragraph for closed date $display .= "

Closed on {$changelog["milestone"]["closed_date"]}

"; // Converts the issues array into HTML list $display .= ''; // Echos or returns HTML list based on $echo parameter if ( true === $echo ) { echo $display; } else { return $display; } } } /** * Gets the changelog from GitHub and returns as an array * * @since 4.7.0 * @uses QSM_Changelog_Generator::api_call Used to retrieve the changelog from GitHub * @param string $repo The name of the GitHub repo. Should be similar to 'QuizandSurveyMaster/quiz_master_next' * @param int $milestone The number of the milestone in your GitHub repo * @return array An array of all the titles of closed issues for the milestone */ public static function get_changelog( $repo, $milestone ) { // Gets transient if available $changelog = get_transient( "changelog-$repo-$milestone" ); if ( false === $changelog ) { $changelog = array(); // Constructs url and then calls the api $issue_url = "https://api.github.com/repos/$repo/issues?milestone=$milestone&state=all"; $issue_data = QSM_Changelog_Generator::api_call( $issue_url ); if ( $issue_data ) { // Constructs url and then calls the api $milestone_url = "https://api.github.com/repos/$repo/milestones/$milestone"; $milestone_data = QSM_Changelog_Generator::api_call( $milestone_url ); if ( $milestone_data && isset( $milestone_data['title'] ) ) { $milestone_array = array( 'title' => $milestone_data["title"], 'description' => $milestone_data["description"], 'closed_date' => $milestone_data["closed_at"] ); } else { $milestone_array = array( 'title' => '', 'description' => '', 'closed_date' => '' ); } $changelog["milestone"] = $milestone_array; $changelog["issues"] = array(); // Creates an array of all issues that are closed foreach ( $issue_data as $issue ) { if ( ! isset( $issue["pull_request"] ) ) { if ( "closed" === $issue["state"] ) { $changelog["issues"][] = array( 'title' => $issue["title"], 'labels' => $issue["labels"], 'issue' => $issue["number"], 'url' => $issue["html_url"] ); } } } } // Sets the transient set_transient( "changelog-$repo-$milestone", $changelog, 3600 ); } return $changelog; } /** * Gets the contents of the $url that is passed * * @since 4.7.0 * @param string $url The url to get the contents of * @return bool|array Returns false if encounters an error. Returns an associated array if successful */ public static function api_call( $url ) { // Gets the url $response = wp_remote_get( $url ); // If an error occurs, return false. If successful, return json_decoded array if ( is_wp_error( $response ) ) { return false; } else { $data = wp_remote_retrieve_body( $response ); if ( is_wp_error( $data ) ) { return false; } else { return json_decode( $data, true ); } } } } ?>