Skip to content

Commit

Permalink
Merge pull request #43 from moosetechnology/feat/number-of-jira-ticke…
Browse files Browse the repository at this point in the history
…t-closed

feat(metrics): number of jira tickets closed
  • Loading branch information
alkalinan authored Aug 26, 2024
2 parents c6a6d65 + 77f7293 commit 52305cb
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 48 deletions.
15 changes: 14 additions & 1 deletion src/GitLabHealth-Model-Analysis/AnalysisReport.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Class {
'numberOfOpenMergeRequests',
'numberOfMergedMergeRequest',
'numberOfClosedMergeRequests',
'numberOfMergeRequestsWithoutReview'
'numberOfMergeRequestsWithoutReview',
'numberOfTicketsClosed'
],
#category : #'GitLabHealth-Model-Analysis'
}
Expand Down Expand Up @@ -183,6 +184,18 @@ AnalysisReport >> numberOfProjectWithCommit: anObject [
numberOfProjectWithCommit := anObject
]

{ #category : #accessing }
AnalysisReport >> numberOfTicketsClosed [

^ numberOfTicketsClosed
]

{ #category : #accessing }
AnalysisReport >> numberOfTicketsClosed: anObject [

numberOfTicketsClosed := anObject
]

{ #category : #accessing }
AnalysisReport >> over [

Expand Down
7 changes: 7 additions & 0 deletions src/GitLabHealth-Model-Analysis/GitMetric.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Class {
#instVars : [
'user',
'glhImporter',
'jiraImporter',
'itsProjects',
'gitAnalyzer',
'glhModel'
Expand Down Expand Up @@ -85,6 +86,12 @@ GitMetric >> glhImporter: aGLPHModelImporter [
glhImporter := aGLPHModelImporter
]

{ #category : #accessing }
GitMetric >> jiraImporter: anObject [

jiraImporter := anObject
]

{ #category : #churn }
GitMetric >> loadCommitsFromProjectsIds: aCollection since: since until: until [

Expand Down
85 changes: 68 additions & 17 deletions src/GitLabHealth-Model-Analysis/GitMetric4User.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -571,38 +571,31 @@ GitMetric4User >> foundSuccessorOf: userCommits andCompleteImportForMax: commitL
{ #category : #analysis }
GitMetric4User >> generateAnalysisForPeriod: period over: aDateWeekMonthOrYear withMaxCommitWindows: maxCommitWindow [

| contribution commitFrequency commentContribution mergeRequestDuration codeChurn delayUntilFirstChurn averageTimeBetweenCommits numberOfProjectWithCommit until since numberOfOpenMergeRequests numberOfMergedMergeRequests numberOfClosedMergeRequests numberOfMergeRequestWithoutReview |
| contribution commitFrequency commentContribution mergeRequestDuration codeChurn delayUntilFirstChurn averageTimeBetweenCommits numberOfProjectWithCommit until since numberOfOpenMergeRequests numberOfMergedMergeRequests numberOfClosedMergeRequests numberOfMergeRequestWithoutReview numberOfTicketsClosed |
since := period at: #since.
until := period at: #until.

"COMMITS"
contribution := self
codeContributionsSince: since
until: until
overA: aDateWeekMonthOrYear.

commitFrequency := self
commitFrequencySince: since
until: until
overA: aDateWeekMonthOrYear.

commentContribution := self
commentsContributionsSince: since
until: until
overA: aDateWeekMonthOrYear.

codeChurn := self
codeChurnSince: since
until: until
onACommitWindowOf: maxCommitWindow
overA: aDateWeekMonthOrYear.

delayUntilFirstChurn := self
delayUntilFirstChurnSince: since
until: until
onACommitWindowOf: maxCommitWindow
overA: aDateWeekMonthOrYear.

numberOfProjectWithCommit := self
numberOfProjectWithCommitSince: since
until: until
Expand All @@ -611,37 +604,33 @@ GitMetric4User >> generateAnalysisForPeriod: period over: aDateWeekMonthOrYear w
averageTimeBetweenCommitSince: since
until: until
overA: aDateWeekMonthOrYear.

"MERGE REQUESTS"

mergeRequestDuration := self
mergeRequestDurationSince: since
until: until
overA: aDateWeekMonthOrYear.

numberOfOpenMergeRequests := self
numberOfOpenMergeRequestsSince: since
until: until
overA: aDateWeekMonthOrYear.

numberOfMergedMergeRequests := self
numberOfMergedMergeRequestsSince:
since
until: until
overA: aDateWeekMonthOrYear.

numberOfClosedMergeRequests := self
numberOfClosedMergeRequestSince:
since
until: until
overA: aDateWeekMonthOrYear.

numberOfMergeRequestWithoutReview := self
numberOfMergeRequestsMergedWithoutReviewSince:
since
until: until
overA: aDateWeekMonthOrYear.

numberOfTicketsClosed := self
numberOfTicketsClosedSince: since
until: until
overA: aDateWeekMonthOrYear.
^ AnalysisReport new
username: self user name;
period: period;
Expand All @@ -663,7 +652,9 @@ GitMetric4User >> generateAnalysisForPeriod: period over: aDateWeekMonthOrYear w
(numberOfMergedMergeRequests at: #average);
numberOfClosedMergeRequests:
(numberOfClosedMergeRequests at: #average);
numberOfMergeRequestsWithoutReview: (numberOfMergeRequestWithoutReview at: #average).
numberOfMergeRequestsWithoutReview:
(numberOfMergeRequestWithoutReview at: #average);
numberOfTicketsClosed: (numberOfTicketsClosed at: #average)
]

{ #category : #initialization }
Expand Down Expand Up @@ -697,6 +688,25 @@ GitMetric4User >> loadCommitOfProjects: aCollection since: aTimespan [
^ self userCommits.
]

{ #category : #loading }
GitMetric4User >> loadItsMergeRequesWithJiraIssueSince: since until: until [

itsMergeRequests := self
loadItsMergeRequestsSince: since
until: until.

jiraImporter importAllCurrentAndPastIssuesOf:
user commits anyOne author_email.

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

^ itsMergeRequests select: [ :mergeRequest |
mergeRequest jiraIssue isNotNil ]
]

{ #category : #loading }
GitMetric4User >> loadItsMergeRequestsSince: since until: until [

Expand Down Expand Up @@ -1014,6 +1024,47 @@ GitMetric4User >> numberOfProjectWithCommitSince: since until: until overA: aDat

]

{ #category : #'metrics -jira' }
GitMetric4User >> numberOfTicketsClosedSince: since until: until overA: aDateWeekMonthOrYear [

| groupedByDate itsMergeRequestsWithJiraIssue dateOver average mergedMergeRequestWithJiraIssue |
groupedByDate := self
setupGroupedDateFrom: since
to: until
over: aDateWeekMonthOrYear.

itsMergeRequestsWithJiraIssue := self
loadItsMergeRequesWithJiraIssueSince:
since
until: until.

mergedMergeRequestWithJiraIssue := itsMergeRequestsWithJiraIssue
select: [ :mr |
mr merged_at isNotNil ].

mergedMergeRequestWithJiraIssue do: [ :userMergeRequest |
dateOver := self
transformDate: userMergeRequest created_at
to: aDateWeekMonthOrYear.
groupedByDate
at: dateOver printString
ifPresent: [ :value | value add: userMergeRequest ] ].

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

average := groupedByDate
ifEmpty: [ 0 ]
ifNotEmpty: [ groupedByDate average ].
^ {
(#overEach -> aDateWeekMonthOrYear name).
(#forOver -> (groupedByDate keys size printString
, aDateWeekMonthOrYear printString)).
(#average -> average asFloat).
(#details -> groupedByDate).
(#userMergeRequestsWithJiraIssue -> itsMergeRequestsWithJiraIssue size) }
asDictionary
]

{ #category : #accessing }
GitMetric4User >> user [
^ user
Expand Down
93 changes: 63 additions & 30 deletions src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Class {
#superclass : #Object,
#instVars : [
'glhImporter',
'jiraImporter',
'label',
'entities',
'projectCache',
Expand Down Expand Up @@ -45,11 +46,14 @@ GitMetricExporter >> addEntitiesFromUserNames: userNames [
"then collect the project in which the user has be seen commited"
entities addAll: (userNames collect: [ :username |
| projects metrics i size |
projects := self findParticipationOfCommitAuthorNamed: username amongProjects: projectCache.
projects := self
findParticipationOfCommitAuthorNamed: username
amongProjects: projectCache.

metrics := GitMetric4User new.
metrics
glhImporter: glhImporter;
jiraImporter: jiraImporter;
findUserNamed: username.


Expand Down Expand Up @@ -77,17 +81,18 @@ GitMetricExporter >> addEntitiesFromUserNames: userNames [
GitMetricExporter >> addEntitiesFromUserNamesAndProjects: usersWithProjects [

entities addAll: (usersWithProjects associations collect: [ :assoc |
| username projects metrics |
username := assoc key.
projects := assoc value.
| username projects metrics |
username := assoc key.
projects := assoc value.

metrics := GitMetric4User new.
metrics
glhImporter: glhImporter;
findUserNamed: username.
metrics loadProjectsFromIds: projects.
metrics := GitMetric4User new.
metrics
glhImporter: glhImporter;
jiraImporter: jiraImporter;
findUserNamed: username.
metrics loadProjectsFromIds: projects.

metrics ]).
metrics ]).

^ self
]
Expand Down Expand Up @@ -133,15 +138,17 @@ GitMetricExporter >> csvMetricsFor: date [

('commits frequency (avg) - ' , date asString
-> [ :groupAnalyses |
| analysis |
analysis := self getAnalysisWithDate: date from: groupAnalyses.
analysis ifNil: [ nil ] ifNotNil: [ analysis commitFrequency ] ]).
| analysis |
analysis := self getAnalysisWithDate: date from: groupAnalyses.
analysis ifNil: [ nil ] ifNotNil: [ analysis commitFrequency ] ]).

('comment contribution (avg) - ' , date asString
-> [ :groupAnalyses |
| analysis |
analysis := self getAnalysisWithDate: date from: groupAnalyses.
analysis ifNil: [ nil ] ifNotNil: [ analysis commentContribution ] ]).
| analysis |
analysis := self getAnalysisWithDate: date from: groupAnalyses.
analysis
ifNil: [ nil ]
ifNotNil: [ analysis commentContribution ] ]).

('churn % (W=' , maxCommitWindow printString , ') - '
, date asString -> [ :groupAnalyses |
Expand All @@ -153,7 +160,9 @@ GitMetricExporter >> csvMetricsFor: date [
, ') - ' , date asString -> [ :groupAnalyses |
| analysis |
analysis := self getAnalysisWithDate: date from: groupAnalyses.
analysis ifNil: [ nil ] ifNotNil: [ analysis delayUntilFirstChurn ] ]).
analysis
ifNil: [ nil ]
ifNotNil: [ analysis delayUntilFirstChurn ] ]).

('number of project with min 1 commit of user - ' , date asString
-> [ :groupAnalyses |
Expand All @@ -163,9 +172,11 @@ GitMetricExporter >> csvMetricsFor: date [

('merge Request Duration - ' , date asString
-> [ :groupAnalyses |
| analysis |
analysis := self getAnalysisWithDate: date from: groupAnalyses.
analysis ifNil: [ nil ] ifNotNil: [ analysis mergeRequestDuration ] ]).
| analysis |
analysis := self getAnalysisWithDate: date from: groupAnalyses.
analysis
ifNil: [ nil ]
ifNotNil: [ analysis mergeRequestDuration ] ]).

('average time between commits - ' , date asString
-> [ :groupAnalyses |
Expand All @@ -175,27 +186,43 @@ GitMetricExporter >> csvMetricsFor: date [

('number of open merge request - ' , date asString
-> [ :groupAnalyses |
| analysis |
analysis := self getAnalysisWithDate: date from: groupAnalyses.
analysis ifNil: [ nil ] ifNotNil: [ analysis numberOfOpenMergeRequests ] ]).
| analysis |
analysis := self getAnalysisWithDate: date from: groupAnalyses.
analysis
ifNil: [ nil ]
ifNotNil: [ analysis numberOfOpenMergeRequests ] ]).

('number of merged merge request - ' , date asString
-> [ :groupAnalyses |
| analysis |
analysis := self getAnalysisWithDate: date from: groupAnalyses.
analysis ifNil: [ nil ] ifNotNil: [ analysis numberOfMergedMergeRequest ] ]).
| analysis |
analysis := self getAnalysisWithDate: date from: groupAnalyses.
analysis
ifNil: [ nil ]
ifNotNil: [ analysis numberOfMergedMergeRequest ] ]).

('number of merge requests closed and not merged - '
, date asString -> [ :groupAnalyses |
| analysis |
analysis := self getAnalysisWithDate: date from: groupAnalyses.
analysis ifNil: [ nil ] ifNotNil: [ analysis numberOfClosedMergeRequests ] ]).
analysis
ifNil: [ nil ]
ifNotNil: [ analysis numberOfClosedMergeRequests ] ]).

('number of merge requests without review - ' , date asString
-> [ :groupAnalyses |
| analysis |
analysis := self getAnalysisWithDate: date from: groupAnalyses.
analysis ifNil: [ nil ] ifNotNil: [ analysis numberOfMergeRequestsWithoutReview ] ]) }
| analysis |
analysis := self getAnalysisWithDate: date from: groupAnalyses.
analysis
ifNil: [ nil ]
ifNotNil: [ analysis numberOfMergeRequestsWithoutReview ] ]).

('number of merge request with jira ticket closed - ' , date asString
-> [ :groupAnalyses |
| analysis |
analysis := self getAnalysisWithDate: date from: groupAnalyses.
analysis
ifNil: [ nil ]
ifNotNil: [ analysis numberOfTicketsClosed ] ]) }
]

{ #category : #accessing }
Expand Down Expand Up @@ -418,6 +445,12 @@ GitMetricExporter >> initialize [
over := Date
]

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

jiraImporter := anObject
]

{ #category : #accessing }
GitMetricExporter >> label: aString [
label := aString
Expand Down

0 comments on commit 52305cb

Please sign in to comment.