Skip to content

Commit

Permalink
fix metric definitions and implementation for MR
Browse files Browse the repository at this point in the history
  • Loading branch information
HLAD Nicolas committed Sep 13, 2024
1 parent 3b6ee88 commit 9d4695b
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ MergedMergeRequestMetricTest >> testCalculate [
glhImporter := GLPHImporterMock new.
glhImporter mergeRequests: { (GLPHEMergeRequest new
author: user;
merge_user: user;
created_at: '09-05-2024';
merged_at: '09-05-2024')
}.
Expand Down Expand Up @@ -54,11 +55,14 @@ MergedMergeRequestMetricTest >> testCalculate1MRInPeriod1Outside [
"open and merge during the same week"
(GLPHEMergeRequest new
author: user;
merge_user: user;
created_at: '09-05-2024';
merged_at: '09-05-2024')
merged_at: '09-05-2024').

"open but merged anotherWeek"
.(GLPHEMergeRequest new
(GLPHEMergeRequest new
author: user;
merge_user: user;
created_at: '09-05-2024';
merged_at: '09-10-2024')}.

Expand Down Expand Up @@ -88,14 +92,17 @@ MergedMergeRequestMetricTest >> testCalculate1MROpenedButNotMerged [
{ (GLHProject new repository: GLHRepository new) }.

glhImporter := GLPHImporterMock new.
glhImporter mergeRequests: { (GLPHEMergeRequest new
glhImporter mergeRequests: {
(GLPHEMergeRequest new
author: user;
merge_user: user;
created_at: '09-05-2024';
merged_at: '09-05-2024')
.(GLPHEMergeRequest new
merged_at: '09-05-2024').
(GLPHEMergeRequest new
author: user;
created_at: '09-05-2024';
merged_at: nil)}.
merged_at: nil)
}.


mergedMergeRequest := MergedMergeRequestMetric new
Expand All @@ -112,6 +119,103 @@ MergedMergeRequestMetricTest >> testCalculate1MROpenedButNotMerged [
self assert: result equals: 1
]

{ #category : #tests }
MergedMergeRequestMetricTest >> testCalculate2MROneForEachUser [

| result glhImporter user1 mergedMergeRequest user2 |
"Given"
user1 := GLHUser new
name: 'test';
contributedProjects:
{ (GLHProject new repository: GLHRepository new) }.

user2 := GLHUser new
name: 'test';
contributedProjects:
{ (GLHProject new repository: GLHRepository new) }.

glhImporter := GLPHImporterMock new.
glhImporter mergeRequests: { (GLPHEMergeRequest new
author: user1;
title: 'MR1';
created_at: '09-05-2024';
merge_user: user1;
merged_at: '09-05-2024')
.(GLPHEMergeRequest new
author: user2;
title: 'MR2';
created_at: '09-05-2024';
merge_user: user2;
merged_at: '09-06-2024'
)}.


mergedMergeRequest := MergedMergeRequestMetric new
user: user1;
glhImporter: glhImporter;
setPeriodSince: '09-01-2024'
until: '09-07-2024';
over: Week.

"When"
result := mergedMergeRequest calculate.

"Then"
self assert: result equals: 2
]

{ #category : #tests }
MergedMergeRequestMetricTest >> testCalculate3MROpenByOther [

| result glhImporter user1 mergedMergeRequest user2 |
"Given"
user1 := GLHUser new
name: 'test';
contributedProjects:
{ (GLHProject new repository: GLHRepository new) }.

user2 := GLHUser new
name: 'test';
contributedProjects:
{ (GLHProject new repository: GLHRepository new) }.

glhImporter := GLPHImporterMock new.
glhImporter mergeRequests: { (GLPHEMergeRequest new
author: user2;
title: 'MR1';
created_at: '09-05-2024';
merge_user: user1;
merged_at: '09-05-2024').
(GLPHEMergeRequest new
author: user2;
title: 'MR2';
created_at: '09-05-2024';
merge_user: user1;
merged_at: '09-06-2024'
).
(GLPHEMergeRequest new
author: user2;
title: 'MR3';
created_at: '09-05-2024';
merge_user: user1;
merged_at: '09-06-2024'
)}.


mergedMergeRequest := MergedMergeRequestMetric new
user: user1;
glhImporter: glhImporter;
setPeriodSince: '09-01-2024'
until: '09-07-2024';
over: Week.

"When"
result := mergedMergeRequest calculate.

"Then"
self assert: result equals: 3
]

{ #category : #tests }
MergedMergeRequestMetricTest >> testCalculateNoMergeRequests [

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ClosedTicketsMetric >> calculate [
{ #category : #accessing }
ClosedTicketsMetric >> description [

^ 'number of merge request with jira ticket closed'
^ 'number of closed merge request associated with a jira ticket'
]

{ #category : #accessing }
Expand Down
6 changes: 0 additions & 6 deletions src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,6 @@ GitMetricExporter >> exportProjectAnalysesInCSV [

file := self constructFilePath: groupOver.
file writeStreamDo: [ :aStream |
aStream
<< 'sep=,';
<< OSPlatform current lineEnding.
exportBrowserModel writeCSVOn: aStream ] ]
]

Expand Down Expand Up @@ -301,9 +298,6 @@ GitMetricExporter >> exportUserAnalysesInCSV [

file := self constructFilePath: groupOver.
file writeStreamDo: [ :aStream |
aStream
<< 'sep=,';
<< OSPlatform current lineEnding.
exportBrowserModel writeCSVOn: aStream ] ]
]

Expand Down
14 changes: 12 additions & 2 deletions src/GitLabHealth-Model-Analysis/MergedMergeRequestMetric.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ MergedMergeRequestMetric >> calculate [

| groupedByDate userMergedMergeRequests dateOver |
userMergeRequests ifNil: [ self load ].

groupedByDate := self setupGroupedDate.

userMergedMergeRequests := userMergeRequests select: [
:userMergeRequest |
userMergeRequest merged_at isNotNil ].
userMergeRequest merge_user isNotNil
and: [ userMergeRequest merge_user id = user id ] ].

userMergedMergeRequests do: [ :userMergeRequest |
"here we look at the specific date of its merged"
Expand All @@ -29,7 +31,15 @@ MergedMergeRequestMetric >> calculate [
{ #category : #accessing }
MergedMergeRequestMetric >> description [

^ 'number of merged merge request'
^ 'number of merge request merged by this user'
]

{ #category : #loading }
MergedMergeRequestMetric >> load [
userMergeRequests := self
loadMergeRequestsSince:
(period at: #since)
until: (period at: #until)
]

{ #category : #accessing }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ OpenedMergeRequestMetric >> description [
^'number of opened merge request'
]

{ #category : #loading }
OpenedMergeRequestMetric >> load [
userMergeRequests := self loadMergeRequestsOfUser: user since: (period at: #since)
until: (period at: #until).
]

{ #category : #accessing }
OpenedMergeRequestMetric >> name [

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ PendingMergeRequestMetric >> description [
^ 'number of merge request opened during a period and left opened at the end of it'
]

{ #category : #loading }
PendingMergeRequestMetric >> load [
userMergeRequests := self loadMergeRequestsOfUser: user since: (period at: #since)
until: (period at: #until).
]

{ #category : #accessing }
PendingMergeRequestMetric >> name [
^'pendingMergeRequest'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ TimeBetweenCommitMetric >> calculate [

average := groupedByDate
ifEmpty: [ nil ]
ifNotEmpty: [ groupedByDate average ].
ifNotEmpty: [ groupedByDate average asFloat ].

^ average
^ average
]

{ #category : #accessing }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ UserMergeRequestMetric >> load [
{ #category : #accessing }
UserMergeRequestMetric >> name [

^ self subclassResponsibility
^ self class name asString
]
29 changes: 28 additions & 1 deletion src/GitLabHealth-Model-Analysis/UserMetric.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,33 @@ UserMetric >> loadCompleteMergeRequestsSince: since until: until [
^ mergeRequests
]

{ #category : #loading }
UserMetric >> loadMergeRequestsOfUser: anUser since: since until: until [

| cacheSymbol mergeRequests |
glhImporter withCommitDiffs: false.
cacheSymbol := self
cacheSymbolFor: GLPHEMergeRequest
since: since
until: until.

mergeRequests := anUser contributedProjects collect: [ :project |
| mr |
project cacheAt: cacheSymbol ifAbsentPut: [
mr := glhImporter
importMergeRequests: project
since: since
until: until.
mr ] ].

mergeRequests := mergeRequests flattened.
glhImporter withCommitDiffs: true.

mergeRequests do: [ :mr | glhImporter importMergeResquestAuthor: mr ].

^ mergeRequests select: [ :mergeRequest | mergeRequest author = anUser ]
]

{ #category : #loading }
UserMetric >> loadMergeRequestsSince: since until: until [

Expand All @@ -145,7 +172,7 @@ UserMetric >> loadMergeRequestsSince: since until: until [

mergeRequests do: [ :mr | glhImporter importMergeResquestAuthor: mr ].

^ mergeRequests select: [ :mergeRequest | mergeRequest author = user ]
^ mergeRequests "select: [ :mergeRequest | mergeRequest author = user ]"
]

{ #category : #loading }
Expand Down

0 comments on commit 9d4695b

Please sign in to comment.