Skip to content

Commit

Permalink
Merge pull request #105 from moosetechnology/fix-email-importer
Browse files Browse the repository at this point in the history
fix/add email user to the importer + tests
  • Loading branch information
badetitou authored Nov 8, 2024
2 parents 3c4574e + ebaebab commit 1b73d22
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 9 deletions.
18 changes: 12 additions & 6 deletions src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -265,21 +265,26 @@ GitMetricExporter >> exportUserAnalysesInCSV [
| exportBrowserModel groupedByOver group groupOver groupByName periods csvMetrics file |
exportBrowserModel := MiExportModel new.
groupedByOver := self userAnalyses groupedBy: #over.

groupedByOver associations do: [ :groupAssociation |
group := groupAssociation value.
groupOver := groupAssociation key.

groupByName := group groupedBy: #username.
exportBrowserModel entitiesList: groupByName.
exportBrowserModel removeColumnForQueryNamed: #Type.
exportBrowserModel removeColumnForQueryNamed: #Name.

exportBrowserModel
addColumnForQuery: [ :groupAnalyses |
(groupAnalyses at: 1) username ]
withName: #'User name'.

exportBrowserModel
addColumnForQuery: [ :groupAnalyses |
(groupAnalyses at: 1) email ]
withName: #'User email'.

periods := (group groupedBy: #period) keys.
periods do: [ :period |
csvMetrics := self
Expand All @@ -289,10 +294,10 @@ GitMetricExporter >> exportUserAnalysesInCSV [
exportBrowserModel
addColumnForQuery: association value
withName: association key ] ].


file := self constructFilePath: groupOver.

file writeStreamDo: [ :aStream |
exportBrowserModel writeCSVOn: aStream ] ]
]
Expand Down Expand Up @@ -365,6 +370,7 @@ GitMetricExporter >> generateUsersAnalysesDuringPeriod: period over: aDateWeekMo
^ self userEntities collect: [ :user |
userAnalysisReport := UserAnalysisReport new
username: user name;
email: (user email ifNil: [ user public_email]);
period: period;
over: aDateWeekMonthOrYear.

Expand Down
15 changes: 14 additions & 1 deletion src/GitLabHealth-Model-Analysis/UserAnalysisReport.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@ Class {
#name : 'UserAnalysisReport',
#superclass : 'AnalysisReport',
#instVars : [
'username'
'username',
'email'
],
#category : 'GitLabHealth-Model-Analysis',
#package : 'GitLabHealth-Model-Analysis'
}

{ #category : 'accessing' }
UserAnalysisReport >> email [

^ email
]

{ #category : 'accessing' }
UserAnalysisReport >> email: anObject [

email := anObject
]

{ #category : 'accessing' }
UserAnalysisReport >> username [

Expand Down
64 changes: 63 additions & 1 deletion src/GitLabHealth-Model-Importer-Tests/GLHApiMock.class.st
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class {
#name : #GLHApiMock,
#superclass : #GLHApi,
#category : 'GitLabHealth-Model-Importer-Tests'
#category : #'GitLabHealth-Model-Importer-Tests'
}

{ #category : #'api - commits' }
Expand All @@ -10,3 +10,65 @@ GLHApiMock >> commitDiff: aCommitID ofProject: aProjectId unidiff: aBoolean [
aCommitID = 'createError' ifTrue: [
^ '{"message":"500 Internal Server Error"}' ]
]

{ #category : #api }
GLHApiMock >> user: aUserID [

^ '{
"id": 123,
"username": "jack.dupond",
"name": "dupond jack",
"state": "active",
"locked": false,
"avatar_url": "https://gitlab.myCompany.com/uploads/-/system/user/avatar/123/avatar.png",
"web_url": "https://gitlab.myCompany.com/Jack.Dupond",
"created_at": "2021-06-19T21:11:06.114+02:00",
"bio": "I am a very good developer. All my life I try to be as good as Badetitou",
"location": "",
"public_email": "jack.dupond-public@myCompany.com",
"skype": "",
"linkedin": "",
"twitter": "",
"discord": "",
"website_url": "",
"organization": "",
"job_title": "",
"pronouns": "",
"bot": false,
"work_information": null,
"followers": 0,
"following": 0,
"is_followed": false,
"local_time": "3:05 PM",
"last_sign_in_at": "2024-10-31T09:16:46.412+01:00",
"confirmed_at": "2021-06-19T21:11:05.919+02:00",
"last_activity_on": "2024-11-04",
"email": "jack.dupond@myCompany.com",
"theme_id": 8,
"color_scheme_id": 1,
"projects_limit": 0,
"current_sign_in_at": "2024-11-04T09:06:50.149+01:00",
"identities": [
{
"provider": "azure_activedirectory_v2",
"extern_uid": "3de29e50-1847-11ccd28ddc23e22a"
}
],
"can_create_group": false,
"can_create_project": false,
"two_factor_enabled": false,
"external": false,
"private_profile": false,
"commit_email": "jack.dupond-commiter@myCompany.com",
"is_admin": false,
"note": null,
"namespace_id": 1234,
"created_by": null,
"email_reset_offered_at": null,
"highest_role": 50,
"current_sign_in_ip": "10.12.0.12",
"last_sign_in_ip": "10.12.0.12",
"sign_in_count": 12345
}
'
]
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Class {
'importer',
'model'
],
#category : 'GitLabHealth-Model-Importer-Tests'
#category : #'GitLabHealth-Model-Importer-Tests'
}

{ #category : #running }
Expand Down Expand Up @@ -53,3 +53,15 @@ GLHModelImporterLocalTest >> testIsServerError [
self assert:
(importer isServerError: '{"message":"500 Internal Server Error"}')
]

{ #category : #tests }
GLHModelImporterLocalTest >> testParseUserResult [

| user |
user := importer importUser: 123.
self assert: user id equals: 123.

self assert: user name equals: 'dupond jack'.
self assert: user email equals: 'jack.dupond@myCompany.com'.
self assert: user public_email equals: 'jack.dupond-public@myCompany.com'.
]

0 comments on commit 1b73d22

Please sign in to comment.