Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit b89a8b2

Browse files
author
Isaac Würth
committed
Add milestone report
1 parent e92ae8b commit b89a8b2

File tree

5 files changed

+229
-3
lines changed

5 files changed

+229
-3
lines changed

package-lock.json

Lines changed: 19 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gtt-report.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,23 @@ new Promise(resolve => {
284284
.then(() => resolve());
285285
}))
286286

287+
// get milestones
288+
.then(() => new Promise(resolve => {
289+
if (!config.get('query').includes('milestones')) return resolve();
290+
291+
Cli.list(`${Cli.fetch} Fetching milestones`);
292+
293+
reports
294+
.forEach((report, done) => {
295+
report.getMilestones()
296+
.catch(error => done(error))
297+
.then(() => done());
298+
})
299+
.catch(error => Cli.x(`could not fetch milestones.`, error))
300+
.then(() => Cli.mark())
301+
.then(() => resolve());
302+
}))
303+
287304
// merge reports
288305
.then(() => new Promise(resolve => {
289306
Cli.list(`${Cli.merge} Merging reports`);
@@ -320,6 +337,17 @@ new Promise(resolve => {
320337
.then(() => resolve());
321338
}))
322339

340+
// process milestones
341+
.then(() => new Promise(resolve => {
342+
if (!config.get('query').includes('milestones') || master.milestones.length === 0) return resolve();
343+
344+
Cli.bar(`${Cli.process}️️ Processing milestones`, master.milestones.length);
345+
master.processMilestones(() => Cli.advance())
346+
.then(() => Cli.mark())
347+
.catch(error => Cli.x(`could not process milestones.`, error))
348+
.then(() => resolve());
349+
}))
350+
323351
// make report
324352
.then(() => new Promise(resolve => {
325353
if (master.issues.length === 0 && master.mergeRequests.length === 0)

src/models/milestone.js

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
const _ = require('underscore');
2+
const moment = require('moment');
3+
4+
const hasTimes = require('./hasTimes');
5+
const Issue = require('./issue')
6+
7+
/**
8+
* issue model
9+
*/
10+
class milestone extends hasTimes {
11+
constructor(config, data = {}) {
12+
super(config);
13+
this.data = data;
14+
this.stats = {
15+
spent : 0,
16+
total_spent : 0,
17+
time_estimate : 0
18+
}
19+
}
20+
21+
make(project, id, create = false) {
22+
let promise;
23+
24+
if (create) {
25+
promise = this.post(`projects/${encodeURIComponent(project)}/milestones`, {title: id});
26+
} else {
27+
promise = this.get(`projects/${encodeURIComponent(project)}/milestones/${id}`);
28+
}
29+
30+
promise.then(issue => {
31+
this.data = issue.body;
32+
return promise;
33+
});
34+
35+
return promise;
36+
}
37+
38+
/*
39+
* properties
40+
*/
41+
get iid() {
42+
return this.data.iid;
43+
}
44+
45+
get id() {
46+
return this.data.id;
47+
}
48+
49+
get project_id() {
50+
return this.data.project_id;
51+
}
52+
53+
get title() {
54+
return this.data.title;
55+
}
56+
57+
get description() {
58+
return this.data.description;
59+
}
60+
61+
get state() {
62+
return this.data.state;
63+
}
64+
65+
get created_at() {
66+
return moment(this.data.created_at);
67+
}
68+
69+
get updated_at() {
70+
return moment(this.data.updated_at);
71+
}
72+
73+
get due_date() {
74+
return this.data.due_date ? moment(this.data.due_date): null;
75+
}
76+
77+
get start_date() {
78+
return this.data.start_date ? moment(this.data.start_date): null;
79+
}
80+
81+
get expired() {
82+
return this.data.expired;
83+
}
84+
85+
get spent() {
86+
return this.stats ? this.config.toHumanReadable(this.stats.spent, this._type) : null;
87+
}
88+
89+
get total_spent() {
90+
return this.stats ? this.config.toHumanReadable(this.stats.total_spent, this._type) : null;
91+
}
92+
93+
get total_estimate() {
94+
return this.stats ? this.config.toHumanReadable(this.stats.time_estimate, this._type) : null;
95+
}
96+
97+
get _type() {
98+
return 'milestones';
99+
}
100+
101+
get _typeSingular() {
102+
return 'Milestone';
103+
}
104+
105+
getIssues(){
106+
let promise = new Promise(resolve => {
107+
this.get(`projects/${encodeURIComponent(this.project_id)}/issues/?milestone=${this.title}`)
108+
.then(data => data.body)
109+
.then(rawIssues => {
110+
let issues = []
111+
rawIssues.forEach(data => {
112+
let issue = new Issue(this.config, data)
113+
issues.push(issue)
114+
})
115+
this.issues = issues
116+
resolve()
117+
})
118+
})
119+
120+
return promise
121+
}
122+
123+
getStats(){
124+
let promise = new Promise((resolve) => {
125+
this.issues.forEach(async issue => {
126+
await issue.getStats()
127+
this.stats.time_estimate += issue.total_estimate;
128+
this.stats.total_spent += issue.total_spent;
129+
this.stats.spent += issue.spent;
130+
})
131+
resolve()
132+
})
133+
return promise
134+
}
135+
136+
async getNotes(){
137+
let promise = new Promise(async resolve => {
138+
await this.getIssues();
139+
this.notes = [];
140+
for (const issue of this.issues) {
141+
await issue.getNotes()
142+
this.notes = this.notes.concat(issue.notes)
143+
}
144+
resolve()
145+
})
146+
147+
148+
return promise
149+
}
150+
151+
}
152+
153+
module.exports = milestone;

src/models/report.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const Base = require('./base');
55
const Issue = require('./issue');
66
const MergeRequest = require('./mergeRequest');
77
const Project = require('./project');
8+
const Milestone = require('./milestone')
89

910
/**
1011
* report model
@@ -23,6 +24,7 @@ class report extends Base {
2324

2425
this.issues = [];
2526
this.mergeRequests = [];
27+
this.milestones = [];
2628
}
2729

2830
/**
@@ -95,6 +97,13 @@ class report extends Base {
9597
return promise;
9698
}
9799

100+
getMilestones(){
101+
let promise = this.all(`projects/${this.project.id}/milestones`);
102+
promise.then(milestones => this.milestones = milestones);
103+
104+
return promise;
105+
}
106+
98107
/**
99108
* filter empty
100109
* @param issues
@@ -153,6 +162,7 @@ class report extends Base {
153162
if (!this.members) this.members = [];
154163
this.members = this.members.concat(report.members ? report.members : []);
155164
this.projects = Object.assign(this.projects, report.projects);
165+
this.milestones = this.milestones.concat(report.milestones);
156166
}
157167

158168
/**
@@ -172,6 +182,15 @@ class report extends Base {
172182
processMergeRequests(advance = false) {
173183
return this.process('mergeRequests', MergeRequest, advance);
174184
}
185+
186+
/**
187+
* process merge requests
188+
* @param advance
189+
* @return {Promise}
190+
*/
191+
processMilestones(advance = false) {
192+
return this.process('milestones', Milestone, advance);
193+
}
175194
}
176195

177196
module.exports = report;

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@
764764
"estraverse" "^4.2.0"
765765
"esutils" "^2.0.2"
766766
"optionator" "^0.8.1"
767+
"source-map" "~0.6.1"
767768
optionalDependencies:
768769
"source-map" "~0.6.1"
769770

@@ -776,6 +777,7 @@
776777
"estraverse" "^1.9.1"
777778
"esutils" "^2.0.2"
778779
"optionator" "^0.8.1"
780+
"source-map" "~0.2.0"
779781
optionalDependencies:
780782
"source-map" "~0.2.0"
781783

@@ -1169,6 +1171,7 @@
11691171
"async" "^1.4.0"
11701172
"optimist" "^0.6.1"
11711173
"source-map" "^0.4.4"
1174+
"uglify-js" "^2.6"
11721175
optionalDependencies:
11731176
"uglify-js" "^2.6"
11741177

@@ -1584,13 +1587,17 @@
15841587
"integrity" "sha1-NzaitCi4e72gzIO1P6PWM6NcKug="
15851588
"resolved" "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz"
15861589
"version" "2.4.0"
1590+
dependencies:
1591+
"graceful-fs" "^4.1.6"
15871592
optionalDependencies:
15881593
"graceful-fs" "^4.1.6"
15891594

15901595
"jsonfile@^4.0.0":
15911596
"integrity" "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss="
15921597
"resolved" "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz"
15931598
"version" "4.0.0"
1599+
dependencies:
1600+
"graceful-fs" "^4.1.6"
15941601
optionalDependencies:
15951602
"graceful-fs" "^4.1.6"
15961603

@@ -1664,6 +1671,8 @@
16641671
"integrity" "sha1-QIhDO0azsbolnXh4XY6W9zugJDk="
16651672
"resolved" "https://registry.npmjs.org/klaw/-/klaw-1.3.1.tgz"
16661673
"version" "1.3.1"
1674+
dependencies:
1675+
"graceful-fs" "^4.1.9"
16671676
optionalDependencies:
16681677
"graceful-fs" "^4.1.9"
16691678

@@ -2849,6 +2858,7 @@
28492858
"version" "2.8.29"
28502859
dependencies:
28512860
"source-map" "~0.5.1"
2861+
"uglify-to-browserify" "~1.0.0"
28522862
"yargs" "~3.10.0"
28532863
optionalDependencies:
28542864
"uglify-to-browserify" "~1.0.0"

0 commit comments

Comments
 (0)