From 6f20239a914f9a89eec710fb8991900dfd05e721 Mon Sep 17 00:00:00 2001 From: Kilian B <60846047+knowbased@users.noreply.github.com> Date: Thu, 9 Jan 2025 16:25:55 +0100 Subject: [PATCH] fix(GLHModelImporter): small bug when running main script --- .../GLHModelImporter.class.st | 43 ++++++++++--------- .../GLPHModelImporter.class.st | 13 +++--- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st b/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st index 2b954dc..45de5ed 100644 --- a/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st +++ b/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st @@ -254,12 +254,12 @@ GLHModelImporter >> importAllGroups [ ^ groups ] -{ #category : #'as yet unclassified' } +{ #category : #commits } GLHModelImporter >> importAndLoadLatestsCommitsOfProject: aGLHProject [ - | commits | - self completeImportProject: aGLHProject. - commits := self importLastestCommitsOfProject: aGLHProject. + | commits completedProject | + completedProject := self completeImportProject: aGLHProject. + commits := self importLastestCommitsOfProject: completedProject. commits do: [ :commit | self completeImportedCommit: commit ]. self chainsCommitsFrom: commits. ^ commits @@ -413,23 +413,25 @@ GLHModelImporter >> importCommitsOfProject: aProject since: fromDate until: toDa GLHModelImporter >> importContributedProjectsOfUser: aGLHUser [ | remaningProjects params results projects | - params := { - #order_by -> 'last_activity_at'. - #simple -> 'true'. - } asDictionary. - results := self repoApi projects contributedProjectsOfUser: aGLHUser id withParams: params. - - projects := (results collect: [ :projectsJson | self parseArrayOfProject: projectsJson ]) flattened. - - self glhModel - addAll: projects - unless: self blockOnIdEquality. - + params := { + (#order_by -> 'last_activity_at'). + (#simple -> 'true') } asDictionary. + results := self repoApi projects + contributedProjectsOfUser: aGLHUser id + withParams: params. + + projects := (results collect: [ :projectsJson | + self parseArrayOfProject: projectsJson ]) flattened. + projects := self glhModel + addAll: projects + unless: self blockOnIdEquality. + remaningProjects := self importProjects: ((projects collect: #id) difference: ((self userCatalogue atId: aGLHUser id) at: #contributedProjects)). + aGLHUser contributedProjects addAll: projects , remaningProjects unless: self blockOnIdEquality. @@ -714,12 +716,11 @@ GLHModelImporter >> importUserByUsername: anUsername [ result := self repoApi users allWithParams: params. "when result is an error" - result isArray ifFalse: [ result := { result } ]. + (result isCollection not and: result isEmpty) ifTrue: [ result := { result } ]. - searchResult := (result collect: [ :usersJson | - NeoJSONReader fromString: usersJson ]) - first. - + searchResult := result ifEmpty: [ result ] ifNotEmpty: [(result collect: [ :usersJson | + NeoJSONReader fromString: usersJson ]) first]. + (searchResult class = Dictionary and: [ (searchResult at: #message) includesSubstring: '403 Forbidden' ]) diff --git a/src/GitLabProjectHealth-Model-Importer/GLPHModelImporter.class.st b/src/GitLabProjectHealth-Model-Importer/GLPHModelImporter.class.st index 37dbd7d..a122410 100644 --- a/src/GitLabProjectHealth-Model-Importer/GLPHModelImporter.class.st +++ b/src/GitLabProjectHealth-Model-Importer/GLPHModelImporter.class.st @@ -28,14 +28,15 @@ GLPHModelImporter >> commitsOfProject: aGLHProject forRefName: refName until: to { #category : #'private - api' } GLPHModelImporter >> completeImportProject: aGLHProject [ - |completedProject| - completedProject := super completeImportProject: aGLHProject. + | completedProject | + completedProject := super completeImportProject: aGLHProject. "for this initial import, with only look at some but not all MR" - withInitialMergeRequest ifTrue: [ self - importMergeRequests: completedProject - since: DateAndTime today - until: DateAndTime now. ]. + withInitialMergeRequest ifTrue: [ + self + importMergeRequests: completedProject + since: DateAndTime today + until: DateAndTime now ]. ^ completedProject ]