Skip to content

Commit

Permalink
fix catalogue to add project ids
Browse files Browse the repository at this point in the history
  • Loading branch information
HLAD Nicolas committed Sep 4, 2024
1 parent 65c43f4 commit 7aeba73
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,10 @@ GLHUserCatalogueTest >> testNamesAtChangingUser [
username: 'testUser';
yourself.

user hash. " 114462615"

catalogue addUser: user withName: 'toto'.

user name: 'test User'.

user hash.

self assert: (catalogue namesAt: user) size equals: 3.
self
Expand All @@ -247,6 +244,6 @@ GLHUserCatalogueTest >> testNamesAtChangingUser [
assert: ((catalogue namesAt: user) includes: 'testUser')
equals: true.
self
assert: ((catalogue namesAt: user) includes: 'test user')
equals: true
assert: ((catalogue namesAt: user) includes: 'test User')
equals: false
]
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,17 @@ GLHUserCatalogueV2Test >> testExportAndLoad [
user := GLHUser new
username: 'testUser';
name: 'test user';
contributedProjects: { GLHProject new id: 11 };
yourself.


catalogue addUser: user.
json := catalogue exportToJson.

res := GLHUserCatalogue loadFromJson: json.
self assert: res size equals: catalogue size
res := GLHUserCatalogueV2 loadFromJson: json.
self assert: res size equals: catalogue size.
self assert: ((res at: 'test user' at: #contributedProjects) includes: 11) equals: true.
self assert: ((res at: 'test user' at: #names) includes: 'test user') equals: true.
self assert: ((res at: 'test user' at: #names) includes: 'testUser') equals: true.
]

{ #category : #test }
Expand All @@ -164,12 +167,14 @@ GLHUserCatalogueV2Test >> testExportToJson [
user := GLHUser new
username: 'testUser';
name: 'test user';
contributedProjects: { GLHProject new id: 11 } ;
id: 1;
yourself.
user2 := GLHUser new
username: 'testUser2';
name: 'test user2';
id: 2;
contributedProjects: { GLHProject new id: 21 . GLHProject new id: 22 } ;
yourself.


Expand All @@ -181,7 +186,9 @@ GLHUserCatalogueV2Test >> testExportToJson [
res := STONJSON fromString: json.
self assert: res size equals: catalogue size.
self assert: ((res at: 'test user2') at: #foundNames) size equals: 2.
self assert: ((res at: 'test user') at: #foundNames) size equals: 2
self assert: ((res at: 'test user') at: #foundNames) size equals: 2.
self assert: ((res at: 'test user') at: #contributedProjects) size equals: 1.
self assert: ((res at: 'test user2') at: #contributedProjects) size equals: 2.
]

{ #category : #'as yet unclassified' }
Expand Down
49 changes: 44 additions & 5 deletions src/GitLabHealth-Model-Analysis/GLHUserCatalogueV2.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ GLHUserCatalogueV2 class >> loadFromJson: aString [
catalogue := self new.
dic := (STONJSON fromString: aString) asDictionary.
dic associationsDo: [ :assoc |
| itsName itsUsername itsCommitNames itsId |
| itsName itsUsername itsCommitNames itsId itsProjectIDs|
itsName := assoc key.
itsCommitNames := assoc value at: #foundNames.
itsUsername := assoc value at: #username.
itsId := assoc value at: #id.
itsProjectIDs := assoc value at: #contributedProjects ifAbsent: [{}].

catalogue
addUser: (GLHUser new
id: itsId;
username: itsUsername;
name: itsName;
yourself)
withNames: itsCommitNames ].
withNames: itsCommitNames
withProjects: itsProjectIDs ].

^ catalogue
]
Expand Down Expand Up @@ -186,6 +188,12 @@ GLHUserCatalogueV2 >> anImporter: aGLHModelImporter [

]

{ #category : #accessing }
GLHUserCatalogueV2 >> atId: anId [
^ self detect: [ :entry |
(entry at: #user) id = anId ]
]

{ #category : #'as yet unclassified' }
GLHUserCatalogueV2 >> collectUsernames [

Expand Down Expand Up @@ -237,15 +245,17 @@ GLHUserCatalogueV2 >> exportToJson [
(#id -> assoc key id) } asDictionary); yourself ]."
tempDic := Dictionary new.
self associationsDo: [ :assoc |
|entry user names|
|entry user names projectIDs|
entry := assoc value.
user := entry at: #user.
names := entry at: #names.
projectIDs := entry at: #contributedProjects.
tempDic
at: assoc key put: {
(#name -> user name).
(#username -> user username).
(#foundNames -> names asArray).
(#contributedProjects -> projectIDs asArray).
(#id -> user id) } asDictionary;
yourself ].

Expand All @@ -270,7 +280,9 @@ GLHUserCatalogueV2 >> initACatalogueEntryForUser: aGLHUser [.
add: aGLHUser username;
add: aGLHUser name;
yourself);
at: #contributedProjects put: (Set new);
at: #contributedProjects put: (Set new
addAll: (aGLHUser contributedProjects collect: #id);
yourself );
yourself
]

Expand Down Expand Up @@ -323,10 +335,37 @@ GLHUserCatalogueV2 >> reImportAllUsers [
assoc value at: #user put: user ]
]

{ #category : #'as yet unclassified' }
GLHUserCatalogueV2 >> reImportUser: aGLHUser [
"use it after a catalogue import from JSON"
|user|
user := anImporter
ifNotNil: [
aGLHUser id
ifNotNil: [ anImporter importUser: aGLHUser id ]
ifNil: [ anImporter importUserByUsername: aGLHUser username ] ]
ifNil: [aGLHUser].


self at: aGLHUser name at: #user put: (user).

]

{ #category : #scrape }
GLHUserCatalogueV2 >> scrapeAuthorNameForAllRealUsers [

|listOfUsers|
listOfUsers := self users select: [ :user | user id isNotNil ].
listOfUsers do: [ :user | self scrapeAuthorNameForUser: user ].
]

{ #category : #'as yet unclassified' }
GLHUserCatalogueV2 >> scrapeAuthorNameForAllUsers [

self users do: [ :user | self scrapeAuthorNameForUser: user ]
|listOfUsers|

listOfUsers := self users.
listOfUsers do: [ :user | self scrapeAuthorNameForUser: user ]
]

{ #category : #'as yet unclassified' }
Expand Down
13 changes: 8 additions & 5 deletions src/GitLabHealth-Model-Importer/GLHModelImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ GLHModelImporter >> importCommitsOfBranch: aGLHBranch forRefName: refName until:
{ #category : #'as yet unclassified' }
GLHModelImporter >> importContributedProjectsOfUser: aGLHUser [

| newlyFoundElmts page foundElmts knownProjects|
| newlyFoundElmts page foundElmts remaningProjects|
page := 0.
foundElmts := OrderedCollection new.
newlyFoundElmts := { true }.
Expand All @@ -519,12 +519,15 @@ GLHModelImporter >> importContributedProjectsOfUser: aGLHUser [
(self glhModel
addAll: newlyFoundElmts
unless: self blockOnIdEquality) ].

knownProjects := self importProject: ((self userCatalogue at: aGLHUser name) at: #contributedProjects).


remaningProjects := self importProjects: ((foundElmts collect: #id) difference: ((self userCatalogue atId: aGLHUser id) at: #contributedProjects)).

aGLHUser contributedProjects
addAll: (foundElmts, knownProjects)
addAll: (foundElmts, remaningProjects)
unless: self blockOnIdEquality.

self userCatalogue addUser: aGLHUser withProjects: (aGLHUser contributedProjects collect: #id).

^ foundElmts
]
Expand Down Expand Up @@ -1062,7 +1065,7 @@ GLHModelImporter >> parsePipelinesResult: result [

| reader |

result = '{"message":"403 Forbidden"}' ifTrue: [ ^ { } ].
(result includesSubstring: '{"message":"40' )ifTrue: [ ^ { } ].

reader := NeoJSONReader on: result readStream.
reader mapInstVarsFor: GLHPipeline.
Expand Down

0 comments on commit 7aeba73

Please sign in to comment.