summaryrefslogtreecommitdiffstats
path: root/bin/tools/generate_authors.php
blob: 18018686e458ea2e55bd2eaf5a548d25e56aae41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
/**
 * ownCloud - News
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Bernhard Posselt <dev@bernhard-posselt.com>
 * @copyright Bernhard Posselt 2016
 */

$cmd = 'git --no-pager shortlog -nse HEAD';
exec($cmd, $contributors);

// extract data from git output into an array
$regex = '/^\s*(?P<commit_count>\d+)\s*(?P<name>.*\w)\s*<(?P<email>[^\s]+)>$/';
$contributors = array_map(function ($contributor) use ($regex) {
    preg_match($regex, $contributor, $result);
    return $result;
}, $contributors);

// filter out bots
$contributors = array_filter($contributors, function ($contributor) {
    return strpos($contributor['name'], 'Jenkins') !== 0;
});

// turn tuples into markdown
$markdownLines = array_map(function ($contrib) {
    return '* [' . $contrib['name'] . '](mailto:' . $contrib['email'] . ')';
}, $contributors);

// add headline
array_unshift($markdownLines, '# Authors');

$markdown = implode("\n", $markdownLines);
file_put_contents('AUTHORS.md', $markdown);