diff --git a/src/GitLabHealth-Model-Analysis-Tests/GLHUserCatalogueTest.class.st b/src/GitLabHealth-Model-Analysis-Tests/GLHUserCatalogueTest.class.st index f828a73..ac24887 100644 --- a/src/GitLabHealth-Model-Analysis-Tests/GLHUserCatalogueTest.class.st +++ b/src/GitLabHealth-Model-Analysis-Tests/GLHUserCatalogueTest.class.st @@ -4,14 +4,22 @@ A GLHUserCatalogueTest is a test class for testing the behavior of GLHUserCatalo Class { #name : #GLHUserCatalogueTest, #superclass : #TestCase, + #instVars : [ + 'catalogue' + ], #category : #'GitLabHealth-Model-Analysis-Tests' } +{ #category : #running } +GLHUserCatalogueTest >> setUp [ + + catalogue := GLHUserCatalogue new. +] + { #category : #test } GLHUserCatalogueTest >> testAddSameUser [ - | user catalogue | - catalogue := GLHUserCatalogue new. + | user | user := GLHUser new username: 'testUser'; @@ -27,24 +35,24 @@ GLHUserCatalogueTest >> testAddSameUser [ { #category : #test } GLHUserCatalogueTest >> testAddUser [ - | user catalogue | - catalogue := GLHUserCatalogue new. + | user | + user := GLHUser new username: 'testUser'; name: 'test user'; yourself. - catalogue addUser: user. - - self assert: catalogue size equals: 1. + catalogue addUser: user. + + self assert: catalogue size equals: 1 ] { #category : #test } GLHUserCatalogueTest >> testAddUserWithName [ - | user catalogue | - catalogue := GLHUserCatalogue new. + | user | + user := GLHUser new username: 'testUser'; @@ -64,30 +72,27 @@ GLHUserCatalogueTest >> testAddUserWithName [ { #category : #test } GLHUserCatalogueTest >> testAddUserWithNames [ - - | user catalogue | - catalogue := GLHUserCatalogue new. + | user | + user := GLHUser new username: 'testUser'; name: 'test user'; yourself. - catalogue addUser: user withNames: {'toto' . 'tata' . 'titi'}. - + catalogue addUser: user withNames: { 'toto'. 'tata'. 'titi' }. + self assert: (catalogue at: user) size equals: 5. self assert: ((catalogue at: user) includes: 'toto') equals: true. self assert: ((catalogue at: user) includes: 'tata') equals: true. - self - assert: ((catalogue at: user) includes: 'titi') - equals: true + self assert: ((catalogue at: user) includes: 'titi') equals: true ] { #category : #test } GLHUserCatalogueTest >> testAddUsers [ - | user1 user2 catalogue | - catalogue := GLHUserCatalogue new. + | user1 user2 | + user1 := GLHUser new username: 'testUser1'; @@ -108,8 +113,8 @@ GLHUserCatalogueTest >> testAddUsers [ { #category : #test } GLHUserCatalogueTest >> testCollectUsernames [ - | user1 user2 catalogue res | - catalogue := GLHUserCatalogue new. + | user1 user2 res | + user1 := GLHUser new username: 'testUser1'; @@ -126,25 +131,23 @@ GLHUserCatalogueTest >> testCollectUsernames [ res := catalogue collectUsernames. - - self assert: res size equals: 4. - self assert: (res at: 'testUser1') equals: user1. - self assert: (res at: 'testUser2') equals: user2. - self assert: (res at: 'test user1') equals: user1. - self assert: (res at: 'test user2') equals: user2. - + self assert: res size equals: 4. + self assert: (res at: 'testUser1') equals: user1. + self assert: (res at: 'testUser2') equals: user2. + self assert: (res at: 'test user1') equals: user1. + self assert: (res at: 'test user2') equals: user2 ] { #category : #tests } GLHUserCatalogueTest >> testExportAndLoad [ - | user json catalogue res | + | user json res | user := GLHUser new username: 'testUser'; name: 'test user'; yourself. - catalogue := GLHUserCatalogue new. + catalogue addUser: user. json := catalogue exportToJson. @@ -156,27 +159,28 @@ GLHUserCatalogueTest >> testExportAndLoad [ { #category : #test } GLHUserCatalogueTest >> testExportToJson [ - | user user2 json catalogue res | + | user user2 json res | user := GLHUser new username: 'testUser'; name: 'test user'; - id: 1; - yourself. - user2 := GLHUser new - username: 'testUser2'; - name: 'test user2'; - id: 2; + id: 1; yourself. - catalogue := GLHUserCatalogue new. + user2 := GLHUser new + username: 'testUser2'; + name: 'test user2'; + id: 2; + yourself. - catalogue addUser: user; addUser: user2. + + catalogue + addUser: user; + addUser: user2. json := catalogue exportToJson. - res := (STONJSON fromString: json). + 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 user2') at: #foundNames) size equals: 2. + self assert: ((res at: 'test user') at: #foundNames) size equals: 2 ] { #category : #tests } @@ -190,3 +194,59 @@ GLHUserCatalogueTest >> testLoadFromJson [ self assert: (res searchUserWithName: 'Nicolas') isNotEmpty equals: true. self assert: (res searchUserWithName: 'VERHAEGHE') isNotEmpty equals: true. ] + +{ #category : #test } +GLHUserCatalogueTest >> testNamesAt [ + + | user | + + + user := GLHUser new + username: 'testUser'; + name: 'test user'; + yourself. + + catalogue addUser: user withName: 'toto'. + + + self assert: (catalogue namesAt: user) size equals: 3. + self + assert: ((catalogue namesAt: user) includes: 'toto') + equals: true. + self + assert: ((catalogue namesAt: user) includes: 'testUser') + equals: true. + self + assert: ((catalogue namesAt: user) includes: 'test user') + equals: true +] + +{ #category : #test } +GLHUserCatalogueTest >> testNamesAtChangingUser [ + + | user | + + + user := GLHUser new + 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 + assert: ((catalogue namesAt: user) includes: 'toto') + equals: true. + self + assert: ((catalogue namesAt: user) includes: 'testUser') + equals: true. + self + assert: ((catalogue namesAt: user) includes: 'test user') + equals: true +] diff --git a/src/GitLabHealth-Model-Analysis-Tests/GLHUserCatalogueV2Test.class.st b/src/GitLabHealth-Model-Analysis-Tests/GLHUserCatalogueV2Test.class.st new file mode 100644 index 0000000..b1e9b90 --- /dev/null +++ b/src/GitLabHealth-Model-Analysis-Tests/GLHUserCatalogueV2Test.class.st @@ -0,0 +1,259 @@ +Class { + #name : #GLHUserCatalogueV2Test, + #superclass : #TestCase, + #instVars : [ + 'catalogue' + ], + #category : #'GitLabHealth-Model-Analysis-Tests' +} + +{ #category : #running } +GLHUserCatalogueV2Test >> setUp [ + + catalogue := GLHUserCatalogueV2 new +] + +{ #category : #test } +GLHUserCatalogueV2Test >> testAddSameUser [ + + | user | + + user := GLHUser new + username: 'testUser'; + name: 'test user'; + yourself. + + catalogue addUser: user. + catalogue addUser: user. + + self assert: catalogue size equals: 1 +] + +{ #category : #test } +GLHUserCatalogueV2Test >> testAddUser [ + + | user | + + + user := GLHUser new + username: 'testUser'; + name: 'test user'; + yourself. + + catalogue addUser: user. + + self assert: catalogue size equals: 1 +] + +{ #category : #test } +GLHUserCatalogueV2Test >> testAddUserWithName [ + + | user | + + + user := GLHUser new + username: 'testUser'; + name: 'test user'; + yourself. + + catalogue addUser: user withName: 'toto'. + + self assert: (catalogue namesAt: user) size equals: 3. + self assert: ((catalogue namesAt: user) includes: 'toto') equals: true. + self assert: ((catalogue namesAt: user) includes: 'testUser') equals: true. + self + assert: ((catalogue namesAt: user) includes: 'test user') + equals: true +] + +{ #category : #test } +GLHUserCatalogueV2Test >> testAddUserWithNames [ + + | user | + user := GLHUser new + username: 'testUser'; + name: 'test user'; + yourself. + + catalogue addUser: user withNames: { 'toto'. 'tata'. 'titi' }. + + self assert: (catalogue namesAt: user) size equals: 5. + self + assert: ((catalogue namesAt: user) includes: 'toto') + equals: true. + self + assert: ((catalogue namesAt: user) includes: 'tata') + equals: true. + self + assert: ((catalogue namesAt: user) includes: 'titi') + equals: true +] + +{ #category : #test } +GLHUserCatalogueV2Test >> testAddUsers [ + + | user1 user2 | + + + user1 := GLHUser new + username: 'testUser1'; + name: 'test user1'; + yourself. + + user2 := GLHUser new + username: 'testUser2'; + name: 'test user2'; + yourself. + + catalogue addUser: user1. + catalogue addUser: user2. + + self assert: catalogue size equals: 2 +] + +{ #category : #test } +GLHUserCatalogueV2Test >> testCollectUsernames [ + + | user1 user2 res | + + + user1 := GLHUser new + username: 'testUser1'; + name: 'test user1'; + yourself. + + user2 := GLHUser new + username: 'testUser2'; + name: 'test user2'; + yourself. + + catalogue addUser: user1. + catalogue addUser: user2. + + + res := catalogue collectUsernames. + + self assert: res size equals: 4. + self assert: (res at: 'testUser1') equals: user1. + self assert: (res at: 'testUser2') equals: user2. + self assert: (res at: 'test user1') equals: user1. + self assert: (res at: 'test user2') equals: user2 +] + +{ #category : #tests } +GLHUserCatalogueV2Test >> testExportAndLoad [ + + | user json res | + user := GLHUser new + username: 'testUser'; + name: 'test user'; + yourself. + + + catalogue addUser: user. + json := catalogue exportToJson. + + res := GLHUserCatalogue loadFromJson: json. + self assert: res size equals: catalogue size +] + +{ #category : #test } +GLHUserCatalogueV2Test >> testExportToJson [ + + | user user2 json res | + user := GLHUser new + username: 'testUser'; + name: 'test user'; + id: 1; + yourself. + user2 := GLHUser new + username: 'testUser2'; + name: 'test user2'; + id: 2; + yourself. + + + catalogue + addUser: user; + addUser: user2. + json := catalogue exportToJson. + + 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 +] + +{ #category : #tests } +GLHUserCatalogueV2Test >> testLoadFromJson [ + + | json res | + json := '{"Benoit VERHAEGHE":{"id":1,"username":"Benoit.VERHAEGHE","foundNames":["Benoit VERHAEGHE","Benoit.VERHAEGHE","Benoît VERHAEGHE","Benoît Verhaeghe"],"name":"Benoit VERHAEGHE"},"HLAD Nicolas":{"id":2,"username":"Nicolas.HLAD","foundNames":["Nicolas Hlad","Nicolas.HLAD","HLAD Nicolas"],"name":"HLAD Nicolas"}}'. + + res := GLHUserCatalogue loadFromJson: json. + self assert: res size equals: 2. + + self + assert: (res searchUserWithName: 'Hlad') anyOne name + equals: 'HLAD Nicolas'. + self + assert: (res searchUserWithName: 'VERHAEGHE') anyOne name + equals: 'Benoit VERHAEGHE'. +] + +{ #category : #test } +GLHUserCatalogueV2Test >> testNamesAt [ + + | user | + + + user := GLHUser new + username: 'testUser'; + name: 'test user'; + yourself. + + catalogue addUser: user withName: 'toto'. + + + self assert: (catalogue namesAt: user) size equals: 3. + self + assert: ((catalogue namesAt: user) includes: 'toto') + equals: true. + self + assert: ((catalogue namesAt: user) includes: 'testUser') + equals: true. + self + assert: ((catalogue namesAt: user) includes: 'test user') + equals: true +] + +{ #category : #test } +GLHUserCatalogueV2Test >> testNamesAtChangingUser [ + + | user | + + + user := GLHUser new + name: 'test User'; + yourself. + + user hash. " 114462615" + + catalogue addUser: user withName: 'toto'. + + user username: 'testUser'. + + user hash. + + self assert: (catalogue namesAt: user) size equals: 3. + self + assert: ((catalogue namesAt: user) includes: 'toto') + equals: true. + "his username has been added after so its not in the catalogue" + self + assert: ((catalogue namesAt: user) includes: 'testUser') + equals: false. + self + assert: ((catalogue namesAt: user) includes: 'test User') + equals: true +] diff --git a/src/GitLabHealth-Model-Analysis/GLHUserCatalogue.class.st b/src/GitLabHealth-Model-Analysis/GLHUserCatalogue.class.st index 06d12f0..4881058 100644 --- a/src/GitLabHealth-Model-Analysis/GLHUserCatalogue.class.st +++ b/src/GitLabHealth-Model-Analysis/GLHUserCatalogue.class.st @@ -12,18 +12,24 @@ Class { GLHUserCatalogue class >> loadFromJson: aString [ | catalogue dic | - catalogue := GLHUserCatalogue new. + catalogue := self new. dic := (STONJSON fromString: aString) asDictionary. dic associationsDo: [ :assoc | - | itsName itsUsername itsCommitNames itsId| + | itsName itsUsername itsCommitNames itsId | itsName := assoc key. itsCommitNames := assoc value at: #foundNames. - itsUsername := assoc value at: #username. + itsUsername := assoc value at: #username. itsId := assoc value at: #id. - - catalogue addUser: (GLHUser new id: itsId; username: itsUsername; name: itsName; yourself ) withNames: itsCommitNames ]. - - ^ catalogue . + + catalogue + addUser: (GLHUser new + id: itsId; + username: itsUsername; + name: itsName; + yourself) + withNames: itsCommitNames ]. + + ^ catalogue ] { #category : #'as yet unclassified' } @@ -121,13 +127,20 @@ GLHUserCatalogue >> anImporter: aGLHModelImporter [ ] +{ #category : #accessing } +GLHUserCatalogue >> atWithId: anId [ + |res | + res := self associations detect: [ :assoc | assoc key id = anId ] ifNone: [ nil ]. + ^ res ifNotNil: [ res value ]. +] + { #category : #'as yet unclassified' } GLHUserCatalogue >> collectUsernames [ | username2User | self ifEmpty: [ ^ { } ]. - username2User := Dictionary new. + username2User := OrderedDictionary new. self associationsDo: [ :assoc | | user | @@ -190,7 +203,15 @@ GLHUserCatalogue >> initialize [ ] { #category : #'as yet unclassified' } -GLHUserCatalogue >> loadAllUsers [ +GLHUserCatalogue >> namesAt: aGLHUser [ + + | assoc | + assoc := self associationAt: aGLHUser. + ^ assoc value +] + +{ #category : #'as yet unclassified' } +GLHUserCatalogue >> reImportAllUsers [ "use it after a catalogue import from JSON" self associationsDo: [ :assoc | @@ -222,6 +243,14 @@ GLHUserCatalogue >> scrapeAuthorNameForUser: aGLHUser [ contributedProjectsForCommitAuthorsRelatedToUser: aGLHUser) ] +{ #category : #scrape } +GLHUserCatalogue >> scrapeAuthorNamesForUsers: aUserCollection [ + + aUserCollection do: [ :aGLHUser | + self scrapeAuthorNameForUser: aGLHUser + ]. +] + { #category : #completion } GLHUserCatalogue >> searchModelForAuthorNamesOfUser: aGLHUser [ |assoc| diff --git a/src/GitLabHealth-Model-Analysis/GLHUserCatalogueItem.class.st b/src/GitLabHealth-Model-Analysis/GLHUserCatalogueItem.class.st new file mode 100644 index 0000000..108c1d6 --- /dev/null +++ b/src/GitLabHealth-Model-Analysis/GLHUserCatalogueItem.class.st @@ -0,0 +1,15 @@ +Class { + #name : #GLHUserCatalogueItem, + #superclass : #Dictionary, + #instVars : [ + 'user', + 'names' + ], + #category : #'GitLabHealth-Model-Analysis' +} + +{ #category : #initialization } +GLHUserCatalogueItem >> initialize [ + + names := Set new. +] diff --git a/src/GitLabHealth-Model-Analysis/GLHUserCatalogueV2.class.st b/src/GitLabHealth-Model-Analysis/GLHUserCatalogueV2.class.st new file mode 100644 index 0000000..d289db3 --- /dev/null +++ b/src/GitLabHealth-Model-Analysis/GLHUserCatalogueV2.class.st @@ -0,0 +1,289 @@ +Class { + #name : #GLHUserCatalogueV2, + #superclass : #GLHUserCatalogue, + #category : #'GitLabHealth-Model-Analysis' +} + +{ #category : #import } +GLHUserCatalogueV2 class >> loadFromJson: aString [ + + | catalogue dic | + catalogue := self new. + dic := (STONJSON fromString: aString) asDictionary. + dic associationsDo: [ :assoc | + | itsName itsUsername itsCommitNames itsId| + itsName := assoc key. + itsCommitNames := assoc value at: #foundNames. + itsUsername := assoc value at: #username. + itsId := assoc value at: #id. + + catalogue addUser: (GLHUser new id: itsId; username: itsUsername; name: itsName; yourself ) withNames: itsCommitNames ]. + + ^ catalogue . +] + +{ #category : #'as yet unclassified' } +GLHUserCatalogueV2 class >> scrapeContributedProjectsForCommitAuthorsRelatedToUser: aGLHUser [ + "get all " + + | maxProjects itsProjects | + self + deprecated: + 'Use #scrapeWithImporter:ContributedProjectsForCommitAuthorsRelatedToUser: instead' + on: '12 August 2024' + in: + 'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'. + + aGLHUser id ifNil: [ ^ { } asSet ]. + + maxProjects := 10. + + GLHModelImporter current withCommitDiffs: false. + itsProjects := aGLHUser contributedProjects ifEmpty: [ + GLHModelImporter current + importContributedProjectsOfUser: aGLHUser ]. + + itsProjects + collect: [ :project | + GLHModelImporter current importAndLoadLatestsCommitsOfProject: + project ] + from: 1 + to: (itsProjects size min: maxProjects). + + ^ (aGLHUser commits collect: [ :commit | commit author_name ]) asSet +] + +{ #category : #'as yet unclassified' } +GLHUserCatalogueV2 class >> scrapeWithImporter: anImporter contributedProjectsForCommitAuthorsRelatedToUser: aGLHUser [ + "get all " + + | maxProjects itsProjects | + aGLHUser id ifNil: [ ^ { } asSet ]. + + maxProjects := 10. + + anImporter withCommitDiffs: false. + itsProjects := aGLHUser contributedProjects ifEmpty: [ + anImporter + importContributedProjectsOfUser: aGLHUser ]. + + itsProjects + collect: [ :project | + anImporter importAndLoadLatestsCommitsOfProject: + project ] + from: 1 + to: (itsProjects size min: maxProjects). + + ^ (aGLHUser commits collect: [ :commit | commit author_name ]) asSet +] + +{ #category : #adding } +GLHUserCatalogueV2 >> addUser: aGLHUser [ + + self at: aGLHUser name ifAbsentPut: [ + self newEntryForUser: aGLHUser ] +] + +{ #category : #adding } +GLHUserCatalogueV2 >> addUser: aGLHUser withName: name [ + + self + at: aGLHUser name + ifPresent: [ :entry | (entry at: #names) add: name ] + ifAbsentPut: [ + |entry| + entry := (self newEntryForUser: aGLHUser). + (entry at: #names) add: name. + entry + ] +] + +{ #category : #adding } +GLHUserCatalogueV2 >> addUser: aGLHUser withNames: aCollectionOfNames [ + + self + at: aGLHUser name + ifPresent: [ :entry | (entry at: #names) addAll: aCollectionOfNames ] + ifAbsentPut: [ + |entry| + entry := (self newEntryForUser: aGLHUser ). + (entry at: #names ) addAll: aCollectionOfNames. + entry ] +] + +{ #category : #accessing } +GLHUserCatalogueV2 >> anImporter: aGLHModelImporter [ + anImporter := aGLHModelImporter + +] + +{ #category : #'as yet unclassified' } +GLHUserCatalogueV2 >> collectUsernames [ + + | username2User | + self ifEmpty: [ ^ { } ]. + + username2User := OrderedDictionary new. + + self associationsDo: [ :assoc | + | user | + user := assoc value at: #user . + (assoc value at: #names) do: [ :username | username2User at: username put: user ] ]. + + ^ username2User +] + +{ #category : #completion } +GLHUserCatalogueV2 >> completeAuthorNameOfUser: aGLHUser with: authorName [ + + self + deprecated: 'Use #addUser:withName: instead' + on: '12 August 2024' + in: + 'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'. + + self addUser: aGLHUser withName: authorName +] + +{ #category : #completion } +GLHUserCatalogueV2 >> completeAuthorNameOfUser: aGLHUser withAll: authorNames [ + + self + deprecated: 'Use #addUser:withNames: instead' + on: '12 August 2024' + in: + 'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'. + + + self addUser: aGLHUser withNames: authorNames +] + +{ #category : #export } +GLHUserCatalogueV2 >> exportToJson [ + + | tempDic | + " tempDic := self associations collect: [ :assoc | + Dictionary new at: (assoc key name) put: ({ + (#names -> assoc value asArray). + (#id -> assoc key id) } asDictionary); yourself ]." + tempDic := Dictionary new. + self associationsDo: [ :assoc | + |entry user names| + entry := assoc value. + user := entry at: #user. + names := entry at: #names. + tempDic + at: assoc key put: { + (#name -> user name). + (#username -> user username). + (#foundNames -> names asArray). + (#id -> user id) } asDictionary; + yourself ]. + + ^ STONJSON toString: tempDic +] + +{ #category : #initialization } +GLHUserCatalogueV2 >> initialize [ + + anImporter := GLHModelImporter current. +] + +{ #category : #'accessing - name' } +GLHUserCatalogueV2 >> names [ + ^ self collect: [ :entry | entry at: #names ] +] + +{ #category : #'as yet unclassified' } +GLHUserCatalogueV2 >> namesAt: aGLHUser [ + ^ (self at: aGLHUser name) at: #names. +] + +{ #category : #'instance creation' } +GLHUserCatalogueV2 >> newEntryForUser: aGLHUser [. + +^ Dictionary new + at: #user put: aGLHUser; + at: #names put: (Set new + add: aGLHUser username; + add: aGLHUser name; + yourself); + yourself +] + +{ #category : #'as yet unclassified' } +GLHUserCatalogueV2 >> reImportAllUsers [ + "use it after a catalogue import from JSON" + + self associationsDo: [ :assoc | + | user | + user := assoc value at: #user. + user := anImporter + ifNotNil: [ + user id + ifNotNil: [ anImporter importUser: user id ] + ifNil: [ anImporter importUserByUsername: user username ] ] + ifNil: [user]. + assoc value at: #user put: user ] +] + +{ #category : #'as yet unclassified' } +GLHUserCatalogueV2 >> scrapeAuthorNameForAllUsers [ + + self users do: [ :user | self scrapeAuthorNameForUser: user ] +] + +{ #category : #'as yet unclassified' } +GLHUserCatalogueV2 >> scrapeAuthorNameForUser: aGLHUser [ + + self addUser: aGLHUser withNames: (GLHUserCatalogue + scrapeWithImporter: anImporter + contributedProjectsForCommitAuthorsRelatedToUser: aGLHUser). +] + +{ #category : #scrape } +GLHUserCatalogueV2 >> scrapeAuthorNamesForUsers: aUserCollection [ + + aUserCollection do: [ :aGLHUser | + self scrapeAuthorNameForUser: aGLHUser + ]. +] + +{ #category : #search } +GLHUserCatalogueV2 >> searchId: anId [ + ^ self select: [ :entry | (entry at: #user) id = anId ]. +] + +{ #category : #completion } +GLHUserCatalogueV2 >> searchModelForAuthorNamesOfUser: aGLHUser [ + + self addUser: aGLHUser withNames: + (aGLHUser commits collect: [ :c | c author_name ]) +] + +{ #category : #search } +GLHUserCatalogueV2 >> searchName: aName [ + + ^ self select: [ :entry | + |collectionOfName| + collectionOfName := entry at: #names. + (' ' join: collectionOfName) asLowercase includesSubstring: + aName asLowercase ] +] + +{ #category : #search } +GLHUserCatalogueV2 >> searchUserWithName: aName [ + + ^ (self searchName: aName) users +] + +{ #category : #accessing } +GLHUserCatalogueV2 >> userAt: aGLHUser [ + ^ (self at: aGLHUser name) at: #user. +] + +{ #category : #accessing } +GLHUserCatalogueV2 >> users [ + + ^ self collect: [ :entry | entry at: #user ]. +] diff --git a/src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st b/src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st index af7b0ec..744c658 100644 --- a/src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st +++ b/src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st @@ -378,3 +378,39 @@ GitMetricExporter >> onlyImportProjectsOfGroup: groupId [ group := glhImporter importGroup: groupId. projectCache := group toScope: GLHProject ] + +{ #category : #adding } +GitMetricExporter >> setupAnalysisForUsersWithNames: userNames [ + "import all the project since a certain time" + + | users | + users := userNames collect: [ :username | + glhImporter importUserByUsername: username ]. + + glhImporter userCatalogue scrapeAuthorNamesForUsers: users. + + entities addAll: (users collect: [ :user | + | itsProjects metrics i size | + itsProjects := glhImporter importContributedProjectsOfUser: user. + + metrics := GitMetric4User new. + metrics + glhImporter: glhImporter; + user: user. + + i := 0. + size := itsProjects size. + metrics itsProjects: (itsProjects collect: [ :p | + (' ' join: { + 'complete import of project:'. + p name printString. + '['. + (i := i + 1) printString. + '/'. + size. + ']' }) recordInfo. + + p id -> (glhImporter completeImportProject: p) ]) asDictionary ]). + + ^ self +] diff --git a/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st b/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st index 9a1abf7..69008a4 100644 --- a/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st +++ b/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st @@ -857,7 +857,9 @@ GLHModelImporter >> initialize [ withInitialCommits := false. withInitialMergeRequest := false. withCommitsSince := (Date today - 1 week) asDateAndTime. - userCatalogue := GLHUserCatalogue new anImporter: self; yourself. + userCatalogue := GLHUserCatalogueV2 new + anImporter: self; + yourself. self initReader ]