Skip to content

Commit e7c8610

Browse files
authored
Merge pull request #127 from nextcloud/fix/formats
2 parents 81e25cf + c5e75d7 commit e7c8610

File tree

1 file changed

+63
-29
lines changed

1 file changed

+63
-29
lines changed

changelog/index.php

Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected function processPR($repoName, $pr)
6868
{
6969
$title = $this->cleanTitle($pr['title']);
7070
$id = '#' . $pr['number'];
71-
if ($repoName !== 'server') {
71+
if ($repoName !== self::REPO_SERVER) {
7272
$id = $repoName . $id;
7373
}
7474
$data = [
@@ -163,7 +163,7 @@ protected function getReposToIterate($head = 'master')
163163
// Return repos names
164164
$orgRepositories = array_map(fn($repo): string => $repo['name'], $results);
165165
} catch (\Exception $e) {
166-
throw new Exception('Unable to fetch the github repositories list.');
166+
throw new Exception('Unable to fetch the github repositories list: ' . $e->getMessage());
167167
}
168168

169169
return [...$reposToIterate, ...array_intersect($orgRepositories, $shippedApps)];
@@ -514,40 +514,48 @@ protected function execute(InputInterface $input, OutputInterface $output)
514514
$output->writeln("");
515515
$output->writeln("<h4>Changes</h4>");
516516
$output->writeln("<ul>");
517-
foreach ($prTitles['closed'] as $id => $data) {
518-
$repoName = $data['repoName'];
519-
$number = $data['number'];
520-
$title = $data['title'];
521-
$output->writeln("\t<li><a href=\"https://github.com/$orgName/$repoName/pull/$number\">$title ($repoName#$number)</a></li>");
517+
$closedPRs = $this->groupPRsByRepo($prTitles['closed']);
518+
foreach ($closedPRs as $repo => $prs) {
519+
$output->writeln("<li><strong><a href=\"https://github.com/$orgName/$repo\">$repo</a></strong><ul>");
520+
foreach ($prs as $id => $data) {
521+
$repoName = $data['repoName'];
522+
$number = $data['number'];
523+
$title = $data['title'];
524+
$output->writeln("\t<li><a href=\"https://github.com/$orgName/$repoName/pull/$number\">$title ($repoName#$number)</a></li>");
525+
}
526+
$output->writeln("</ul></li>");
522527
}
523528
$output->writeln("</ul>");
524-
$count = count($prTitles['pending']);
525-
if ($count > 0) {
526-
$output->writeln("<error>$count pending PRs not printed - maybe the release is not ready yet</error>");
527-
}
528529
break;
529530
case 'forum':
530-
foreach ($prTitles['closed'] as $id => $data) {
531-
$repoName = $data['repoName'];
532-
$number = $data['number'];
533-
$title = $data['title'];
534-
$output->writeln("* [$title ($repoName#$number)](https://github.com/$orgName/$repoName/pull/$number)");
535-
}
536-
$count = count($prTitles['pending']);
537-
if ($count > 0) {
538-
$output->writeln("<error>$count pending PRs not printed - maybe the release is not ready yet</error>");
531+
// Making it a second heading as the first one is the title of the post
532+
$output->writeln("## Nextcloud " . $milestoneToCheck);
533+
$closedPRs = $this->groupPRsByRepo($prTitles['closed']);
534+
foreach ($closedPRs as $repo => $prs) {
535+
$output->writeln("\n### [$repo](https://github.com/$orgName/$repo)");
536+
foreach ($prs as $id => $data) {
537+
$repoName = $data['repoName'];
538+
$number = $data['number'];
539+
$title = $this->escapeMarkdown($data['title']);
540+
$output->writeln("* [$title ($repoName#$number)](https://github.com/$orgName/$repoName/pull/$number)");
541+
}
539542
}
540543
break;
541544
case 'markdown':
542545
default:
543-
foreach ($prTitles['closed'] as $id => $data) {
544-
$repoName = $data['repoName'];
545-
$number = $data['number'];
546-
$title = $data['title'];
547-
if ($repoName === 'server') {
548-
$output->writeln("* #$number");
549-
} else {
550-
$output->writeln("* $orgName/$repoName#$number");
546+
$output->writeln("## Nextcloud " . $milestoneToCheck);
547+
$closedPRs = $this->groupPRsByRepo($prTitles['closed']);
548+
foreach ($closedPRs as $repo => $prs) {
549+
$output->writeln("\n### [$repo](https://github.com/$orgName/$repo)");
550+
foreach ($prs as $id => $data) {
551+
$repoName = $data['repoName'];
552+
$number = $data['number'];
553+
$title = $data['title'];
554+
if ($repoName === self::REPO_SERVER) {
555+
$output->writeln("* #$number");
556+
} else {
557+
$output->writeln("* $orgName/$repoName#$number");
558+
}
551559
}
552560
}
553561

@@ -592,7 +600,7 @@ function ($a, $b) {
592600
$output->writeln("* $author");
593601
$prevAuthor = $author;
594602
}
595-
if ($repoName === 'server') {
603+
if ($repoName === self::REPO_SERVER) {
596604
$output->writeln(" * [ ] #$number");
597605
} else {
598606
$output->writeln(" * [ ] $orgName/$repoName#$number");
@@ -606,6 +614,32 @@ function ($a, $b) {
606614
# TODO
607615
#$client->removeCache();
608616
}
617+
618+
function escapeMarkdown(string $text): string {
619+
// Escape characters that break markdown
620+
$escapeChars = ['*', '_', '~', '`', '[', ']', '(', ')', '#', '+', '-', '!', '|'];
621+
foreach ($escapeChars as $char) {
622+
$text = str_replace($char, '\\' . $char, $text);
623+
}
624+
return $text;
625+
}
626+
627+
function groupPRsByRepo($prs) {
628+
$grouped = [];
629+
foreach ($prs as $pr) {
630+
$repo = $pr['repoName'];
631+
$grouped[$repo][] = $pr;
632+
}
633+
ksort($grouped);
634+
635+
// Put server on top
636+
if (isset($grouped[self::REPO_SERVER])) {
637+
$serverPRs = $grouped[self::REPO_SERVER];
638+
unset($grouped[self::REPO_SERVER]);
639+
$grouped = array_merge([self::REPO_SERVER => $serverPRs], $grouped);
640+
}
641+
return $grouped;
642+
}
609643
}
610644

611645
$application = new Application();

0 commit comments

Comments
 (0)