diff --git a/src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st b/src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st index e74badb..1c24ce7 100644 --- a/src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st +++ b/src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st @@ -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 @@ -289,10 +294,10 @@ GitMetricExporter >> exportUserAnalysesInCSV [ exportBrowserModel addColumnForQuery: association value withName: association key ] ]. - - + + file := self constructFilePath: groupOver. - + file writeStreamDo: [ :aStream | exportBrowserModel writeCSVOn: aStream ] ] ] @@ -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. diff --git a/src/GitLabHealth-Model-Analysis/UserAnalysisReport.class.st b/src/GitLabHealth-Model-Analysis/UserAnalysisReport.class.st index 8de5c1f..d9b5535 100644 --- a/src/GitLabHealth-Model-Analysis/UserAnalysisReport.class.st +++ b/src/GitLabHealth-Model-Analysis/UserAnalysisReport.class.st @@ -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 [ diff --git a/src/GitLabHealth-Model-Importer-Tests/GLHApiMock.class.st b/src/GitLabHealth-Model-Importer-Tests/GLHApiMock.class.st index a5835ef..9a87144 100644 --- a/src/GitLabHealth-Model-Importer-Tests/GLHApiMock.class.st +++ b/src/GitLabHealth-Model-Importer-Tests/GLHApiMock.class.st @@ -1,7 +1,7 @@ Class { #name : #GLHApiMock, #superclass : #GLHApi, - #category : 'GitLabHealth-Model-Importer-Tests' + #category : #'GitLabHealth-Model-Importer-Tests' } { #category : #'api - commits' } @@ -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 +} + ' +] diff --git a/src/GitLabHealth-Model-Importer-Tests/GLHModelImporterLocalTest.class.st b/src/GitLabHealth-Model-Importer-Tests/GLHModelImporterLocalTest.class.st index 2723dca..53e1660 100644 --- a/src/GitLabHealth-Model-Importer-Tests/GLHModelImporterLocalTest.class.st +++ b/src/GitLabHealth-Model-Importer-Tests/GLHModelImporterLocalTest.class.st @@ -8,7 +8,7 @@ Class { 'importer', 'model' ], - #category : 'GitLabHealth-Model-Importer-Tests' + #category : #'GitLabHealth-Model-Importer-Tests' } { #category : #running } @@ -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'. +]