Skip to content

Commit

Permalink
fix: merge requests loading (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
knowbased authored Sep 18, 2024
1 parent bbb81c7 commit cb9dd03
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ Class {
{ #category : #calculating }
ClosedMergeRequestMetric >> calculate [

| groupedByDate userClosedMergeRequests dateOver |
| groupedByDate dateOver |
userMergeRequests ifNil: [ self load ].
groupedByDate := self setupGroupedDate.

userMergeRequests := userMergeRequests select: [ :userMergeRequest |
userMergeRequest state = 'closed' ].

userClosedMergeRequests := userMergeRequests select: [
:userMergeRequest |
"userMergeRequest merged_at isNil and:"
userMergeRequest state = 'closed' ].

userClosedMergeRequests do: [ :userMergeRequest |
userMergeRequests do: [ :userMergeRequest |
dateOver := self transformDate: userMergeRequest created_at to: over.

groupedByDate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ CommentContributionMetric >> description [
CommentContributionMetric >> load [

userCommits := self
loadCompleteCommitsSince: (period at: #since)
loadUserCompleteCommitsSince: (period at: #since)
until: (period at: #until)
]
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ JiraTimeMRTimeDifferenceMetric >> description [
JiraTimeMRTimeDifferenceMetric >> load [

userMergeRequests := self
loadCompleteMergeRequestsWithJiraIssueOfUser:
user
since: (period at: #since)
loadUserCompleteMergeRequestsWithJiraIssueSince: (period at: #since)
until: (period at: #until).

"Take only the merge requests that have been merged and given a time estimate"
Expand All @@ -71,6 +69,5 @@ JiraTimeMRTimeDifferenceMetric >> load [
timeOriginalEstimate
isNotNil.
mergeRequest merged_at isNotNil and:
issueIsEstimated ].

issueIsEstimated ]
]
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ MergedMergeRequestMetric >> description [
^ 'number of merge request merged by this user'
]

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

userMergeRequests := self
loadMergeRequestsSince: (period at: #since)
until: (period at: #until)
]

{ #category : #accessing }
MergedMergeRequestMetric >> name [

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ ReviewedByUserMergeRequestMetric >> description [
ReviewedByUserMergeRequestMetric >> load [

userMergeRequests := self
loadCompleteMergeRequestsOfUser: user since:
(period at: #since)
loadCompleteMergeRequestsSince: (period at: #since)
until: (period at: #until)
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ SelfMergedUnderAMinuteMergeRequestMetric >> description [
SelfMergedUnderAMinuteMergeRequestMetric >> load [

userMergeRequests := self
loadCompleteMergeRequestsOfUser: user
since: (period at: #since)
loadCompleteMergeRequestsSince: (period at: #since)
until: (period at: #until)
]

Expand Down
2 changes: 1 addition & 1 deletion src/GitLabHealth-Model-Analysis/UserCommitsMetric.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ UserCommitsMetric >> description [
UserCommitsMetric >> load [

userCommits := self
loadCommitsSince: (period at: #since)
loadUserCommitsSince: (period at: #since)
until: (period at: #until)
]

Expand Down
3 changes: 1 addition & 2 deletions src/GitLabHealth-Model-Analysis/UserJiraMetric.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ UserJiraMetric >> description [
UserJiraMetric >> load [

userMergeRequests := self
loadMergeRequestsWithJiraIssueOfUser: user since:
(period at: #since)
loadUserMergeRequestsWithJiraIssueSince: (period at: #since)
until: (period at: #until)
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ UserMergeRequestMetric >> description [
UserMergeRequestMetric >> load [

userMergeRequests := self
loadMergeRequestsOfUser: user since: (period at: #since)
loadUserMergeRequestsSince: (period at: #since)
until: (period at: #until)

]

{ #category : #accessing }
Expand Down
115 changes: 75 additions & 40 deletions src/GitLabHealth-Model-Analysis/UserMetric.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,69 @@ UserMetric >> load [
]

{ #category : #loading }
UserMetric >> loadCommitsSince: since until: until [
UserMetric >> loadCompleteMergeRequestsSince: since until: until [

| mergeRequests |
mergeRequests := self
loadMergeRequestsSince: since until: until.

mergeRequests do: [ :mergeRequest |
glhImporter importMergeResquestMerger: mergeRequest.
glhImporter importMergeRequestCommits: mergeRequest ].

^ mergeRequests
]

{ #category : #loading }
UserMetric >> loadMergeRequestsSince: since until: until [

| cacheSymbol mergeRequests |
glhImporter withCommitDiffs: false.
cacheSymbol := self
cacheSymbolFor: GLPHEMergeRequest
since: since
until: until.

mergeRequests := user 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 "mergeRequests select: [ :mergeRequest |
mergeRequest author = user ]"
]

{ #category : #loading }
UserMetric >> loadMergeRequestsWithJiraIssueSince: since until: until [

| email mergeRequests |
mergeRequests := self
loadMergeRequestsSince: since until: until.

email := self userEmail.

jiraImporter importAllCurrentAndPastIssuesOf: email.

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

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

{ #category : #loading }
UserMetric >> loadUserCommitsSince: since until: until [

| cacheSymbol allCommits |
glhImporter withCommitDiffs: false.
Expand Down Expand Up @@ -101,22 +163,19 @@ UserMetric >> loadCommitsSince: since until: until [
]

{ #category : #loading }
UserMetric >> loadCompleteCommitsSince: since until: until [
UserMetric >> loadUserCompleteCommitsSince: since until: until [

| commits |
commits := self loadCommitsSince: since until: until.
commits := self loadUserCommitsSince: since until: until.
commits do: [ :commit | glhImporter completeImportedCommit: commit ].
^ commits
]

{ #category : #loading }
UserMetric >> loadCompleteMergeRequestsOfUser: anUser since: since until: until [
UserMetric >> loadUserCompleteMergeRequestsSince: since until: until [

| mergeRequests |
mergeRequests := self
loadMergeRequestsOfUser: anUser
since: since
until: until.
mergeRequests := self loadUserMergeRequestsSince: since until: until.

mergeRequests do: [ :mergeRequest |
glhImporter importMergeResquestMerger: mergeRequest.
Expand All @@ -126,13 +185,10 @@ UserMetric >> loadCompleteMergeRequestsOfUser: anUser since: since until: until
]

{ #category : #loading }
UserMetric >> loadCompleteMergeRequestsWithJiraIssueOfUser: anUser since: since until: until [
UserMetric >> loadUserCompleteMergeRequestsWithJiraIssueSince: since until: until [

| email mergeRequests |
mergeRequests := self
loadCompleteMergeRequestsOfUser: anUser
since: since
until: until.
mergeRequests := self loadUserCompleteMergeRequestsSince: since until: until.

email := self userEmail.

Expand All @@ -148,40 +204,19 @@ UserMetric >> loadCompleteMergeRequestsWithJiraIssueOfUser: anUser since: since
]

{ #category : #loading }
UserMetric >> loadMergeRequestsOfUser: anUser since: since until: until [

| cacheSymbol mergeRequests |
glhImporter withCommitDiffs: false.
cacheSymbol := self
cacheSymbolFor: GLPHEMergeRequest
since: since
until: until.
UserMetric >> loadUserMergeRequestsSince: 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 |
mergeRequests := self loadMergeRequestsSince: since until: until.

^ mergeRequests select: [ :mergeRequest | mergeRequest author = anUser ]
^ mergeRequests select: [ :mergeRequest | mergeRequest author = user ]
]

{ #category : #loading }
UserMetric >> loadMergeRequestsWithJiraIssueOfUser: anUser since: since until: until [
UserMetric >> loadUserMergeRequestsWithJiraIssueSince: since until: until [

| email mergeRequests |
mergeRequests := self
loadMergeRequestsOfUser: anUser
since: since
until: until.
mergeRequests := self loadUserMergeRequestsSince: since until: until.

email := self userEmail.

Expand Down

0 comments on commit cb9dd03

Please sign in to comment.