Skip to content

Commit 9f06e7a

Browse files
committed
Redo options page a bit, add template replace option + title option, fix more stuff
1 parent c5a2fc9 commit 9f06e7a

File tree

3 files changed

+141
-71
lines changed

3 files changed

+141
-71
lines changed

src/content.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
let lastRefresh = (new Date()).getTime();
33
let jiraLogo = chrome.extension.getURL("images/jira.png");
44
let jiraUrl = undefined;
5-
let acceptanceStartString = 'h3. Acceptatiecriteria';
6-
let acceptanceEndString = 'h3. Notities';
5+
let acceptanceStartString = 'h3. Acceptance Criteria';
6+
let acceptanceEndString = 'h3. Notes';
77
let prTemplate = '';
8+
let prTemplateEnabled = true;
9+
let prTitleEnabled = true;
810
let NL = "\r";
911
chrome.storage.sync.get({
1012
jiraUrl: '',
11-
acceptanceStartString: 'h3. Acceptatiecriteria',
12-
acceptanceEndString: 'h3. Notities',
13-
prTemplate: '### Ticket' + NL +
13+
acceptanceStartString: 'h3. Acceptance Criteria',
14+
acceptanceEndString: 'h3. Notes',
15+
prTemplateEnabled: true,
16+
prTitleEnabled: true,
17+
prTemplate: '### Fix {{TICKETNUMBER}}' + NL +
1418
'Link to ticket: {{TICKETURL}}' + NL +
1519
NL +
16-
//'#### Description' + NL +
17-
//'{{DESCRIPTION}}' + NL +
18-
//NL +
1920
'### What has been done' + NL +
2021
'- ' + NL +
2122
'- ' + NL +
@@ -39,6 +40,9 @@ chrome.storage.sync.get({
3940
acceptanceStartString = items.acceptanceStartString;
4041
acceptanceEndString = items.acceptanceEndString;
4142
prTemplate = items.prTemplate;
43+
prTemplateEnabled = items.prTemplateEnabled;
44+
prTitleEnabled = items.prTitleEnabled;
45+
4246
if (jiraUrl == '') {
4347
console.error('GitHub Jira plugin could not load: Jira URL is not set.');
4448
return;
@@ -76,6 +80,7 @@ function checkPage() {
7680
handlePrPage();
7781
}, 200); //Small timeout for dom to finish setup
7882
}
83+
7984
if (url.match(/github\.com\/(.*)\/(.*)\/pulls/) != null) {
8085
//@todo PR overview page
8186
}
@@ -179,6 +184,10 @@ function handlePrPage() {
179184
}
180185

181186
function handlePrCreatePage() {
187+
if (prTitleEnabled == false && prTemplateEnabled == false) {
188+
return;
189+
}
190+
182191
let body = $("textarea#pull_request_body");
183192
if (body.attr('jira-loading') == 1) {
184193
return false; //Already loading
@@ -187,9 +196,8 @@ function handlePrCreatePage() {
187196

188197
let title = document.title;
189198
let ticketUrl = '**No linked ticket**';
190-
let ticketDescription = '...';
191199
let acceptanceList = '';
192-
200+
let ticketNumber = '?';
193201
if (title != undefined) {
194202
let titleMatch = title.match(/([a-zA-Z]+-[0-9]+)/);
195203
if (titleMatch) {
@@ -202,7 +210,9 @@ function handlePrCreatePage() {
202210
chrome.runtime.sendMessage(
203211
{query: 'getTicketInfo', jiraUrl: jiraUrl, ticketNumber: ticketNumber},
204212
function(result) {
205-
$('input#pull_request_title').val('['+ticketNumber.toUpperCase()+'] ' + result.fields.summary);
213+
if (prTitleEnabled) {
214+
$('input#pull_request_title').val('[' + ticketNumber.toUpperCase() + '] ' + result.fields.summary);
215+
}
206216

207217
let description = result.fields.description;
208218

@@ -218,5 +228,7 @@ function handlePrCreatePage() {
218228
}
219229
}
220230

221-
body.val(prTemplate.replace('{{TICKETURL}}', ticketUrl).replace('{{DESCRIPTION}}', ticketDescription).replace('{{ACCEPTANCE}}', acceptanceList));
231+
if (prTemplateEnabled) {
232+
body.val(prTemplate.replace('{{TICKETURL}}', ticketUrl).replace('{{TICKETNUMBER}}', ticketNumber).replace('{{ACCEPTANCE}}', acceptanceList));
233+
}
222234
}

src/options.html

Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,84 @@
88
</head>
99

1010
<body>
11-
<br/><br/>
12-
<H1>GitHub Jira integration plugin for Chrome</H1>
13-
<br/><br/>
14-
<span id="status"></span><br/>
15-
<label for="jiraUrl">Jira URL (without scheme or slashes):</label>
16-
<input type="url" id="jiraUrl"/><br/>
17-
<label for="acceptanceStartString">Acceptance criteria start string</label>
18-
<input type="text" id="acceptanceStartString"/><br/>
19-
<label for="acceptanceEndString">Acceptance criteria end string</label>
20-
<input type="text" id="acceptanceEndString"/><br/>
21-
<label for="prTemplate">New PR template:</label>
22-
<textarea style="width:300px; height:200px;" id="prTemplate"></textarea>
23-
<br /><br/>
24-
<button id="save">Save</button>
25-
<br />
26-
<button id="clear">Clear storage</button>
27-
<p>It's possible to show the acceptance criteria from your issues in your PR. You need to place the following tag in your template:</p>
28-
<p>### Acceptance criteria<br>{{ACCEPTANCE}}</p>
29-
30-
<a target="_blank" href="https://github.com/RobQuistNL/chrome-github-jira">
31-
<img
32-
style="position: absolute; top: 0; right: 0; border: 0;"
33-
src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67"
34-
alt="Fork me on GitHub"
35-
data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png">
36-
</a>
11+
<a href="https://github.com/RobQuistNL/chrome-github-jira">Source / GitHub / Issues</a>
12+
<br/>
13+
<h3>Settings</h3>
14+
<table>
15+
<tr>
16+
<td><label for="jiraUrl">Jira URL (without scheme or slashes):</label></td>
17+
<td><input type="url" id="jiraUrl"/></td>
18+
</tr>
19+
20+
<tr>
21+
<td>
22+
<label for="acceptanceStartString">Acceptance criteria start string</label>
23+
</td>
24+
<td>
25+
<input type="text" id="acceptanceStartString"/>
26+
</td>
27+
</tr>
28+
29+
<tr>
30+
<td>
31+
<label for="acceptanceEndString">Acceptance criteria end string</label>
32+
</td>
33+
<td>
34+
<input type="text" id="acceptanceEndString"/>
35+
</td>
36+
</tr>
37+
38+
<tr>
39+
<td>
40+
<label for="prTitleEnabled">Automatically insert title based on ticket number</label>
41+
</td>
42+
<td>
43+
<input type="checkbox" id="prTitleEnabled" value="1"/>
44+
</td>
45+
</tr>
46+
47+
<tr>
48+
<td>
49+
<label for="prTemplateEnabled">Automatically insert template in new PR</label>
50+
</td>
51+
<td>
52+
<input type="checkbox" id="prTemplateEnabled" value="1"/>
53+
</td>
54+
</tr>
55+
56+
<tr>
57+
<td colspan="2">
58+
<label for="prTemplate">New PR template:</label>
59+
</td>
60+
</tr>
61+
<tr>
62+
<td colspan="2">
63+
<textarea style="width:300px; height:200px;" id="prTemplate"></textarea>
64+
</td>
65+
</tr>
66+
67+
<tr>
68+
<td colspan="2">
69+
<h2 id="status" style="display:none;background-color:rgb(57,255,59);">Options saved.</h2>
70+
</td>
71+
</tr>
72+
73+
<tr>
74+
<td>
75+
<button id="save">Save</button>
76+
</td>
77+
<td>
78+
<button id="clear">Clear storage</button>
79+
</td>
80+
</tr>
81+
</table>
82+
83+
<h3>Available template variables:</h3>
84+
<table>
85+
<tr><td><pre>{{ACCEPTANCE}}</pre></td> <td>The acceptance criteria as parsed from the ticket</td></tr>
86+
<tr><td><pre>{{TICKETURL}}</pre></td> <td>Direct URL to the Jira ticket</td></tr>
87+
<tr><td><pre>{{TICKETNUMBER}}</pre></td> <td>The ticket in XXX-123 format</td></tr>
88+
</table>
3789

3890
<script type="text/javascript" src="options.js"></script>
3991
</body>

src/options.js

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
function loadOptions() {
2-
var NL = "\r";
2+
let NL = "\r";
33
chrome.storage.sync.get({
44
jiraUrl: '',
5-
acceptanceStartString: 'h3. Acceptatiecriteria',
6-
acceptanceEndString: 'h3. Notities',
7-
prTemplate: '### Ticket' + NL +
8-
'Link to ticket: {{TICKETURL}}' + NL +
9-
NL +
10-
//'#### Description' + NL +
11-
//'{{DESCRIPTION}}' + NL +
12-
//NL +
13-
'### What has been done' + NL +
14-
'- ' + NL +
15-
'- ' + NL +
16-
NL +
17-
'### How to test' + NL +
18-
'- ' + NL +
19-
'- ' + NL +
20-
NL +
21-
'### Acceptance criteria' + NL +
22-
'{{ACCEPTANCE}}' +
23-
NL +
24-
'### Todo' + NL +
25-
'- [ ] ' + NL +
26-
'- [ ] ' + NL +
27-
NL +
28-
'### Notes' + NL +
29-
'- ' + NL +
30-
'- '
5+
acceptanceStartString: 'h3. Acceptance Criteria',
6+
acceptanceEndString: 'h3. Notes',
7+
prTemplateEnabled: true,
8+
prTitleEnabled: true,
9+
prTemplate: '### Fix {{TICKETNUMBER}}' + NL +
10+
'Link to ticket: {{TICKETURL}}' + NL +
11+
NL +
12+
'### What has been done' + NL +
13+
'- ' + NL +
14+
'- ' + NL +
15+
NL +
16+
'### How to test' + NL +
17+
'- ' + NL +
18+
'- ' + NL +
19+
NL +
20+
'### Acceptance criteria' + NL +
21+
'{{ACCEPTANCE}}' +
22+
NL +
23+
'### Todo' + NL +
24+
'- [ ] ' + NL +
25+
'- [ ] ' + NL +
26+
NL +
27+
'### Notes' + NL +
28+
'- ' + NL +
29+
'- '
3130
}, function(items) {
3231
document.getElementById('jiraUrl').value = items.jiraUrl;
3332
document.getElementById('acceptanceStartString').value = items.acceptanceStartString;
3433
document.getElementById('acceptanceEndString').value = items.acceptanceEndString;
3534
document.getElementById('prTemplate').value = items.prTemplate;
35+
document.getElementById("prTemplateEnabled").checked = items.prTemplateEnabled;
36+
document.getElementById("prTitleEnabled").checked = items.prTitleEnabled;
3637
});
3738
}
3839

@@ -41,20 +42,25 @@ function saveOptions() {
4142
jiraUrl: document.getElementById("jiraUrl").value,
4243
acceptanceStartString: document.getElementById("acceptanceStartString").value,
4344
acceptanceEndString: document.getElementById("acceptanceEndString").value,
44-
prTemplate: document.getElementById("prTemplate").value
45+
prTemplate: document.getElementById("prTemplate").value,
46+
prTemplateEnabled: document.getElementById("prTemplateEnabled").checked,
47+
prTitleEnabled: document.getElementById("prTitleEnabled").checked,
4548
}, function() {
4649
// Update status to let user know options were saved.
47-
var status = document.getElementById('status');
48-
status.textContent = 'Options saved.';
50+
let status = document.getElementById('status');
51+
status.style.display = 'block';
4952
window.scrollTo(0, 0);
5053
setTimeout(function() {
51-
status.textContent = '';
52-
}, 750);
54+
status.style.display = 'none';
55+
}, 2000);
5356
});
5457
}
5558

5659
function clearOptions() {
57-
chrome.storage.sync.remove(['jiraUrl', 'prTemplate']);
60+
chrome.storage.sync.remove([
61+
'jiraUrl', 'prTemplate', 'acceptanceStartString', 'acceptanceEndString', 'prTemplateEnabled',
62+
'prTitleEnabled'
63+
]);
5864
loadOptions();
5965
saveOptions();
6066
}

0 commit comments

Comments
 (0)