Skip to content

Commit

Permalink
add an import for the merge_user
Browse files Browse the repository at this point in the history
  • Loading branch information
badetitou committed Jul 2, 2024
1 parent 25e91c6 commit 593425f
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Class {
GLPHApiMock >> mergeRequestOfProject: project withId: id [

^ '{
"author":{ "id": 12 }
"author":{ "id": 12 },
"merge_user":{ "id": 12 }
}'
]
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ GLPHModelImporterMergeRequestTest >> setUp [
"created_at":"2024-07-01T16:05:48.775+02:00",
"updated_at":"2024-07-01T16:05:51.221+02:00",
"merged_by":null,
"merge_user":null,
"merge_user":{
"id":12,
"username":"badetitou",
"name":"Verhaeghe Benoit",
"state":"active",
"avatar_url":"https://gitlab.com/badetitou.png",
"web_url":"https://gitlab.com/badetitou"
},
"merged_at":null,
"closed_by":null,
"closed_at":null,
Expand Down Expand Up @@ -105,6 +112,49 @@ GLPHModelImporterMergeRequestTest >> setUp [
}]'
]

{ #category : #test }
GLPHModelImporterMergeRequestTest >> testParseMergeRequestMergeUserAlreadySet [

| mergeRequest user |
mergeRequest := (glhImporter parseMergeRequestResult: gitlabMergeData) anyOne.
user := GLHUser new.
mergeRequest merge_user: user.
glhImporter importMergeResquestMerger: mergeRequest.
self assert: mergeRequest merge_user equals: user
]

{ #category : #test }
GLPHModelImporterMergeRequestTest >> testParseMergeRequestMergeUserExistInModelAndCacheID [

| mergeRequest user |
mergeRequest := (glhImporter parseMergeRequestResult: gitlabMergeData)
anyOne.
user := glhModel newUser.
user id: 12.
glhImporter importMergeResquestMerger: mergeRequest.
self assert: mergeRequest merge_user equals: user
]

{ #category : #test }
GLPHModelImporterMergeRequestTest >> testParseMergeRequestMergeUserIsNil [

| mergeRequest |
mergeRequest := (glhImporter parseMergeRequestResult: '[{"id":46074}]') anyOne.
self assert: mergeRequest merge_user equals: nil
]

{ #category : #test }
GLPHModelImporterMergeRequestTest >> testParseMergeRequestMergeUserWithoutCache [

| mergeRequest user |
mergeRequest := (glhImporter parseMergeRequestResult: gitlabMergeData) anyOne.
mergeRequest flush.
user := glhModel newUser.
user id: 12.
glhImporter importMergeResquestMerger: mergeRequest.
self assert: mergeRequest merge_user equals: user
]

{ #category : #test }
GLPHModelImporterMergeRequestTest >> testParseMergeRequestResult [

Expand Down
36 changes: 29 additions & 7 deletions src/GitLabProjectHealth-Model-Importer/GLPHModelImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,20 @@ GLPHModelImporter >> configureReaderForMergeRequest: reader [
(mapping mapInstVar: #merged_at) valueSchema: DateAndTime.
(mapping mapInstVar: #closed_at) valueSchema: DateAndTime.
"(mapping mapInstVar: #assignee) valueSchema: GLHUser."
(mapping
mapProperty: #author
getter: [ ]
setter: [ :object :value | object cacheAt: #authorID put: (value at: #id) ]).
"(mapping mapInstVar: #closed_by) valueSchema: GLHUser.
(mapping mapInstVar: #mergeCommit) valueSchema: GLHCommit." ].

mapping
mapProperty: #author
getter: [ ]
setter: [ :object :value |
object cacheAt: #authorID put: (value at: #id) ].
mapping
mapProperty: #merge_user
getter: [ ]
setter: [ :object :value |
value ifNotNil: [
object cacheAt: #mergeUserID put: (value at: #id) ] ] ].

"(mapping mapInstVar: #closed_by) valueSchema: GLHUser.
(mapping mapInstVar: #mergeCommit) valueSchema: GLHCommit."
"indique ce que doit faire le reader lorsqu'il parse une DateAndTime object"
reader for: DateAndTime customDo: [ :mapping |
mapping decoder: [ :string |
Expand Down Expand Up @@ -354,6 +361,21 @@ GLPHModelImporter >> importMergeResquestAuthor: aGLPHEMergeRequest [
aGLPHEMergeRequest author: (self importUser: authorID)
]

{ #category : #'import - merge request' }
GLPHModelImporter >> importMergeResquestMerger: aGLPHEMergeRequest [

| authorID |
aGLPHEMergeRequest merge_user ifNotNil: [ ^ aGLPHEMergeRequest merge_user ].
authorID := aGLPHEMergeRequest cacheAt: #mergeUserID ifAbsent: [
(generalReader
on: (self glhApi
mergeRequestOfProject:
aGLPHEMergeRequest project_id
withId: aGLPHEMergeRequest iid) readStream;
next) at: #merge_user at: #id ].
aGLPHEMergeRequest merge_user: (self importUser: authorID)
]

{ #category : #'as yet unclassified' }
GLPHModelImporter >> importProject: aProjectID [

Expand Down

0 comments on commit 593425f

Please sign in to comment.