Skip to content

Commit

Permalink
Merge pull request #64 from moosetechnology/feat-number-of-commit-by-…
Browse files Browse the repository at this point in the history
…tickets

feat: add commitsNumberByJiraTicket metric
  • Loading branch information
alkalinan authored Sep 18, 2024
2 parents 2dfe0a0 + bfca23d commit 97972f6
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 1 deletion.
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
]
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).
]
9 changes: 8 additions & 1 deletion src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ GitMetricExporter >> initialize [
ClosedMergeRequestMetric.
MergedMergeRequestMetric.
SelfMergedUnderAMinuteMergeRequestMetric.
ClosedTicketsMetric. JiraTimeMRTimeDifferenceMetric }
ClosedTicketsMetric.
JiraTimeMRTimeDifferenceMetric. CommitsNumberByJiraTicketsMetric }
]

{ #category : #accessing }
Expand All @@ -473,6 +474,12 @@ GitMetricExporter >> maxCommitWindow: anInteger [
maxCommitWindow := anInteger abs
]

{ #category : #accessing }
GitMetricExporter >> metrics: anObject [

metrics := anObject
]

{ #category : #adding }
GitMetricExporter >> onlyImportProjectsOfGroup: groupId [

Expand Down

0 comments on commit 97972f6

Please sign in to comment.