Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(changelog): bot detection #90

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions changelog/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function processPR($repoName, $pr)
return [$id, $data];
}

protected function shouldPRBeSkipped(array $pr)
protected function shouldPRBeSkipped(array $pr, $noBots = false)
{
if (preg_match('!^\d+(\.\d+(\.\d+))? ?(rc|beta|alpha)? ?(\d+)?$!i', $pr['title'])) {
return true;
Expand All @@ -89,6 +89,15 @@ protected function shouldPRBeSkipped(array $pr)
}
}
}

$prAuthor = $pr['author']['login'] ?? '';
if ($noBots && (str_contains($prAuthor, '[bot]')
|| str_contains($prAuthor, 'nextcloud-')
|| str_contains($prAuthor, 'dependabot')
|| str_contains($prAuthor, 'renovate'))) {
// ignore this bot-created PR
return true;
}
return false;
}

Expand Down Expand Up @@ -164,6 +173,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$repoName = $input->getArgument('repo');
$base = $input->getArgument('base');
$head = $input->getArgument('head');
$noBots = $input->getOption('no-bots');

$orgName = self::ORG_NAME;

Expand Down Expand Up @@ -289,15 +299,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

foreach ($commits as $commit) {
$noBots = $input->getOption('no-bots');
$name = $commit['commit']['author']['name'];
if ($noBots && (str_contains($name, '[bot]') || str_contains($name, 'nextcloud-'))) {
// ignore this bot-created commit
continue;
}
$login = $commit['author']['login'];
$fullMessage = $commit['commit']['message'];
list($firstLine,) = explode("\n", $fullMessage, 2);
if (substr($firstLine, 0, 20) === 'Merge pull request #') {
if ($noBots && (str_contains($login, '[bot]') || str_contains($login, 'nextcloud-'))) {
// ignore this bot-created commit
continue;
}

$firstLine = substr($firstLine, 20);
list($number,) = explode(" ", $firstLine, 2);
$pullRequests[] = $number;
Expand Down Expand Up @@ -337,7 +347,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
foreach ($response['data']['repository']['milestones']['nodes'] as $milestone) {
if ($milestone['title'] === \sprintf('Nextcloud %s', $milestoneToCheck)) {
foreach ($milestone['pullRequests']['nodes'] as $pr) {
if ($this->shouldPRBeSkipped($pr)) {
if ($this->shouldPRBeSkipped($pr, $noBots)) {
continue;
}
list($id, $data) = $this->processPR($repoName, $pr);
Expand Down Expand Up @@ -371,7 +381,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$milestone = $response['data']['repository']['milestone'];

foreach ($milestone['pullRequests']['nodes'] as $pr) {
if ($this->shouldPRBeSkipped($pr)) {
if ($this->shouldPRBeSkipped($pr, $noBots)) {
continue;
}
list($id, $data) = $this->processPR($repoName, $pr);
Expand All @@ -390,7 +400,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$query .= ' repository(owner: "' . $orgName . '", name: "' . $repoName . '") {';

foreach ($pullRequests as $pullRequest) {
$query .= "pr$pullRequest: pullRequest(number: $pullRequest) { number, title, labels(first: 10) { nodes { id, name } } },";
$query .= "pr$pullRequest: pullRequest(number: $pullRequest) { number, author { login }, title, labels(first: 10) { nodes { id, name } } },";
}

$query .= <<<'QUERY'
Expand All @@ -412,7 +422,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

foreach ($response['data']['repository'] as $pr) {
if ($this->shouldPRBeSkipped($pr)) {
if ($this->shouldPRBeSkipped($pr, $noBots)) {
continue;
}
list($id, $data) = $this->processPR($repoName, $pr);
Expand Down Expand Up @@ -499,16 +509,11 @@ function cmp($a, $b) {
$number = $data['number'];
$title = $data['title'];
$author = array_key_exists('author', $data) ? '@' . $data['author'] : '';
if ($author === '@backportbot-nextcloud') {
$author = '';
}
if ($author === '@dependabot-preview') {
$author = '';
}
if ($author === '@dependabot') {
$author = '';
}
if ($author === '@dependabot[bot]') {
if (str_contains($author, 'bot-nextcloud')
|| str_contains($author, 'nextcloud-')
|| str_contains($author, 'dependabot')
|| str_contains($author, 'renovate')
|| str_contains($author, '[bot]')) {
$author = '';
}
if ($prevAuthor !== $author) {
Expand Down