-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from moosetechnology/feat-number-of-commit-by-…
…tickets feat: add commitsNumberByJiraTicket metric
- Loading branch information
Showing
3 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
src/GitLabHealth-Model-Analysis-Tests/CommitsNumberByJiraTicketsMetricTest.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
" | ||
A CommitsNumberByJiraTicketsMetricTest is a test class for testing the behavior of CommitsNumberByJiraTicketsMetric | ||
" | ||
Class { | ||
#name : #CommitsNumberByJiraTicketsMetricTest, | ||
#superclass : #TestCase, | ||
#category : #'GitLabHealth-Model-Analysis-Tests' | ||
} | ||
|
||
{ #category : #tests } | ||
CommitsNumberByJiraTicketsMetricTest >> testCalculate [ | ||
|
||
| result glhImporter user jiraImporter commitsNumber | | ||
"Given" | ||
user := GLHUser new | ||
username: 'test'; | ||
contributedProjects: | ||
{ (GLHProject new repository: GLHRepository new) }. | ||
|
||
glhImporter := GLPHImporterMock new. | ||
glhImporter mergeRequests: { (GLPHEMergeRequest new | ||
author: user; | ||
created_at: '09-05-2024'; | ||
merged_at: '09-06-2024' asDate; | ||
title: '205 feat do something') }. | ||
|
||
glhImporter commits: { (GLHCommit new | ||
id: 1; | ||
created_at: '09-05-2024' asDate; | ||
commitCreator: user; | ||
deletions: 5) }. | ||
|
||
jiraImporter := JiraImporterMock new. | ||
jiraImporter issues: { (JPIssue new | ||
key: '205'; | ||
timeEstimate: 25 hours asDuration) }. | ||
|
||
|
||
commitsNumber := CommitsNumberByJiraTicketsMetric new | ||
user: user; | ||
glhImporter: glhImporter; | ||
jiraImporter: jiraImporter; | ||
setPeriodSince: '09-04-2024' until: '09-04-2024'; | ||
over: Week. | ||
|
||
"When" | ||
result := commitsNumber calculate. | ||
|
||
"Then" | ||
self assert: result equals: 1 | ||
] | ||
|
||
{ #category : #tests } | ||
CommitsNumberByJiraTicketsMetricTest >> testCalculateNoCommits [ | ||
|
||
| result glhImporter user jiraImporter commitsNumber | | ||
"Given" | ||
user := GLHUser new | ||
username: 'test'; | ||
contributedProjects: | ||
{ (GLHProject new repository: GLHRepository new) }. | ||
|
||
glhImporter := GLPHImporterMock new. | ||
glhImporter mergeRequests: { (GLPHEMergeRequest new | ||
author: user; | ||
created_at: '09-05-2024'; | ||
merged_at: '09-06-2024' asDate; | ||
title: '205 feat do something') }. | ||
|
||
jiraImporter := JiraImporterMock new. | ||
jiraImporter issues: { (JPIssue new | ||
key: '205'; | ||
timeEstimate: 25 hours asDuration) }. | ||
|
||
|
||
commitsNumber := CommitsNumberByJiraTicketsMetric new | ||
user: user; | ||
glhImporter: glhImporter; | ||
jiraImporter: jiraImporter; | ||
setPeriodSince: '09-04-2024' until: '09-04-2024'; | ||
over: Week. | ||
|
||
"When" | ||
result := commitsNumber calculate. | ||
|
||
"Then" | ||
self assert: result equals: 0 | ||
] | ||
|
||
{ #category : #tests } | ||
CommitsNumberByJiraTicketsMetricTest >> testCalculateNoMergeRequests [ | ||
|
||
| result glhImporter user jiraImporter commitsNumber | | ||
"Given" | ||
user := GLHUser new | ||
username: 'test'; | ||
contributedProjects: | ||
{ (GLHProject new repository: GLHRepository new) }. | ||
|
||
glhImporter := GLPHImporterMock new. | ||
|
||
jiraImporter := JiraImporterMock new. | ||
jiraImporter issues: { (JPIssue new | ||
key: '205'; | ||
timeEstimate: 25 hours asDuration) }. | ||
|
||
|
||
commitsNumber := CommitsNumberByJiraTicketsMetric new | ||
user: user; | ||
glhImporter: glhImporter; | ||
jiraImporter: jiraImporter; | ||
setPeriodSince: '09-04-2024' until: '09-04-2024'; | ||
over: Week. | ||
|
||
"When" | ||
result := commitsNumber calculate. | ||
|
||
"Then" | ||
self assert: result equals: 0 | ||
] |
39 changes: 39 additions & 0 deletions
39
src/GitLabHealth-Model-Analysis/CommitsNumberByJiraTicketsMetric.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
Class { | ||
#name : #CommitsNumberByJiraTicketsMetric, | ||
#superclass : #UserJiraMetric, | ||
#category : #'GitLabHealth-Model-Analysis' | ||
} | ||
|
||
{ #category : #calculating } | ||
CommitsNumberByJiraTicketsMetric >> calculate [ | ||
|
||
| groupedByDate dateOver | | ||
userMergeRequests ifNil: [ self load ]. | ||
userMergeRequests ifEmpty: [ ^ 0 ]. | ||
groupedByDate := self setupGroupedDate. | ||
userMergeRequests do: [ :userMergeRequest | | ||
dateOver := self transformDate: userMergeRequest created_at to: over. | ||
groupedByDate | ||
at: dateOver printString | ||
ifPresent: [ :value | value add: userMergeRequest ] ]. | ||
groupedByDate := groupedByDate collect: [ :group | | ||
| average | | ||
average := (group collect: [ :mergeRequest | | ||
mergeRequest commits size ]) average ]. | ||
^ groupedByDate average | ||
] | ||
|
||
{ #category : #accessing } | ||
CommitsNumberByJiraTicketsMetric >> description [ | ||
|
||
^ 'average number of commit by merge request associated to a jira ticket' | ||
] | ||
|
||
{ #category : #loading } | ||
CommitsNumberByJiraTicketsMetric >> load [ | ||
|
||
userMergeRequests := self | ||
loadUserCompleteMergeRequestsWithJiraIssueSince: | ||
(period at: #since) | ||
until: (period at: #until). | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters