Получите количество открытых проблем от GitHub с помощью API GitHub


Я разрабатываю php-приложение, в котором пользователь вводит ссылку на любой общедоступный репозиторий GitHub, а вывод будет

(i) Общее количество открытых вопросов

(ii) Количество открытых выпусков, которые были открыты за последние 24 часа

(iii) Количество открытых выпусков, которые были открыты более 24 часов назад, но менее 7 дней назад

(iv) Количество открытых вопросов, которые были открыты более 7 дней назад

Код для печати (i) Общее количество открытых проблемы приведены ниже с использованием api github и php curl, и он работает нормально.
Но я понятия не имею, как напечатать остальные три пункта (ii),(iii) и (iv).
Любая помощь в этом отношении будет признательна. Заранее спасибо.

<?php
//Test url
$url = "https://api.github.com/repos/anandkgpt03/test";
//Initiate curl
$ch = curl_init();
//Set the url
curl_setopt($ch, CURLOPT_URL,$url);
//Set the User Agent as username
curl_setopt($ch, CURLOPT_USERAGENT, "anandkgpt03");
//Accept the response as json
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Accept: application/json'));
//Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);

//Decode the json in associative array
$new_result=json_decode($result,true);

echo "Total Number of Open Issues:".$new_result["open_issues_count"];
?>
Author: Anand Gupta, 2015-09-07

2 answers

Вы можете получить то, что хотите, используя API GitHub.

Выполните следующие действия:

  1. Посетите URL-адрес проблемы с опцией state open: https://api.github.com/repos/{name}/support/issues?q=state:open.
  2. В результатах (в формате JSON) найдите метку времени created_at.
  3. Сравните вышеупомянутые значения с текущей меткой времени и отсортируйте эти выходные данные с помощью любой функции datetime.

Надеюсь, это поможет!

 1
Author: In1, 2015-09-09 10:26:00

Я использовал с параметр, доступный в API GitHub, который возвращает только проблемы, обновленные в это время или после этого, что помогает получить количество открытых проблем, открытых через какое-либо время.

Этот URL-адрес может быть полезен для получения дополнительной информации об этом: https://developer.github.com/v3/issues/

Ниже приведен правильный рабочий код моего вопроса.

<html>
<head>
<title></title>
</head>
<body>
<form action="" method="POST">
<input type="text" name="url" placeholder="Full URL of GitHub repository" size="60">
<input type="submit" name="submitButton">
</form>
</body>
</html>

<?php

if(isset($_POST['submitButton']))
{
    //Example-> https://github.com/Shippable/support/issues
    $input_url = $_POST['url'];
    //Break the input url in array format
    $input_url_array =  explode('/',$input_url);

    //Validate the input url
    if(strcmp($input_url_array[0],"https:")||strcmp($input_url_array[1],"")||strcmp($input_url_array[2],"github.com")||empty($input_url_array[3])||empty($input_url_array[4]))
    {
        die("</br>Invalid Url !!! Url should be in format <b>https://github.com/{org_name or username}/{repo_name}/</b><br>");
    }

    //url for the github Api, $input_url_array[3] contain organisation or username, put_url_array[3] contain repository name
    $url = "https://api.github.com/repos/".$input_url_array[3]."/".$input_url_array[4];
    //call the function and receive the result in associative array format
    $result = curlRequestOnGitApi($url);
    //Get total no of open issues using the $result array
    $total_open_issues = $result["open_issues_count"];
    echo "<br>Total Open Issues:<b>".$total_open_issues."</b><br>";


    //Date and Time 1 day or 24 hours ago in ISO 8601 Format
    $time_last24hr = date('Y-m-d\TH:i:s.Z\Z', strtotime('-1 day', time()));
    //url for the github Api with since parameter equal to time of last 24 hrs that return only issues updated at or after this time 
    $url = "https://api.github.com/repos/".$input_url_array[3]."/".$input_url_array[4]."/issues?since=".$time_last24hr;     
    //call the function and receive the result in associative array format
    $result = curlRequestOnGitApi($url);
    //Get no of open issues that were opened in last 24 hours
    $issues_last24hr = count($result);
    echo "Number of open issues that were opened in the last 24 hours:<b>".$issues_last24hr."</b><br>";


    //Date and Time 1 day or 24 hours ago in ISO 8601 Format
    $time_7daysago = date('Y-m-d\TH:i:s.Z\Z', strtotime('-7 day', time()));
    //url for the github Api with since parameter equal to time of 7 days ago that return only issues updated at or after this time 
    $url = "https://api.github.com/repos/".$input_url_array[3]."/".$input_url_array[4]."/issues?since=".$time_7daysago;
    //call the function and receive the result in associative array format
    $result = curlRequestOnGitApi($url);
    //Get no of open issues that were opened in 7 days ago
    $issues_last7days = count($result);
    echo "Number of open issues that were opened more than 24 hours ago but less than 7 days ago:<b>".($issues_last7days-$issues_last24hr)."</b><br>";


    echo "Number of open issues that were opened more than 7 days ago:<b>".($total_open_issues-$issues_last7days)."</b><br>";
}       

function curlRequestOnGitApi($url)
{
    $ch = curl_init();

    //Set the url
    curl_setopt($ch, CURLOPT_URL,$url);

    //Set the User Agent as username
    curl_setopt($ch, CURLOPT_USERAGENT, "anyusername");

    //Accept the response as json
    curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Accept: application/json'));

    //Will return the response, if false it print the response
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Execute
    $result=curl_exec($ch);

    // Closing
    curl_close($ch);

    //Decode the json in array
    $new_result=json_decode($result,true);

    //Return array
    return $new_result;
}

?>
 1
Author: Anand Gupta, 2015-09-09 15:00:59