Skip to content

Commit 50d56ef

Browse files
committed
Link to GitHub when Webhook creation fails with 409
If the Webhook creation fails due to a conflict (i.e. it already exists) the error message now links to the Webhook's page on GitHub, allowing the admin to easily review it.
1 parent e5d38a9 commit 50d56ef

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

SourceGithub/SourceGithub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ public function route_webhook( $p_request, $p_response, $p_args ) {
124124

125125
if( $t_id ) {
126126
# Webhook already exists for this URL
127+
# Set the Github URL so user can easily link to it
128+
$t_hook->web_url = "https://github.com/$t_username/$t_reponame/settings/hooks/" . $t_hook->id;
127129
return $p_response
128130
->withStatus( HTTP_STATUS_CONFLICT,
129131
plugin_lang_get( 'webhook_exists', 'SourceGithub' ) )

SourceGithub/files/sourcegithub.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,19 @@ jQuery(document).ready(function($) {
3535
},
3636
error: function(xhr, textStatus, errorThrown) {
3737
status_icon.removeClass("fa-check green").addClass("fa-exclamation-triangle red");
38-
status_message.text(errorThrown);
38+
39+
var details = JSON.parse(xhr.responseText);
40+
if (xhr.status === 409) {
41+
status_message.html(
42+
'<a href="' + details.web_url + '">' + errorThrown + '</a>'
43+
);
44+
} else {
45+
status_message.text(errorThrown);
46+
}
47+
3948
console.error(
4049
'Webhook creation failed',
41-
{ error: errorThrown, details: JSON.parse(xhr.responseText), request: this.url }
50+
{ error: errorThrown, details: details, request: this.url, x: textStatus }
4251
);
4352
}
4453
});

0 commit comments

Comments
 (0)