forked from ndu2/gitlab-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissue.js
More file actions
executable file
·131 lines (104 loc) · 2.94 KB
/
issue.js
File metadata and controls
executable file
·131 lines (104 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const _ = require('underscore');
const moment = require('moment');
const hasTimes = require('./hasTimes');
/**
* issue model
*/
class issue extends hasTimes {
constructor(config, data = {}) {
super(config);
this.data = data;
}
make(project, id, create = false) {
let promise;
if (create) {
promise = this.post(`projects/${encodeURIComponent(project)}/issues`, {title: id});
} else {
promise = this.get(`projects/${encodeURIComponent(project)}/issues/${id}`);
}
promise.then(issue => {
this.data = issue.body;
return promise;
});
return promise;
}
list(project, state, my) {
return new Promise((resolve, reject) => {
let promise;
const query = `scope=${my ? "assigned-to-me" : "all"}&state=${state}`;
if (project) {
promise = this.get(`projects/${encodeURIComponent(project)}/issues?${query}`);
} else {
promise = this.get(`issues/?${query}`);
}
promise.then(response => {
const issues = response.body.map(issue => new this.constructor(this.config, issue))
resolve(issues)
});
promise.catch(error => reject(error))
})
}
/*
* properties
*/
get iid() {
return this.data.iid;
}
get id() {
return this.data.id;
}
get title() {
return this.data.title;
}
get project_id() {
return this.data.project_id;
}
get description() {
return this.data.description;
}
get labels() {
let labels = _.difference(this.data.labels, this.config.get('excludeLabels'));
let include = this.config.get('includeLabels');
return include.length > 0 ? _.intersection(labels, include) : labels;
}
get milestone() {
return this.data.milestone ? this.data.milestone.title : null;
}
get assignee() {
return this.data.assignee ? this.data.assignee.username : null;
}
get author() {
return this.data.author.username;
}
get closed() {
return this.data.state === 'closed';
}
get updated_at() {
return moment(this.data.updated_at);
}
get created_at() {
return moment(this.data.created_at);
}
get state() {
return this.data.state;
}
get spent() {
return this.config.toHumanReadable(this.timeSpent, this._type);
}
get due_date() {
return this.data.due_date ? moment(this.data.due_date): null;
}
get total_spent() {
return this.stats ? this.config.toHumanReadable(this.stats.total_time_spent, this._type) : null;
}
get total_estimate() {
return this.stats ? this.config.toHumanReadable(this.stats.time_estimate, this._type) : null;
}
get _type() {
return 'issues';
}
get _typeSingular() {
return 'Issue';
}
}
module.exports = issue;