diff --git a/src/GitLabHealth-Model-Analysis-Tests/MergedMergeRequestMetricTest.class.st b/src/GitLabHealth-Model-Analysis-Tests/MergedMergeRequestMetricTest.class.st index 10b5169..45e5fc0 100644 --- a/src/GitLabHealth-Model-Analysis-Tests/MergedMergeRequestMetricTest.class.st +++ b/src/GitLabHealth-Model-Analysis-Tests/MergedMergeRequestMetricTest.class.st @@ -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') }. @@ -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')}. @@ -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 @@ -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 [ diff --git a/src/GitLabHealth-Model-Analysis/ClosedTicketsMetric.class.st b/src/GitLabHealth-Model-Analysis/ClosedTicketsMetric.class.st index 4da2be6..a368fd8 100644 --- a/src/GitLabHealth-Model-Analysis/ClosedTicketsMetric.class.st +++ b/src/GitLabHealth-Model-Analysis/ClosedTicketsMetric.class.st @@ -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 } diff --git a/src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st b/src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st index c8efee8..c1cd7d6 100644 --- a/src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st +++ b/src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st @@ -255,9 +255,6 @@ GitMetricExporter >> exportProjectAnalysesInCSV [ file := self constructFilePath: groupOver. file writeStreamDo: [ :aStream | - aStream - << 'sep=,'; - << OSPlatform current lineEnding. exportBrowserModel writeCSVOn: aStream ] ] ] @@ -301,9 +298,6 @@ GitMetricExporter >> exportUserAnalysesInCSV [ file := self constructFilePath: groupOver. file writeStreamDo: [ :aStream | - aStream - << 'sep=,'; - << OSPlatform current lineEnding. exportBrowserModel writeCSVOn: aStream ] ] ] diff --git a/src/GitLabHealth-Model-Analysis/MergedMergeRequestMetric.class.st b/src/GitLabHealth-Model-Analysis/MergedMergeRequestMetric.class.st index 2547b0a..5494e71 100644 --- a/src/GitLabHealth-Model-Analysis/MergedMergeRequestMetric.class.st +++ b/src/GitLabHealth-Model-Analysis/MergedMergeRequestMetric.class.st @@ -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" @@ -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 } diff --git a/src/GitLabHealth-Model-Analysis/OpenedMergeRequestMetric.class.st b/src/GitLabHealth-Model-Analysis/OpenedMergeRequestMetric.class.st index 2e1c4b2..e2f153a 100644 --- a/src/GitLabHealth-Model-Analysis/OpenedMergeRequestMetric.class.st +++ b/src/GitLabHealth-Model-Analysis/OpenedMergeRequestMetric.class.st @@ -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 [ diff --git a/src/GitLabHealth-Model-Analysis/PendingMergeRequestMetric.class.st b/src/GitLabHealth-Model-Analysis/PendingMergeRequestMetric.class.st index 185e7c5..bd020d4 100644 --- a/src/GitLabHealth-Model-Analysis/PendingMergeRequestMetric.class.st +++ b/src/GitLabHealth-Model-Analysis/PendingMergeRequestMetric.class.st @@ -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' diff --git a/src/GitLabHealth-Model-Analysis/TimeBetweenCommitMetric.class.st b/src/GitLabHealth-Model-Analysis/TimeBetweenCommitMetric.class.st index 522f3e4..5af9688 100644 --- a/src/GitLabHealth-Model-Analysis/TimeBetweenCommitMetric.class.st +++ b/src/GitLabHealth-Model-Analysis/TimeBetweenCommitMetric.class.st @@ -39,9 +39,9 @@ TimeBetweenCommitMetric >> calculate [ average := groupedByDate ifEmpty: [ nil ] - ifNotEmpty: [ groupedByDate average ]. + ifNotEmpty: [ groupedByDate average asFloat ]. - ^ average + ^ average ] { #category : #accessing } diff --git a/src/GitLabHealth-Model-Analysis/UserMergeRequestMetric.class.st b/src/GitLabHealth-Model-Analysis/UserMergeRequestMetric.class.st index c9f94e9..f5d6bab 100644 --- a/src/GitLabHealth-Model-Analysis/UserMergeRequestMetric.class.st +++ b/src/GitLabHealth-Model-Analysis/UserMergeRequestMetric.class.st @@ -27,5 +27,5 @@ UserMergeRequestMetric >> load [ { #category : #accessing } UserMergeRequestMetric >> name [ - ^ self subclassResponsibility + ^ self class name asString ] diff --git a/src/GitLabHealth-Model-Analysis/UserMetric.class.st b/src/GitLabHealth-Model-Analysis/UserMetric.class.st index d7f517b..90cbdbd 100644 --- a/src/GitLabHealth-Model-Analysis/UserMetric.class.st +++ b/src/GitLabHealth-Model-Analysis/UserMetric.class.st @@ -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 [ @@ -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 }