Skip to content

Commit

Permalink
add simple import of users
Browse files Browse the repository at this point in the history
  • Loading branch information
badetitou committed Sep 15, 2024
1 parent 25735e8 commit 05af8d4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ GHModelImporterTest >> setUp [

{ #category : 'tests' }
GHModelImporterTest >> testParseCommitsResult [

"we remove the id of author entries to not trigger the call to import user"
| commits |
commits := importer parseCommitsResult: '[
{
Expand Down Expand Up @@ -56,7 +56,6 @@ GHModelImporterTest >> testParseCommitsResult [
"comments_url": "https://api.github.com/repos/moosetechnology/Moose/commits/f5ac58f4afe4632b0a26d1e968439c78962da289/comments",
"author": {
"login": "ClotildeToullec",
"id": 39184695,
"node_id": "MDQ6VXNlcjM5MTg0Njk1",
"avatar_url": "https://avatars.githubusercontent.com/u/39184695?v=4",
"gravatar_id": "",
Expand Down Expand Up @@ -135,7 +134,6 @@ GHModelImporterTest >> testParseCommitsResult [
"comments_url": "https://api.github.com/repos/moosetechnology/Moose/commits/eb31d04f01254d0caf7c7a5b03546e3f6a5c3d58/comments",
"author": {
"login": "ClotildeToullec",
"id": 39184695,
"node_id": "MDQ6VXNlcjM5MTg0Njk1",
"avatar_url": "https://avatars.githubusercontent.com/u/39184695?v=4",
"gravatar_id": "",
Expand Down
6 changes: 6 additions & 0 deletions src/GitHubHealth-Model-Importer/GHApi.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,9 @@ GHApi >> reposOfOrganization: anOrganizationName [

^ self client get: self baseAPIUrl , '/orgs/' , anOrganizationName, '/repos'
]

{ #category : 'api - users' }
GHApi >> user: aUserID [

^ self client get: self baseAPIUrl , '/user/' , aUserID asString
]
53 changes: 52 additions & 1 deletion src/GitHubHealth-Model-Importer/GHModelImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,21 @@ GHModelImporter >> importRepositoriesOfGroup: groupResult [
^ groupResult
]

{ #category : 'api' }
GHModelImporter >> importUser: userID [

| result userResult |
(glhModel allWithType: GLHUser)
detect: [ :user | user id = userID ]
ifFound: [ :user | ^ user ].
('Import user: ' , userID printString) recordInfo.
result := self api user: userID.
userResult := self parseUserResult: result.
^ glhModel
add: userResult
unless: [ :current :new | current id = new id ]
]

{ #category : 'initialization' }
GHModelImporter >> initialize [

Expand Down Expand Up @@ -225,7 +240,25 @@ GHModelImporter >> parseCommitsResult: result [
getter: [ :object | #ignore ]
setter: [ :glhCommit :value |
glhCommit message: (value at: #message) ].
(mapping mapInstVar: #parent_ids) valueSchema: #ArrayOfIds ].

mapping
mapProperty: #author
getter: [ :object | #ignore ]
setter: [ :glhCommit :value |
glhCommit author_name: (value at: #login).
value
at: #id
ifPresent: [ :authorId |
glhCommit commitCreator: (self importUser: authorId) ] ].

mapping
mapProperty: #committer
getter: [ :object | #ignore ]
setter: [ :glhCommit :value |
glhCommit committer_name: (value at: #login) ].

(mapping mapInstVar: #parent_ids to: #parents) valueSchema:
#ArrayOfIds ].

reader for: DateAndTime customDo: [ :mapping |
mapping decoder: [ :string | DateAndTime fromString: string ] ].
Expand Down Expand Up @@ -290,6 +323,24 @@ GHModelImporter >> parsePipelinesResult: pipelineOverview [
^ reader nextAs: GHAPIPipelineOverview
]

{ #category : 'parsing' }
GHModelImporter >> parseUserResult: result [

| reader |
reader := NeoJSONReader on: result readStream.
reader for: GLHUser do: [ :mapping |
mapping mapInstVar: #id to: #id.
mapping mapInstVar: #public_email to: #email.
mapping mapInstVar: #username to: #login.
mapping mapInstVar: #bio to: #bio.
mapping mapInstVar: #organization to: #company.
mapping mapInstVar: #followers to: #followers.
mapping mapInstVar: #following to: #following.
mapping mapInstVar: #web_url to: #html_url.
mapping mapInstVar: #avatar_url to: #avatar_url ].
^ reader nextAs: GLHUser
]

{ #category : 'api' }
GHModelImporter >> privateToken [
^ self api privateToken
Expand Down

0 comments on commit 05af8d4

Please sign in to comment.