Skip to content

Commit 1ba58cf

Browse files
authored
Merge pull request #166 from moosetechnology/develop
Develop
2 parents 309a626 + 0366375 commit 1ba58cf

File tree

3 files changed

+139
-7
lines changed

3 files changed

+139
-7
lines changed

src/GitLabHealth-Model-Analysis-Tests/CodeAdditionByMergeRequestProjectMetricTest.class.st

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ Class {
77
#category : #'GitLabHealth-Model-Analysis-Tests'
88
}
99

10-
11-
{ #category : #'tests' }
10+
{ #category : #tests }
1211
CodeAdditionByMergeRequestProjectMetricTest >> testCalculate [
1312

1413
| result glhImporter codeAddition mergedCommit |
@@ -103,7 +102,6 @@ CodeAdditionByMergeRequestProjectMetricTest >> testCalculateNoCommits [
103102
self assert: result equals: 0
104103
]
105104

106-
107105
{ #category : #tests }
108106
CodeAdditionByMergeRequestProjectMetricTest >> testCalculateNoMergeRequests [
109107

src/GitLabHealth-Model-Analysis-Tests/JiraTimeMRTimeDifferenceProjectMetricTest.class.st

Lines changed: 137 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,66 @@ JiraTimeMRTimeDifferenceProjectMetricTest >> testCalculateNoMergeRequests [
9595
{ #category : #tests }
9696
JiraTimeMRTimeDifferenceProjectMetricTest >> testCalculateWithNoEstimatedTime [
9797

98+
| result glhImporter jiraImporter jiraMRDifference commitMerged commit1 |
99+
glhImporter := GLPHImporterMock new.
100+
101+
102+
commit1 := GLHCommit new
103+
id: 1;
104+
created_at: createdAt;
105+
committed_date: createdAt;
106+
repository: project1 repository;
107+
deletions: 5.
108+
109+
commitMerged := GLHCommit new
110+
id: 2;
111+
created_at: createdAt + 1 minutes;
112+
committed_date: createdAt + 1 minutes;
113+
repository: project1 repository;
114+
deletions: 5.
115+
116+
glhImporter mergeRequests: {
117+
118+
(GLHMergeRequest new
119+
project: project1;
120+
iid: 2;
121+
created_at: createdAt;
122+
merged_at: createdAt + 24 hours;
123+
state: #merged;
124+
mergedCommit: commitMerged;
125+
title: '[AZ-123] feat do something') }.
126+
127+
128+
"those commits will be added to the MR with the mock importer"
129+
glhImporter commits: { commit1 }.
130+
131+
jiraImporter := JiraImporterMock new.
132+
133+
jiraImporter issues: {
134+
(JPIssue new
135+
id: 'AZ-123';
136+
key: 'AZ-123';
137+
yourself) }.
138+
139+
140+
141+
jiraMRDifference := JiraTimeMRTimeDifferenceProjectMetric new
142+
project: project1;
143+
glhImporter: glhImporter;
144+
jiraImporter: jiraImporter;
145+
setPeriodSince: since until: until;
146+
over: Week.
147+
148+
149+
result := jiraMRDifference calculate.
150+
151+
152+
self assert: result equals: nil
153+
]
154+
155+
{ #category : #tests }
156+
JiraTimeMRTimeDifferenceProjectMetricTest >> testCalculateWithNoEstimatedTimeAndOneTicketWith [
157+
98158
| result glhImporter jiraImporter jiraMRDifference jiraIssue commitMerged commit1 |
99159
glhImporter := GLPHImporterMock new.
100160

@@ -115,11 +175,23 @@ JiraTimeMRTimeDifferenceProjectMetricTest >> testCalculateWithNoEstimatedTime [
115175

116176
glhImporter mergeRequests: { (GLHMergeRequest new
117177
project: project1;
178+
iid: 1;
179+
created_at: createdAt;
180+
merged_at: createdAt + 1 hours;
181+
state: #merged;
182+
mergedCommit: commitMerged;
183+
title: '[AZ-654] feat do something').
184+
185+
(GLHMergeRequest new
186+
project: project1;
187+
iid: 2;
118188
created_at: createdAt;
119189
merged_at: createdAt + 24 hours;
120190
state: #merged;
121191
mergedCommit: commitMerged;
122-
title: '[AZ-654] feat do something') }.
192+
title: '[AZ-123] feat do something')
193+
194+
}.
123195

124196

125197
"those commits will be added to the MR with the mock importer"
@@ -130,7 +202,70 @@ JiraTimeMRTimeDifferenceProjectMetricTest >> testCalculateWithNoEstimatedTime [
130202
id: 'AZ-654';
131203
key: 'AZ-654';
132204
yourself.
133-
jiraImporter issues: { jiraIssue }.
205+
jiraImporter issues: { (JPIssue new
206+
id: 'AZ-654';
207+
key: 'AZ-654';
208+
timeEstimate: 2 hours;
209+
yourself). (JPIssue new
210+
id: 'AZ-123';
211+
key: 'AZ-123';
212+
yourself). }.
213+
214+
215+
216+
jiraMRDifference := JiraTimeMRTimeDifferenceProjectMetric new
217+
project: project1;
218+
glhImporter: glhImporter;
219+
jiraImporter: jiraImporter;
220+
setPeriodSince: since until: until;
221+
over: Week.
222+
223+
224+
result := jiraMRDifference calculate.
225+
226+
227+
self assert: result equals: 1 hours asSeconds
228+
]
229+
230+
{ #category : #tests }
231+
JiraTimeMRTimeDifferenceProjectMetricTest >> testCalculateWithNoIssue [
232+
233+
| result glhImporter jiraImporter jiraMRDifference jiraIssue commitMerged commit1 |
234+
glhImporter := GLPHImporterMock new.
235+
236+
237+
commit1 := GLHCommit new
238+
id: 1;
239+
created_at: createdAt;
240+
committed_date: createdAt;
241+
repository: project1 repository;
242+
deletions: 5.
243+
244+
commitMerged := GLHCommit new
245+
id: 2;
246+
created_at: createdAt + 1 minutes;
247+
committed_date: createdAt + 1 minutes;
248+
repository: project1 repository;
249+
deletions: 5.
250+
251+
glhImporter mergeRequests: { (GLHMergeRequest new
252+
project: project1;
253+
created_at: createdAt;
254+
merged_at: createdAt + 24 hours;
255+
state: #merged;
256+
mergedCommit: commitMerged;
257+
title: 'feat do something') }.
258+
259+
260+
"those commits will be added to the MR with the mock importer"
261+
glhImporter commits: { commit1 }.
262+
263+
jiraImporter := JiraImporterMock new.
264+
jiraIssue := JPIssue new
265+
id: 'AZ-654';
266+
key: 'AZ-654';
267+
yourself.
268+
jiraImporter issues: { }.
134269

135270

136271

src/GitLabHealth-Model-Analysis/JiraTimeMRTimeDifferenceProjectMetric.class.st

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Class {
1111
JiraTimeMRTimeDifferenceProjectMetric >> calculate [
1212

1313
| groupedByDate dateOver jiraID |
14-
1514
projectMergeRequests ifNil: [ self load ].
15+
projectMergeRequests := projectMergeRequests reject: [:mr | mr jiraIssue isNil or: [(mr jiraIssue timeOriginalEstimate ifNil: [mr jiraIssue timeEstimate ]) isNil]].
1616
projectMergeRequests ifEmpty: [ ^ nil ].
1717

1818
groupedByDate := self setupGroupedDate.
@@ -48,7 +48,6 @@ JiraTimeMRTimeDifferenceProjectMetric >> calculate [
4848
ifNil: [
4949
jiraIssue timeEstimate ].
5050

51-
jiraTime ifNil: [ ^ nil ].
5251
(jiraTime - mergeRequestTime)
5352
asSeconds ].
5453

0 commit comments

Comments
 (0)