Skip to content

Commit ca74c3f

Browse files
authored
Merge pull request #34 from jsor-labs/changelog
Implement combined changelog for all components
2 parents fd58128 + 6e745bd commit ca74c3f

17 files changed

+237
-36
lines changed

bin/build

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ if ($input->hasParameterOption('--use-asset-dev-server')) {
5252
}
5353

5454
if (!$input->hasParameterOption('--no-component-update')) {
55-
$components = React\Website\Data\components($container['github.client']);
56-
57-
foreach ($components as $component) {
55+
foreach ($container['data.components'] as $component) {
5856
$output->writeln(sprintf(
5957
'<comment>Updating component %s...</comment>',
6058
$component['repository']

config/berti.config.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,24 @@
1616
};
1717

1818
$container['data.components'] = function (Pimple\Container $container) {
19-
return React\Website\Data\components($container['github.client']);
19+
return React\Website\Data\components(
20+
$container['github.client'],
21+
$container['markdown.cache']
22+
);
2023
};
2124

2225
$container['data.components_by_category'] = function (Pimple\Container $container) {
2326
return React\Website\Data\components_by_category($container['data.components']);
2427
};
2528

29+
$container['data.releases'] = function (Pimple\Container $container) {
30+
return React\Website\Data\releases($container['data.components']);
31+
};
32+
33+
$container['data.releases_by_year'] = function (Pimple\Container $container) {
34+
return React\Website\Data\releases_by_year($container['data.releases']);
35+
};
36+
2637
$container['data.built_with'] = function (Pimple\Container $container) {
2738
return React\Website\Data\built_with($container['github.client']);
2839
};
@@ -145,6 +156,16 @@
145156
$container['data.components_by_category']
146157
);
147158

159+
$twig->addGlobal(
160+
'releases',
161+
$container['data.releases']
162+
);
163+
164+
$twig->addGlobal(
165+
'releases_by_year',
166+
$container['data.releases_by_year']
167+
);
168+
148169
$twig->addGlobal(
149170
'built_with',
150171
$container['data.built_with']

pages/changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog
2+
3+
The combined changelog for all ReactPHP components.

src/berti.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function github_url_generator(
4343

4444
/**
4545
* This function extends the `Berti\twig_renderer()` to dynamically switch
46-
* templates if a component repository is detected.
46+
* templates, eg. if a component repository is detected.
4747
*
4848
* It also passes additional component context data when rendering the template.
4949
*/
@@ -58,9 +58,11 @@ function template_renderer(
5858
/** @var \Symfony\Component\Finder\SplFileInfo $documentInput */
5959
$documentInput = $context['berti']['document']->input;
6060

61-
$path = dirname($documentInput->getRealPath());
61+
if ('changelog.md' === $documentInput->getRelativePathname()) {
62+
return $bertiRenderer('changelog.html.twig', $context);
63+
}
6264

63-
$repo = $repositoryDetector($path);
65+
$repo = $repositoryDetector(dirname($documentInput->getRealPath()));
6466

6567
if (!$repo) {
6668
return $bertiRenderer($name, $context);
@@ -79,14 +81,7 @@ function ($component) use ($repo) {
7981
return $bertiRenderer($name, $context);
8082
}
8183

82-
$process = new Process('git describe --tags', $path);
83-
$process->run();
84-
85-
// Might return HEAD if not in a tag checkout
86-
$version = trim($process->getOutput());
87-
8884
$context['component'] = $component;
89-
$context['component_version'] = $version;
9085

9186
$name = 'component.html.twig';
9287

src/data.php

Lines changed: 83 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,59 @@
33
namespace React\Website\Data;
44

55
use Github\Client;
6+
use Github\ResultPager;
7+
use Psr\Cache\CacheItemPoolInterface;
68

7-
function components(Client $client): array
9+
function components(Client $client, CacheItemPoolInterface $markdownCache): array
810
{
9-
return array_map(function ($component) use ($client) {
11+
return array_map(function ($component) use ($client, $markdownCache) {
1012
[$username, $repository] = explode('/', $component['repository']);
1113

12-
$component['versions'] = array_map(
13-
function ($tag) {
14-
return $tag['name'];
14+
$component['contributors'] = $client->repo()->contributors($username, $repository);
15+
$component['participation'] = $client->repo()->participation($username, $repository);
16+
17+
$releases = (new ResultPager($client))
18+
->fetchAll(
19+
$client->repo()->releases(),
20+
'all',
21+
[$username, $repository, ['per_page' => 100]]
22+
);
23+
24+
$releases = array_map(
25+
function (array $release) use ($client, $markdownCache, $component) {
26+
$cacheKey = 'gfm' . md5($component['repository'] . $release['body']);
27+
28+
$cacheItem = $markdownCache->getItem($cacheKey);
29+
30+
if ($cacheItem->isHit()) {
31+
$html = $cacheItem->get();
32+
} else {
33+
$html = $client->markdown()->render(
34+
$release['body'],
35+
'gfm',
36+
$component['repository']
37+
);
38+
39+
$cacheItem->set($html);
40+
$markdownCache->save($cacheItem);
41+
}
42+
43+
return [
44+
'version' => ltrim($release['tag_name'], 'v'),
45+
'tag' => $release['tag_name'],
46+
'date' => new \DateTimeImmutable($release['created_at']),
47+
'html' => $html,
48+
'url' => $release['html_url'],
49+
];
1550
},
16-
$client->repo()->tags($username, $repository)
51+
$releases
1752
);
1853

19-
$component['contributors'] = $client->repo()->contributors($username, $repository);
20-
$component['participation'] = $client->repo()->participation($username, $repository);
54+
usort($releases, function ($a, $b) {
55+
return \version_compare($b['version'], $a['version']);
56+
});
57+
58+
$component['releases'] = array_values($releases);
2159

2260
return array_merge(
2361
$client->repo()->show($username, $repository),
@@ -41,6 +79,43 @@ function components_by_category(array $components): array
4179
return $byCategory;
4280
}
4381

82+
function releases(array $components): array
83+
{
84+
$releases = [];
85+
86+
foreach ($components as $component) {
87+
foreach ($component['releases'] as $release) {
88+
$time = (int) $release['date']->format('U');
89+
90+
$releases[(PHP_INT_MAX - $time) . '-' . $component['repository']] = [
91+
'component' => $component['title'],
92+
'repository' => $component['repository'],
93+
] + $release;
94+
}
95+
}
96+
97+
ksort($releases, SORT_NATURAL);
98+
99+
return array_values($releases);
100+
}
101+
102+
function releases_by_year(array $releases): array
103+
{
104+
$byYear = [];
105+
106+
foreach ($releases as $release) {
107+
$year = (int) $release['date']->format('Y');
108+
109+
if (!isset($byYear[$year])) {
110+
$byYear[$year] = [];
111+
}
112+
113+
$byYear[$year][] = $release;
114+
}
115+
116+
return $byYear;
117+
}
118+
44119
function built_with(Client $client): array
45120
{
46121
return array_map(function ($component) use ($client) {

static-files/assets/main-critical.b3ce38ea4d05827d3ea9.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static-files/assets/main.2c3050a7d983f67a1210.js renamed to static-files/assets/main.c26014c6022c74ac7c57.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static-files/assets/manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"0.0da4d5f750914aa5280f.js": "0.0da4d5f750914aa5280f.js",
2+
"0.6a34aef149239e7a6f57.js": "0.6a34aef149239e7a6f57.js",
33
"icons.svg?hszqu": "f963ff7998d9564c268d2d32f08aeffc.svg",
44
"icons.ttf?hszqu": "a7d4d592f015c765bef62de7c96023be.ttf",
55
"icons.woff?hszqu": "b2f931638bc837a31b6e7f19c542a289.woff",
66
"main-critical.css": "main-critical.b3ce38ea4d05827d3ea9.css",
77
"main-critical.js": "main-critical.b3ce38ea4d05827d3ea9.js",
8-
"main.css": "main.2c3050a7d983f67a1210.css",
9-
"main.js": "main.2c3050a7d983f67a1210.js",
8+
"main.css": "main.c26014c6022c74ac7c57.css",
9+
"main.js": "main.c26014c6022c74ac7c57.js",
1010
"search.svg": "72dc47391c5751aa9e94d8d46846e31c.svg",
1111
"sourcesanspro-bold.woff": "be4ba3dd17008135675e945b630be8f6.woff",
1212
"sourcesanspro-regular.woff": "19ca4d35c8f94db0fa14422334dd2ad3.woff"

0 commit comments

Comments
 (0)