Skip to content

Instantly share code, notes, and snippets.

@Funi1234
Last active November 10, 2022 12:48
Show Gist options
  • Save Funi1234/8fd6be0c8da1c21acd9756029e2b0151 to your computer and use it in GitHub Desktop.
Save Funi1234/8fd6be0c8da1c21acd9756029e2b0151 to your computer and use it in GitHub Desktop.
JIRA PR Generator for our Git PR template
// ==UserScript==
// @name JIRA PR Generator
// @namespace http://tampermonkey.net/
// @version 0.3
// @description JIRA PR Generator
// @author Funi1234
// @match https://kargo1.atlassian.net/browse/*
// @icon https://toppng.com/uploads/thumbnail/jira-software-logo-jira-software-logo-11562914188uzadsiuqmj.png
// @grant none
// ==/UserScript==
(function () {
'use strict';
var url = window.location.href
var jira = window.location.pathname.split("/").pop()
// Add a new button to a JIRA page after its loaded (3 seconds)
setTimeout(function () {
var buttonHTML = document.createElement('div');
buttonHTML.innerHTML = '<div role="presentation"><button tabindex="0" type="button" aria-label="Add Checklist"><img title="Checklist" src="https://issue-checklist-free-1.herocoders.com/images/issue-checklist-icon-grey.svg" width="24px" height="24px" /></button></div>'
var buttonLocation = document.getElementsByClassName("_ca0q1y44")[0]
buttonLocation.appendChild(buttonHTML);
buttonHTML.addEventListener('click', event => {
var changed = ""
var newChange = prompt(jira + " Proposed Changes", "");
while (newChange !== null && newChange !== "") {
changed += "- " + newChange + "\n";
newChange = prompt(jira + " Proposed Changes", "");
}
var schema = ""
var newSchema = prompt(jira + " Schema Updates", "");
while (newSchema !== null && newSchema !== "") {
schema += "- " + newSchema + "\n";
newSchema = prompt(jira + " Schema Updates", "");
}
var testing = ""
var newTesting = prompt(jira + " Testing Steps", "");
while (newTesting !== null && newTesting !== "") {
testing += "- " + newTesting + "\n";
newTesting = prompt(jira + " Schema Updates", "");
}
var impacted = ""
var newImpacted = prompt(jira + " Impacted Areas", "");
while (newImpacted !== null && newImpacted !== "") {
impacted += "- " + newImpacted + "\n";
newImpacted = prompt(jira + " Impacted Areas", "");
}
generate(changed, schema, testing, impacted);
});
}, 3000);
// Display the popup
const display = function (title, body) {
const css = `#container {
left: 0px;
top: 0px;
width: 100%;
height: 100%;
position: absolute;
background-color: rgba(22,22,22,0.5);
}
#container:target {
visibility: visible;
display: block;
}
.reveal-modal {
background:#e1e1e1;
margin: 0 auto;
width:600px;
position:relative;
z-index:41;
top: 20%;
padding:30px;
-webkit-box-shadow:0 0 10px rgba(0,0,0,0.4);
-moz-box-shadow:0 0 10px rgba(0,0,0,0.4);
box-shadow:0 0 10px rgba(0,0,0,0.4);
}
`
var HTMLBody, head, style;
HTMLBody = document.getElementsByTagName('body')[0];
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
var popupHTML = document.createElement('div');
popupHTML.id = 'container'
popupHTML.innerHTML = `<div id="jira-template-modal" class="reveal-modal">
<h3>${title}</h3>
<p>
<textarea rows="30" cols="70">${body}</textarea>
</p>
<a href="javascript:location.reload(true)">X</a>
</div>`
HTMLBody.appendChild(popupHTML)
}
// Generate the template
const generate = function (changed, schema, testing, impacted) {
var title = jira + " - " + document.querySelector('[data-test-id="issue.views.issue-base.foundation.summary.heading"]').innerText
var related = `
#πŸ“Œ - Related Issue
- [${jira}](${url})
`
var changes = `
# 🏹 - Proposed Changes
${changed}
`
var schemaUpdates = `
# 🚨 - Schema Updates
${schema}
`
var testingUpdates = `
# πŸ”¬ - Testing
${testing}
`
var impactedAreas = `
# 🚧 - Impacted Areas
${impacted}
`
var template = ``
template += related
if (changed !== null && changed !== "") { template += changes }
if (schema !== null && schema !== "") { template += schemaUpdates }
if (testing !== null && testing !== "") { template += testingUpdates }
if (impacted !== null && impacted !== "") { template += impactedAreas }
template += `# 🎯 - Checklist
- [x] Tested locally
- [x] Unit Test
- [x] Add milestone, labels, reviewers
# πŸ“Έ - Screenshots
Original | Updated
:---------------|-------------------:
** original screenshot ** | ** updated screenshot **
`
console.log(title);
console.log(template);
display(title, template)
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment