From 7aeba7371c1de9d29e28e0d5c770862a305156ab Mon Sep 17 00:00:00 2001 From: HLAD Nicolas Date: Wed, 4 Sep 2024 15:12:48 +0200 Subject: [PATCH] fix catalogue to add project ids --- .../GLHUserCatalogueTest.class.st | 7 +-- .../GLHUserCatalogueV2Test.class.st | 15 ++++-- .../GLHUserCatalogueV2.class.st | 49 +++++++++++++++++-- .../GLHModelImporter.class.st | 13 +++-- 4 files changed, 65 insertions(+), 19 deletions(-) diff --git a/src/GitLabHealth-Model-Analysis-Tests/GLHUserCatalogueTest.class.st b/src/GitLabHealth-Model-Analysis-Tests/GLHUserCatalogueTest.class.st index ac24887..84ccd0c 100644 --- a/src/GitLabHealth-Model-Analysis-Tests/GLHUserCatalogueTest.class.st +++ b/src/GitLabHealth-Model-Analysis-Tests/GLHUserCatalogueTest.class.st @@ -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 @@ -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 ] diff --git a/src/GitLabHealth-Model-Analysis-Tests/GLHUserCatalogueV2Test.class.st b/src/GitLabHealth-Model-Analysis-Tests/GLHUserCatalogueV2Test.class.st index a8c7e05..0cb4535 100644 --- a/src/GitLabHealth-Model-Analysis-Tests/GLHUserCatalogueV2Test.class.st +++ b/src/GitLabHealth-Model-Analysis-Tests/GLHUserCatalogueV2Test.class.st @@ -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 } @@ -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. @@ -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' } diff --git a/src/GitLabHealth-Model-Analysis/GLHUserCatalogueV2.class.st b/src/GitLabHealth-Model-Analysis/GLHUserCatalogueV2.class.st index 6bb93ef..39a8edf 100644 --- a/src/GitLabHealth-Model-Analysis/GLHUserCatalogueV2.class.st +++ b/src/GitLabHealth-Model-Analysis/GLHUserCatalogueV2.class.st @@ -11,11 +11,12 @@ 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 @@ -23,7 +24,8 @@ GLHUserCatalogueV2 class >> loadFromJson: aString [ username: itsUsername; name: itsName; yourself) - withNames: itsCommitNames ]. + withNames: itsCommitNames + withProjects: itsProjectIDs ]. ^ catalogue ] @@ -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 [ @@ -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 ]. @@ -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 ] @@ -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' } diff --git a/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st b/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st index 645486a..0cfb639 100644 --- a/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st +++ b/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st @@ -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 }. @@ -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 ] @@ -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.