Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(UserJiraMetric): add metric CommitNumberLinkWithJiraTicket #113

Merged
merged 5 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"
A CommitsLinkWithTicketMetricTest is a test class for testing the behavior of CommitsLinkWithTicketMetric
"
Class {
#name : #CommitsLinkWithTicketMetricTest,
#superclass : #TestCase,
#category : #'GitLabHealth-Model-Analysis-Tests'
}

{ #category : #tests }
CommitsLinkWithTicketMetricTest >> testCalculate [

"Given"
| user glhImporter jiraImporter commitLinkWithTicket result |
user := GLHUser new
username: 'test';
contributedProjects:
{ (GLHProject new repository: GLHRepository new) }.

glhImporter := GLPHImporterMock new.

glhImporter commits: {
(GLHCommit new
id: 1;
created_at: '09-05-2024' asDate;
message: 'test';
additions: 7;
commitCreator: user;
deletions: 5).
(GLHCommit new
id: 2;
created_at: '09-05-2024' asDate;
message: '205';
additions: 3;
commitCreator: user;
deletions: 5) }.

jiraImporter := JiraImporterMock new.
jiraImporter issues: { (JPIssue new
key: '205';
timeEstimate: 25 hours asDuration) }.


commitLinkWithTicket := CommitsLinkWithTicketMetric new
user: user;
glhImporter: glhImporter;
jiraImporter: jiraImporter;
setPeriodSince: '09-04-2024' until: '09-04-2024';
over: Week.

"When"
result := commitLinkWithTicket calculate.

"Then"
self assert: result equals: 1.
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Class {
#name : #CommitsLinkWithTicketMetric,
#superclass : #UserJiraMetric,
#category : #'GitLabHealth-Model-Analysis'
}

{ #category : #calculating }
CommitsLinkWithTicketMetric >> calculate [

| groupedByDate |
userCommits ifNil: [ self load ].
groupedByDate := self setupGroupedDate.

userCommits do: [ :c |
| dateOver |
dateOver := self transformDate: c created_at to: over.
groupedByDate at: dateOver printString ifPresent: [ :v | v add: c ] ].

groupedByDate := groupedByDate collect: [ :group | group size ].

^ groupedByDate average asFloat
]

{ #category : #accessing }
CommitsLinkWithTicketMetric >> description [

^ 'number of commits link a jira ticket'
]

{ #category : #loading }
CommitsLinkWithTicketMetric >> load [

| email |
userCommits := self
loadUserCommitsSince: (period at: #since)
until: (period at: #until).

email := self userEmail.

jiraImporter importAllCurrentAndPastIssuesOf: email.

GPJCConnector new
gpModel: glhImporter glhModel;
jiraModel: jiraImporter model;
connect.

^userCommits := userCommits select: [ :commit |
commit jiraIssue isNotNil ]


]
2 changes: 2 additions & 0 deletions src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ GitMetricExporter >> initialize [
analyses := OrderedCollection new.

metrics := {
"User Metrics"
CodeAdditionMetric.
CodeDeletionMetric.
CommentContributionMetric.
Expand All @@ -477,6 +478,7 @@ GitMetricExporter >> initialize [
ClosedTicketsMetric.
JiraTimeMRTimeDifferenceMetric.
CommitsNumberByJiraTicketsMetric.
CommitsLinkWithTicketMetric.


"Project Metrics"
Expand Down
Loading