Commit 1360f429 authored by Stefan Busemann's avatar Stefan Busemann

Merge branch 'task/count-updated-types-for-contributions' into 'develop'

Count updated issues and MRs in contributions

See merge request t3o/typo3.org!344
parents bccaeb81 5a79ad24
Pipeline #8550 failed with stages
in 3 minutes and 35 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,33 @@ 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 ($updated && $item['created_at'] === $item['updated_at']) {
continue;
}
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