diff --git a/src/GitLabHealth-Model-Importer-Tests/GLHApiMock.class.st b/src/GitLabHealth-Model-Importer-Tests/GLHApiMock.class.st new file mode 100644 index 0000000..8ccfe28 --- /dev/null +++ b/src/GitLabHealth-Model-Importer-Tests/GLHApiMock.class.st @@ -0,0 +1,12 @@ +Class { + #name : #GLHApiMock, + #superclass : #GLHApi, + #category : #'GitLabHealth-Model-Importer-Tests' +} + +{ #category : #'api - commits' } +GLHApiMock >> commitDiff: aCommitID ofProject: aProjectId unidiff: aBoolean [ + + aCommitID = 'createError' ifTrue: [ + ^ '{"message":"500 Internal Server Error"}' ] +] diff --git a/src/GitLabHealth-Model-Importer-Tests/GLHModelImporterLocalTest.class.st b/src/GitLabHealth-Model-Importer-Tests/GLHModelImporterLocalTest.class.st index 8e61c1c..d11f892 100644 --- a/src/GitLabHealth-Model-Importer-Tests/GLHModelImporterLocalTest.class.st +++ b/src/GitLabHealth-Model-Importer-Tests/GLHModelImporterLocalTest.class.st @@ -8,7 +8,7 @@ Class { 'importer', 'model' ], - #category : 'GitLabHealth-Model-Importer-Tests' + #category : #'GitLabHealth-Model-Importer-Tests' } { #category : #running } @@ -18,7 +18,22 @@ GLHModelImporterLocalTest >> setUp [ importer := GLHModelImporter new. model := GLPHEModel new. - importer glhModel: model + importer glhModel: model. + importer glhApi: GLHApiMock new +] + +{ #category : #tests } +GLHModelImporterLocalTest >> testImportDiffOfCommitWithServerRaiseError [ + + | commit repo project | + commit := model newCommit. + commit id: 'createError'. + repo := model newRepository. + commit repository: repo. + project := model newProject. + repo project: project. + importer importDiffOfCommit: commit. + self assert: commit diffs isEmpty ] { #category : #tests } @@ -31,3 +46,10 @@ GLHModelImporterLocalTest >> testImportUserAlreadyInModel [ model add: user. self assert: (importer importUser: 12) equals: user ] + +{ #category : #tests } +GLHModelImporterLocalTest >> testIsServerError [ + + self assert: + (importer isServerError: '{"message":"500 Internal Server Error"}') +] diff --git a/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st b/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st index 243e6a9..64269b1 100644 --- a/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st +++ b/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st @@ -611,6 +611,7 @@ GLHModelImporter >> importDiffOfCommit: aCommit [ commitDiff: aCommit id ofProject: aCommit repository project id unidiff: true. + (self isServerError: result) ifTrue: [ ^ { } ]. diffsResult := self newParseDiffResult: result. ^ aCommit diffs addAll: diffsResult unless: self blockForDiffEquality. @@ -926,6 +927,11 @@ GLHModelImporter >> initialize [ ] +{ #category : #api } +GLHModelImporter >> isServerError: aString [ + ^ aString = '{"message":"500 Internal Server Error"}' +] + { #category : #importer } GLHModelImporter >> loadAllProjectsFromRepositorySoftware [ "heavy import that load all the active project inside the model. Only import the project entities"