Skip to content

Commit

Permalink
add API to parse all groups of a gitlab instances
Browse files Browse the repository at this point in the history
  • Loading branch information
badetitou committed Jun 27, 2024
1 parent dfd76b7 commit 92d7126
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
11 changes: 11 additions & 0 deletions src/GitLabHealth-Model-Importer/GLHApi.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,17 @@ GLHApi >> jobsOfProject: aProjectID ofPipelines: aPipelineID [
, '/pipelines/' , aPipelineID printString , '/jobs'
]

{ #category : #'api - groups' }
GLHApi >> listGroupsWithTopLevelOnly: topLevelOnly page: aPageNumber [
"https://docs.gitlab.com/ee/api/groups.html#list-groups"

self client url: self baseAPIUrl , '/groups'.
topLevelOnly ifNotNil: [
self client queryAt: #top_level_only put: topLevelOnly ].
aPageNumber ifNotNil: [ self client queryAt: #page put: aPageNumber ].
^ self client get
]

{ #category : #api }
GLHApi >> pipelinesOfProject: aProjectID [
^ self client get: self baseAPIUrl , '/projects/' , aProjectID printString, '/pipelines'
Expand Down
54 changes: 47 additions & 7 deletions src/GitLabHealth-Model-Importer/GLHModelImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Class {
'withCommitDiffs',
'withCommitsSince',
'withInitialCommits',
'withInitialMergeRequest'
'withInitialMergeRequest',
'generalReader'
],
#category : #'GitLabHealth-Model-Importer'
}
Expand Down Expand Up @@ -158,6 +159,23 @@ GLHModelImporter >> configureReaderForCommit: reader [

]

{ #category : #private }
GLHModelImporter >> configureReaderForGroup: reader [

reader for: GLHGroup do: [ :mapping |
mapping mapInstVars.
(mapping mapInstVar: #projects) valueSchema: #ArrayOfProjects ].
reader mapInstVarsFor: GLHProject.
reader
for: #ArrayOfProjects
customDo: [ :customMappting |
customMappting listOfElementSchema: GLHProject ].
reader
for: #ArrayOfGroups
customDo: [ :customMappting |
customMappting listOfElementSchema: GLHGroup ]
]

{ #category : #private }
GLHModelImporter >> convertApiFileAsFile: aAPIFile [

Expand Down Expand Up @@ -215,6 +233,23 @@ GLHModelImporter >> glhModel: anObject [
glhModel := anObject
]

{ #category : #api }
GLHModelImporter >> importAllGroups [

| page foundGroups newlyFoundGroups |
page := 0.
foundGroups := OrderedCollection new.
newlyFoundGroups := { true }.
[ newlyFoundGroups isNotEmpty ] whileTrue: [
| results |
page := page + 1.
results := self glhApi listGroupsWithTopLevelOnly: true page: page.
newlyFoundGroups := generalReader
on: results readStream;
nextAs: #ArrayOfGroups.
foundGroups addAll: newlyFoundGroups ]
]

{ #category : #'private - api' }
GLHModelImporter >> importCommit: aCommitID ofProject: aGLHProject [

Expand Down Expand Up @@ -677,14 +712,23 @@ GLHModelImporter >> importUserByUsername: anUsername [
] ] ]
]

{ #category : #initialization }
GLHModelImporter >> initReader [

generalReader := NeoJSONReader new.
self configureReaderForCommit: generalReader.
self configureReaderForGroup: generalReader
]

{ #category : #initialization }
GLHModelImporter >> initialize [

withFiles := false.
withCommitDiffs := false.
withInitialCommits := false.
withInitialMergeRequest := false.
withCommitsSince := (Date today - 1 week) asDateAndTime
withCommitsSince := (Date today - 1 week) asDateAndTime.
self initReader
]

{ #category : #private }
Expand Down Expand Up @@ -874,11 +918,7 @@ GLHModelImporter >> parseSubGroupResult: aResult [

| reader |
reader := NeoJSONReader on: aResult readStream.
reader mapInstVarsFor: GLHGroup.
reader
for: #ArrayOfGroups
customDo: [ :customMappting |
customMappting listOfElementSchema: GLHGroup ].
self configureReaderForGroup: reader.
^ reader nextAs: #ArrayOfGroups
]

Expand Down

0 comments on commit 92d7126

Please sign in to comment.