Skip to content

Commit

Permalink
Un-inlining JS in GitHubPushTrigger/config.groovy
Browse files Browse the repository at this point in the history
  • Loading branch information
krystaltt committed Jul 25, 2024
1 parent 69254ce commit 9afbdf9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import com.cloudbees.jenkins.GitHubPushTrigger

tr {
td(colspan: 4) {
div(id: 'gh-hooks-warn')
def url = descriptor.getCheckMethod('hookRegistered').toCheckUrl()
def input = "input[name='${GitHubPushTrigger.class.getName().replace('.', '-')}']"

div(id: 'gh-hooks-warn',
'data-url': url,
'data-input': input
)
}
}

script(src:"${rootURL}${h.getResourcePath()}/plugin/github/js/warning.js")
script {
text("""
InlineWarning.setup({
id: 'gh-hooks-warn',
url: ${descriptor.getCheckMethod('hookRegistered').toCheckUrl()},
input: 'input[name="${GitHubPushTrigger.class.getName().replace(".", "-")}"]'
}).start();
""")
}
33 changes: 32 additions & 1 deletion src/main/webapp/js/warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ var InlineWarning = (function () {

exports.setup = function (opts) {
options = opts;

// Check if the URL needs concatenation
if (opts.url.includes("'+'")) {
// Manually concatenate the parts
let parts = opts.url.split("'+'");
options.url = parts.map(part => part.replace(/'/g, '')).join('');
} else {
options.url = opts.url;
}

return exports;
};

Expand Down Expand Up @@ -38,4 +48,25 @@ var InlineWarning = (function () {
};

return exports;
})();
})();

document.addEventListener('DOMContentLoaded', function() {
var warningElement = document.getElementById('gh-hooks-warn');

if (warningElement) {
var url = warningElement.getAttribute('data-url');
var input = warningElement.getAttribute('data-input');

if (url && input) {
InlineWarning.setup({
id: 'gh-hooks-warn',
url: url,
input: input
}).start();
} else {
console.error('URL or Input is null');
}
} else {
console.error('Element with ID "gh-hooks-warn" not found');
}
});

0 comments on commit 9afbdf9

Please sign in to comment.