Skip to content

Commit

Permalink
Merge pull request #79 from moosetechnology/feature/error-with-bigdif…
Browse files Browse the repository at this point in the history
…f-from-server

Deal with errors when loading big diff
  • Loading branch information
badetitou authored Oct 7, 2024
2 parents 56314d3 + 22e5196 commit 1b1a264
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/GitLabHealth-Model-Importer-Tests/GLHApiMock.class.st
Original file line number Diff line number Diff line change
@@ -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"}' ]
]
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Class {
'importer',
'model'
],
#category : 'GitLabHealth-Model-Importer-Tests'
#category : #'GitLabHealth-Model-Importer-Tests'
}

{ #category : #running }
Expand All @@ -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 }
Expand All @@ -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"}')
]
6 changes: 6 additions & 0 deletions src/GitLabHealth-Model-Importer/GLHModelImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 1b1a264

Please sign in to comment.