From 9afbdf9c09c74db4dec06ed6b4785201cb105ef7 Mon Sep 17 00:00:00 2001 From: krystaltt Date: Wed, 24 Jul 2024 20:52:48 -0700 Subject: [PATCH] Un-inlining JS in GitHubPushTrigger/config.groovy --- .../jenkins/GitHubPushTrigger/config.groovy | 17 ++++------ src/main/webapp/js/warning.js | 33 ++++++++++++++++++- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/main/resources/com/cloudbees/jenkins/GitHubPushTrigger/config.groovy b/src/main/resources/com/cloudbees/jenkins/GitHubPushTrigger/config.groovy index c9a140f5c..768800958 100644 --- a/src/main/resources/com/cloudbees/jenkins/GitHubPushTrigger/config.groovy +++ b/src/main/resources/com/cloudbees/jenkins/GitHubPushTrigger/config.groovy @@ -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(); -""") -} diff --git a/src/main/webapp/js/warning.js b/src/main/webapp/js/warning.js index d3123bc38..994242240 100644 --- a/src/main/webapp/js/warning.js +++ b/src/main/webapp/js/warning.js @@ -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; }; @@ -38,4 +48,25 @@ var InlineWarning = (function () { }; return exports; -})(); \ No newline at end of file +})(); + +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'); + } +}); \ No newline at end of file