Skip to content

Commit 27a1e6a

Browse files
authored
chore: include authors in advisories (#10703)
1 parent f0cad7b commit 27a1e6a

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

‎admin/create-release.php‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,68 @@
104104
exit(1);
105105
}
106106

107+
$output = [];
108+
exec(sprintf(
109+
'gh api --paginate repos/%s/compare/%s...master --jq %s 2>&1',
110+
$repo,
111+
escapeshellarg($previousTag),
112+
escapeshellarg('.commits[] | {sha: .sha, login: .author.login, coAuthored: (.commit.message | contains("Co-authored-by:"))}'),
113+
), $output, $exitCode);
114+
115+
if ($exitCode !== 0) {
116+
echo "Failed to fetch the commits from GitHub:\n";
117+
echo implode("\n", $output) . "\n";
118+
119+
exit(1);
120+
}
121+
122+
[$owner, $name] = explode('/', $repo);
123+
124+
$aiAssistant = '/\A(claude|copilot|cursor|codex)( agent| app| code| cli)? <|@(anthropic|cursor|openai)\.com>|\+copilot@users\.noreply\.github\.com>/i';
125+
126+
$coAuthoredShas = [];
127+
128+
foreach ($output as $line) {
129+
$commit = json_decode($line, true);
130+
131+
if (is_string($commit['login'])) {
132+
$contributors[$commit['login']] = true;
133+
}
134+
135+
if ($commit['coAuthored']) {
136+
$coAuthoredShas[] = $commit['sha'];
137+
}
138+
}
139+
140+
foreach (array_chunk($coAuthoredShas, 50) as $shas) {
141+
$objects = array_map(
142+
static fn (int $index, string $sha): string => sprintf('c%d: object(oid: "%s") { ... on Commit { authors(first: 10) { nodes { name email user { login } } } } }', $index, $sha),
143+
array_keys($shas),
144+
$shas,
145+
);
146+
147+
$output = [];
148+
exec(sprintf(
149+
'gh api graphql -f query=%s 2>&1',
150+
escapeshellarg(sprintf('query { repository(owner: "%s", name: "%s") { %s } }', $owner, $name, implode(' ', $objects))),
151+
), $output, $exitCode);
152+
153+
if ($exitCode !== 0) {
154+
echo "Failed to fetch the commit authors from GitHub:\n";
155+
echo implode("\n", $output) . "\n";
156+
157+
exit(1);
158+
}
159+
160+
foreach (json_decode(implode("\n", $output), true)['data']['repository'] ?? [] as $object) {
161+
foreach ($object['authors']['nodes'] ?? [] as $author) {
162+
if (is_string($author['user']['login'] ?? null) && preg_match($aiAssistant, sprintf('%s <%s>', $author['name'], $author['email'])) !== 1) {
163+
$contributors[$author['user']['login']] = true;
164+
}
165+
}
166+
}
167+
}
168+
107169
$contributors = array_filter(
108170
array_keys($contributors),
109171
static fn (string $login): bool => ! str_ends_with($login, '[bot]'),

0 commit comments

Comments
 (0)