@@ -105,6 +105,7 @@ public function setupWebHook(string $token, Package $package): null|bool|string
105
105
106
106
try {
107
107
$ hooks = $ this ->getHooks ($ token , $ repoKey );
108
+ $ this ->logger ->debug (count ($ hooks ).' existing hooks ' , ['hooks ' => $ hooks ]);
108
109
109
110
$ legacyHooks = array_values (array_filter (
110
111
$ hooks ,
@@ -118,6 +119,10 @@ static function ($hook) {
118
119
return $ hook ['name ' ] === 'web ' && (strpos ($ hook ['config ' ]['url ' ], self ::HOOK_URL ) === 0 || strpos ($ hook ['config ' ]['url ' ], self ::HOOK_URL_ALT ) === 0 );
119
120
}
120
121
));
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
+ });
121
126
122
127
$ hookData = $ this ->getGitHubHookData ();
123
128
$ hasValidHook = false ;
@@ -126,13 +131,17 @@ static function ($hook) {
126
131
$ configWithoutSecret = $ hook ['config ' ];
127
132
unset($ configWithoutSecret ['secret ' ], $ expectedConfigWithoutSecret ['secret ' ]);
128
133
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
+ }
129
138
if (
130
139
$ hook ['updated_at ' ] < '2018-09-04T13:00:00 '
131
140
|| $ hook ['events ' ] != $ hookData ['events ' ]
132
141
|| $ configWithoutSecret != $ expectedConfigWithoutSecret
133
142
|| !$ hook ['active ' ]
134
143
) {
135
- $ this ->logger ->debug ('Updating hook ' .$ hook ['id ' ]);
144
+ $ this ->logger ->debug ('Updating hook ' .$ hook ['id ' ], [ ' config ' => $ expectedConfigWithoutSecret ] );
136
145
$ this ->request ($ token , 'PATCH ' , 'repos/ ' .$ repoKey .'/hooks/ ' .$ hook ['id ' ], $ hookData );
137
146
$ changed = true ;
138
147
} elseif (!$ package ->isAutoUpdated ()) {
0 commit comments