diff --git a/src/GitHubHealth-Model-Importer/GHApi.class.st b/src/GitHubHealth-Model-Importer/GHApi.class.st index 77fb4b2..10040e8 100644 --- a/src/GitHubHealth-Model-Importer/GHApi.class.st +++ b/src/GitHubHealth-Model-Importer/GHApi.class.st @@ -8,7 +8,7 @@ Class { 'baseAPIUrl', 'client' ], - #category : 'GitHubHealth-Model-Importer' + #category : #'GitHubHealth-Model-Importer' } { #category : #api } @@ -101,6 +101,13 @@ GHApi >> organization: anOrganizationName [ ^ self client get: self baseAPIUrl , '/orgs/' , anOrganizationName ] +{ #category : #api } +GHApi >> organization: aGroupName repo: aRepoName [ + + ^ self client get: + self baseAPIUrl , '/repos/' , aGroupName , '/' , aRepoName +] + { #category : #accessing } GHApi >> privateToken [ diff --git a/src/GitHubHealth-Model-Importer/GHModelImporter.class.st b/src/GitHubHealth-Model-Importer/GHModelImporter.class.st index c92fc30..fd483ad 100644 --- a/src/GitHubHealth-Model-Importer/GHModelImporter.class.st +++ b/src/GitHubHealth-Model-Importer/GHModelImporter.class.st @@ -4,7 +4,7 @@ Class { #instVars : [ 'api' ], - #category : 'GitHubHealth-Model-Importer' + #category : #'GitHubHealth-Model-Importer' } { #category : #accessing } @@ -42,6 +42,15 @@ GHModelImporter >> convertApiFileAsFile: aAPIFile [ yourself ] +{ #category : #api } +GHModelImporter >> ensureGroupNamed: aGroupName [ + + ^ self glhModel + detect: [ :a | + (a isKindOf: GLHGroup) and: [ a name = aGroupName ] ] + ifNone: [ self glhModel newGroupNamed: aGroupName ] +] + { #category : #api } GHModelImporter >> importBranchesOf: project [ @@ -173,6 +182,19 @@ GHModelImporter >> importPipelinesOf: project [ project addPipeline: pipeline ] ] +{ #category : #api } +GHModelImporter >> importProject: aProjectName ofGroup: aGroupName [ + + | result projectResult group | + group := self ensureGroupNamed: aGroupName. + result := self api organization: aGroupName repo: aProjectName. + projectResult := self parseProjectResult: result. + projectResult group: group. + self glhModel add: projectResult. + self completeImportProject: projectResult. + ^ projectResult +] + { #category : #api } GHModelImporter >> importRepositoriesOfGroup: groupResult [ @@ -230,7 +252,7 @@ GHModelImporter >> initialize [ withFiles := false ] -{ #category : #private } +{ #category : #parsing } GHModelImporter >> parseArrayOfProject: arrayOfProjects [ | reader | @@ -249,7 +271,7 @@ GHModelImporter >> parseArrayOfProject: arrayOfProjects [ ^ reader nextAs: #ArrayOfProjects ] -{ #category : #private } +{ #category : #parsing } GHModelImporter >> parseBranchesResult: arrayOfBranch [ | reader | @@ -318,7 +340,7 @@ GHModelImporter >> parseCommitsResult: result [ ^ reader nextAs: #ArrayOfCommit ] -{ #category : #private } +{ #category : #parsing } GHModelImporter >> parseFileTreeResult: aResult [ | reader | @@ -331,7 +353,7 @@ GHModelImporter >> parseFileTreeResult: aResult [ ^ reader nextAs: #ArrayOfFile ] -{ #category : #private } +{ #category : #parsing } GHModelImporter >> parseGroupResult: aResult [ | reader | @@ -344,7 +366,7 @@ GHModelImporter >> parseGroupResult: aResult [ ^ reader nextAs: GLHGroup ] -{ #category : #private } +{ #category : #parsing } GHModelImporter >> parsePipelinesResult: pipelineOverview [ | reader | @@ -366,6 +388,21 @@ GHModelImporter >> parsePipelinesResult: pipelineOverview [ ^ reader nextAs: GHAPIPipelineOverview ] +{ #category : #parsing } +GHModelImporter >> parseProjectResult: aResult [ + + | reader | + reader := NeoJSONReader on: aResult readStream. + reader for: GLHProject do: [ :mapping | + mapping mapInstVar: #name to: #name. + mapping mapInstVar: #description to: #description. + mapping mapInstVar: #id to: #id. + mapping mapInstVar: #archived to: #archived. + mapping mapInstVar: #web_url to: #html_url. + mapping mapInstVar: #topics to: #topics ]. + ^ reader nextAs: GLHProject +] + { #category : #parsing } GHModelImporter >> parseUserResult: result [