-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into JENKINS-70695
- Loading branch information
Showing
10 changed files
with
101 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
plugin/src/main/resources/org/jenkinsci/plugins/workflow/cps/Snippetizer/handle-prototype.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
function handlePrototype(url, crumb) { | ||
buildFormTree(document.forms.config); | ||
// TODO JSON.stringify fails in some circumstances: https://gist.github.com/jglick/70ec4b15c1f628fdf2e9 due to Array.prototype.toJSON | ||
// TODO simplify when Prototype.js is removed | ||
const json = Object.toJSON ? Object.toJSON(JSON.parse(document.forms.config.elements.json.value).prototype) : JSON.stringify(JSON.parse(document.forms.config.elements.json.value).prototype); | ||
if (!json) { | ||
return; // just a separator | ||
} | ||
|
||
const headers = new Headers(); | ||
headers.append("Content-Type", "application/x-www-form-urlencoded"); | ||
headers.append("Jenkins-Crumb", crumb); | ||
|
||
fetch(url, { | ||
method: "POST", | ||
headers: headers, | ||
body: "json=" + encodeURIComponent(json), | ||
|
||
}) | ||
.then(response => { | ||
if (response.ok) { | ||
response.text().then((responseText) => { | ||
document.getElementById('prototypeText').value = responseText; | ||
copybutton = document.querySelector('.jenkins-copy-button'); | ||
copybutton.setAttribute("text", responseText); | ||
copybutton.classList.remove('jenkins-hidden'); | ||
}); | ||
} | ||
}) | ||
.catch(error => { | ||
console.error('Fetch error:', error); | ||
}); | ||
} | ||
|
||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
|
||
const generatePipelineScript = document.getElementById("generatePipelineScript"); | ||
const url = generatePipelineScript.getAttribute("data-url"); | ||
const crumb = generatePipelineScript.getAttribute("data-crumb"); | ||
generatePipelineScript.onclick = (_) => { | ||
handlePrototype(url, crumb); | ||
return false; | ||
}; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters