Skip to content

Commit 0d823ca

Browse files
authored
Merge pull request #4 from acoven/master
Combines previous pull request with new changes to support "Spent"
2 parents 35fbebb + 2da8e9e commit 0d823ca

File tree

3 files changed

+49
-26
lines changed

3 files changed

+49
-26
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,19 @@ A Chrome Extension to add [SCRUM](https://en.wikipedia.org/wiki/Scrum_(software_
88

99
You notes/PR/issues should have a title like `(2) My issue title` and the "(2)"
1010
will be converted in a nice tag. Also all projects lists will have the total count
11-
of story points in them next to the count of cards. That's it.
11+
of story points in them next to the count of cards.
12+
13+
## To Install
14+
15+
1. Download all the files in the directory.
16+
1. Launch Chrome
17+
1. Open chrome://extensions/
18+
1. Make sure "Developer mode" is CHECKED
19+
1. Click "Load unpacked extension..."
20+
1. Select the directory you downloaded all the files to.
21+
22+
**GitHub Projects Story Points** should now appear in your Extensions lists
23+
24+
1. Reload the extension page or click the "Reload" link under **GitHub Projects Story Points**
25+
1. Open your Projects or Issues pages in your Repo on GitHub.com
26+
1. You should now see any items with (#) preceeding the title added up as (# points)

github-storypoints.js

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(function (d, w) {
22
'use strict';
33

4-
var pointsRegEx = /^\(([\d\.]+)\)(.+)/i;
4+
var pointsRegEx = /^(\(([\d\.]+)\)\s*)?(.+?)(\s*\[([\d\.]+)\])?$/im; // new RegExp("^(\(([\d\.]+)\))?(.+)(\[([\d\.]+)\])?$", "i"); // Was: /^\(([\d\.]+)\)(.+)/i;
55

66
var debounce = function (func, wait, immediate) {
77
var timeout;
@@ -18,6 +18,10 @@ var debounce = function (func, wait, immediate) {
1818
};
1919
};
2020

21+
var pluralize = (value) => (
22+
value === 1 ? '' : 's'
23+
);
24+
2125
var resetStoryPointsForColumn = (column) => {
2226
const customElements = Array.from(column.getElementsByClassName('github-project-story-points'));
2327
for (let e of customElements) {
@@ -31,15 +35,14 @@ var resetStoryPointsForColumn = (column) => {
3135
}
3236
};
3337

34-
var titleWithPoints = (title, points) => (`
35-
<span class="github-project-story-points counter">
36-
<span style="display:none">(</span>${points}<span style="display:none">)</span>
37-
</span>
38-
${title}
39-
`);
38+
var titleWithPoints = (title, points, spent) => (
39+
`<span style="font-weight:bold">${title}</span><br \>
40+
<span class="github-project-story-points counter"
41+
style="font-size:xx-small">${spent} spent of ${points}</span>`
42+
);
4043

41-
var titleWithTotalPoints = (title, points) => (`${title}
42-
<small class="github-project-story-points">(${points} ${points === 1 ? 'point' : 'points'})</small>`
44+
var titleWithTotalPoints = (title, points, spent) => (
45+
`${title}<span class="github-project-story-points" style="font-size:xx-small"> item${pluralize(title)} (${spent} spent of ${points})</span>`
4346
);
4447

4548
var addStoryPointsForColumn = (column) => {
@@ -65,30 +68,34 @@ var addStoryPointsForColumn = (column) => {
6568
pointsRegEx.exec(titleElement.innerText) ||
6669
[null, '0', titleElement.innerText]
6770
);
68-
const storyPoints = parseFloat(story[1]);
69-
const storyTitle = story[2];
71+
const storyPoints = parseFloat(story[2]) || 0;
72+
const storyTitle = story[3];
73+
const spentPoints = parseFloat(story[5]) || 0;
7074
return {
7175
element: card,
7276
titleElement,
7377
title,
7478
titleNoPoints: storyTitle,
7579
storyPoints,
80+
spentPoints,
7681
};
7782
});
7883
const columnCountElement = column.getElementsByClassName('js-column-card-count')[0];
79-
const columnStoryPoints = columnCards.reduce((acc, card) => acc + card.storyPoints, 0);
80-
81-
// Apply DOM changes
82-
if (columnStoryPoints) {
83-
columnCountElement.innerHTML = titleWithTotalPoints(columnCards.length, columnStoryPoints);
84-
}
8584

85+
let columnStoryPoints = 0;
86+
let columnSpentPoints = 0;
8687
for (let card of columnCards) {
87-
if (card.storyPoints) {
88+
columnStoryPoints += card.storyPoints;
89+
columnSpentPoints += card.spentPoints;
90+
if (card.storyPoints || card.spentPoints) {
8891
card.titleElement.dataset.gpspOriginalContent = card.title;
89-
card.titleElement.innerHTML = titleWithPoints(card.titleNoPoints, card.storyPoints);
92+
card.titleElement.innerHTML = titleWithPoints(card.titleNoPoints, card.storyPoints, card.spentPoints);
9093
}
9194
}
95+
// Apply DOM changes:
96+
if (columnStoryPoints || columnSpentPoints) {
97+
columnCountElement.innerHTML = titleWithTotalPoints(columnCards.length, columnStoryPoints, columnSpentPoints);
98+
}
9299
};
93100

94101
var resets = [];
@@ -103,7 +110,7 @@ var start = debounce(() => {
103110
const projects = d.getElementsByClassName('project-columns-container');
104111
if (projects.length > 0) {
105112
const project = projects[0];
106-
const columns = Array.from(project.getElementsByClassName('col-project-custom'));
113+
const columns = Array.from(project.getElementsByClassName('js-project-column')); // Was 'col-project-custom', but that's gitenterprise; github.com is 'project-column', fortunately, both have 'js-project-column'
107114
for (let column of columns) {
108115
const addStoryPoints = ((c) => debounce(() => {
109116
resetStoryPointsForColumn(c);
@@ -127,10 +134,11 @@ var start = debounce(() => {
127134
pointsRegEx.exec(titleElement.innerText) ||
128135
[null, '0', titleElement.innerText]
129136
);
130-
const storyPoints = parseFloat(story[1]);
131-
const storyTitle = story[2];
132-
if (storyPoints) {
133-
titleElement.innerHTML = titleWithPoints(storyTitle, storyPoints);
137+
const storyPoints = parseFloat(story[2]) || 0;
138+
const storyTitle = story[3];
139+
const spentPoints = parseFloat(story[5]) || 0;
140+
if (storyPoints || spentPoints) {
141+
titleElement.innerHTML = titleWithPoints(storyTitle, storyPoints, spentPoints);
134142
}
135143
}
136144
}, 50);

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"content_scripts": [
88
{
99
"matches": [
10-
"https://github.com/*"
10+
"https://*/*/issues/*", "https://*/*/issues", "https://*/*/projects/*"
1111
],
1212
"include_globs": [
1313
"*/projects/*",

0 commit comments

Comments
 (0)