Skip to content

Commit

Permalink
+ can import commits since a date
Browse files Browse the repository at this point in the history
+ add tests to ensure we get the date of each commit
  • Loading branch information
badetitou committed Sep 15, 2024
1 parent a754018 commit 658f0e8
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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 @@ -182,8 +183,12 @@ GHModelImporterTest >> testParseCommitsResult [
]'.

self assert: commits size equals: 2.
self assert: commits first message equals: 'Update test-and-release.yml'.
self
assert: commits first message
equals: 'Update test-and-release.yml'.
self assert: commits second message equals: 'Update release.yml'.
self assert: commits first authored_date isNotNil.
self assert: commits first committed_date isNotNil
]

{ #category : 'tests' }
Expand Down
22 changes: 19 additions & 3 deletions src/GitHubHealth-Model-Importer/GHApi.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,25 @@ GHApi >> client: anObject [
{ #category : 'api - commits' }
GHApi >> commitsOfProject: aProjectId ofOrganization: organisationName [

^ self client get:
self baseAPIUrl , '/repos/' , organisationName , '/' , aProjectId
, '/commits'
^ self
commitsOfProject: aProjectId
ofOrganization: organisationName
since: nil
perPage: nil
page: nil
]

{ #category : 'api - commits' }
GHApi >> commitsOfProject: aProjectId ofOrganization: organisationName since: aSinceDate perPage: itemPerPage page: pageNumber [

self client url:
self baseAPIUrl , '/repos/' , organisationName , '/' , aProjectId
, '/commits'.
aSinceDate ifNotNil: [ self client queryAt: #since put: aSinceDate ].
itemPerPage ifNotNil: [
self client queryAt: #per_page put: itemPerPage ].
pageNumber ifNotNil: [ self client queryAt: #page put: pageNumber ].
^ self client get
]

{ #category : 'api' }
Expand Down
42 changes: 34 additions & 8 deletions src/GitHubHealth-Model-Importer/GHModelImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,40 @@ GHModelImporter >> importBranchesOf: project [
{ #category : 'api' }
GHModelImporter >> importCommitsOfProject: aGLHProject [

| commitsResult commits |
commitsResult := self api
commitsOfProject: aGLHProject name
ofOrganization: aGLHProject group name.
commits := self parseCommitsResult: commitsResult.
| itemByPage foundCommits tmp pageNumber |
itemByPage := 100.
pageNumber := 1.
('Extract all commits of ' , aGLHProject name) recordInfo.
foundCommits := OrderedCollection new.
('Extract commits from ' , foundCommits size printString , ' to '
, (foundCommits size + itemByPage) printString) recordInfo.
tmp := self parseCommitsResult: (self api
commitsOfProject: aGLHProject name
ofOrganization: aGLHProject group name
since: self withCommitsSince
perPage: itemByPage
page: pageNumber).

foundCommits addAll: tmp.
[ tmp size = itemByPage ] whileTrue: [
pageNumber := pageNumber + 1.
('Extract issues from ' , foundCommits size printString , ' to '
, (foundCommits size + itemByPage) printString) recordInfo.
tmp := self parseCommitsResult: (self api
commitsOfProject: aGLHProject name
ofOrganization: aGLHProject group name
since: self withCommitsSince
perPage: itemByPage
page: pageNumber).
foundCommits addAll: tmp ].

"add the imported commits (unless they are already added to this repository)"
aGLHProject repository commits
addAll: commits
addAll: foundCommits
unless: [ :existing :new | existing id = new id ].
"add the imported commits to the model unles they are already added to the model"
^ self glhModel
addAll: commits
addAll: foundCommits
unless: [ :existing :new | existing id = new id ]
]

Expand Down Expand Up @@ -228,7 +250,11 @@ GHModelImporter >> parseCommitsResult: result [
mapProperty: #commit
getter: [ :object | #ignore ]
setter: [ :glhCommit :value |
glhCommit message: (value at: #message) ].
glhCommit message: (value at: #message).
glhCommit authored_date:
(DateAndTime fromString: (value at: #author at: #date)).
glhCommit committed_date:
(DateAndTime fromString: (value at: #committer at: #date)) ].

mapping
mapProperty: #author
Expand Down

0 comments on commit 658f0e8

Please sign in to comment.