Skip to content

Commit 459a7f8

Browse files
committed
Fix gh sync issue
1 parent d2190e1 commit 459a7f8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Service/GitHubUserMigrationWorker.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public function setupWebHook(string $token, Package $package): null|bool|string
105105

106106
try {
107107
$hooks = $this->getHooks($token, $repoKey);
108+
$this->logger->debug(count($hooks).' existing hooks', ['hooks' => $hooks]);
108109

109110
$legacyHooks = array_values(array_filter(
110111
$hooks,
@@ -118,6 +119,10 @@ static function ($hook) {
118119
return $hook['name'] === 'web' && (strpos($hook['config']['url'], self::HOOK_URL) === 0 || strpos($hook['config']['url'], self::HOOK_URL_ALT) === 0);
119120
}
120121
));
122+
// sort shorter urls first as that should lead us to find the correct one first
123+
usort($currentHooks, static function ($a, $b) {
124+
return $a['config']['url'] <=> $a['config']['url'];
125+
});
121126

122127
$hookData = $this->getGitHubHookData();
123128
$hasValidHook = false;
@@ -126,13 +131,17 @@ static function ($hook) {
126131
$configWithoutSecret = $hook['config'];
127132
unset($configWithoutSecret['secret'], $expectedConfigWithoutSecret['secret']);
128133

134+
// we don't need to keep multiple valid hooks, once we have a valid one wipe the rest
135+
if ($hasValidHook) {
136+
continue;
137+
}
129138
if (
130139
$hook['updated_at'] < '2018-09-04T13:00:00'
131140
|| $hook['events'] != $hookData['events']
132141
|| $configWithoutSecret != $expectedConfigWithoutSecret
133142
|| !$hook['active']
134143
) {
135-
$this->logger->debug('Updating hook '.$hook['id']);
144+
$this->logger->debug('Updating hook '.$hook['id'], ['config' => $expectedConfigWithoutSecret]);
136145
$this->request($token, 'PATCH', 'repos/'.$repoKey.'/hooks/'.$hook['id'], $hookData);
137146
$changed = true;
138147
} elseif (!$package->isAutoUpdated()) {

0 commit comments

Comments
 (0)