Commit bb9900e0 authored by Thomas Löffler's avatar Thomas Löffler

Count updated issues and MRs in contributions

parent ff9db1b9
Pipeline #8424 passed with stages
in 4 minutes and 45 seconds
......@@ -46,7 +46,9 @@ class Contributions implements \Psr\Http\Server\MiddlewareInterface
$gitlabClient = new \GuzzleHttp\Client(['base_uri' => 'https://gitlab.typo3.org/api/v4/']);
$this->countContributions($gitlabClient, $contributions, $beginDate, $endDate, $apiToken, 'issues');
$this->countContributions($gitlabClient, $contributions, $beginDate, $endDate, $apiToken, 'issues', true);
$this->countContributions($gitlabClient, $contributions, $beginDate, $endDate, $apiToken, 'merge_requests');
$this->countContributions($gitlabClient, $contributions, $beginDate, $endDate, $apiToken, 'merge_requests', true);
$contributions['result'] = 'success';
if ($contributions['contributors']) {
......@@ -64,23 +66,30 @@ class Contributions implements \Psr\Http\Server\MiddlewareInterface
return $response;
}
private function countContributions(\GuzzleHttp\Client $gitlabClient, array &$contributions, string $beginDate, string $endDate, string $apiToken, string $type): void
private function countContributions(\GuzzleHttp\Client $gitlabClient, array &$contributions, string $beginDate, string $endDate, string $apiToken, string $type, bool $updated = false): void
{
$uri = $type . '/?scope=all&created_after=' . $beginDate . '&created_before=' . $endDate;
if ($updated) {
$uri = $type . '/?scope=all&updated_after=' . $beginDate . '&updated_before=' . $endDate;
} else {
$uri = $type . '/?scope=all&created_after=' . $beginDate . '&created_before=' . $endDate;
}
$request = new \GuzzleHttp\Psr7\Request('GET', $uri, ['Private-Token', $apiToken]);
$response = $gitlabClient->send($request);
$data = json_decode($response->getBody(), true);
$contributions['statistics'][$type] = count($data);
$contributions['statistics'][$type] += count($data);
$contributionType = $updated ? 'updated' : 'created';
foreach ($data as $item) {
if (!isset($contributions['contributors'][$item['author']['id']])) {
$contributions['contributors'][$item['author']['id']] = [
'contributions' => [
$type => 0
$contributionType => [
$type => 0
]
],
'user' => $item['author']
];
}
$contributions['contributors'][$item['author']['id']]['contributions'][$type]++;
$contributions['contributors'][$item['author']['id']]['contributions'][$contributionType][$type]++;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment