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

fix/add email user to the importer + tests #105

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
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": "[email protected]",
"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": "[email protected]",
"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": "[email protected]",
"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 All @@ -19,7 +19,7 @@ GLHModelImporterLocalTest >> setUp [
importer := GLHModelImporter new.
model := GLHModel new.
importer glhModel: model.
importer glhApi: GLHApiMock new
importer repoApi: GLHApiMock new
]

{ #category : #tests }
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: '[email protected]'.
self assert: user public_email equals: '[email protected]'.
]
Loading