Skip to content

Commit

Permalink
Merge pull request #96 from moosetechnology/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
badetitou authored Oct 24, 2024
2 parents 150421b + ed0b8fb commit 6870d80
Show file tree
Hide file tree
Showing 22 changed files with 1,108 additions and 308 deletions.
46 changes: 40 additions & 6 deletions src/BitBucketHealth-Model-Importer-Tests/BitBucketApiMock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,43 @@ Class {
}

{ #category : #'api - pull-requests' }
BitBucketApiMock >> activitiesOfPullRequest: pullRequestId inRepo: repoSlug ofProject: projectKey [
BitBucketApiMock >> activitiesOfPullRequest: pullRequestId inRepoProjectId: repoSlug ofProjectGroupId: projectKey [

^self pullRequestActivities
]

{ #category : #accessing }
BitBucketApiMock >> commit2 [

| commits2 |
commits2 := '
{
"id": "abcdef0123abcdef4567abcdef8987abcdef6543",
"message": "message test",
"displayId": "abcdef0123a",
"author": {
"name": "charlie",
"emailAddress": "charlie@example.com"
},
"authorTimestamp": 1727168151000,
"committer": {
"name": "charlie",
"emailAddress": "charlie@example.com"
},
"committerTimestamp": 1727168151000,
"message": "WIP on feature 1",
"parents": [
{
"id": "abcdef0123abcdef4567abcdef8987abcdef6543",
"displayId": "abcdef0"
}
]
}
'.

^ commits2 := (NeoJSONReader on: commits2 readStream) next
]

{ #category : #accessing }
BitBucketApiMock >> commits [

Expand Down Expand Up @@ -61,18 +93,20 @@ BitBucketApiMock >> commits: anObject [
]

{ #category : #'api - pull-requests' }
BitBucketApiMock >> commitsOfPullRequest: mergeRequestId ofRepo: repoSlug inProject: projectKey [
BitBucketApiMock >> commitsOfPullRequest: mergeRequestId ofRepoProjectId: repoSlug inProjectGroupId: projectKey [

^commits
]

{ #category : #'api - projects' }
BitBucketApiMock >> commitsOfRepo: repositorySlug inProject: projectKey since: since until: until [
BitBucketApiMock >> commitsOfRepoProjectId: repositorySlug inProjectGroupId: projectKey since: since until: until [

^ self commits select: [ :commit |
| commitDate |

commitDate := DateAndTime fromUnixTime:
(commit at: #committerTimestamp) / 1000.

commitDate >= since asDate and: commitDate <= until asDate ]
]

Expand Down Expand Up @@ -382,7 +416,7 @@ BitBucketApiMock >> diffs: anObject [
]

{ #category : #'api - commits' }
BitBucketApiMock >> diffsOfCommit: commitID inRepo: repositorySlug inProject: projectKey [
BitBucketApiMock >> diffsOfCommit: commitID inRepoProjectId: repositorySlug inProjectGroupId: projectKey [
^diffs
]

Expand Down Expand Up @@ -1078,13 +1112,13 @@ BitBucketApiMock >> pullRequestActivities [
]

{ #category : #'api - pull-requests' }
BitBucketApiMock >> pullRequestsOfRepo: repoSlug inProject: projectKey since: since until: until [
BitBucketApiMock >> pullRequestsOfRepoProjectId: repoSlug inProjectGroupId: projectKey since: since until: until [

^ mergeRequests
]

{ #category : #'api - projects' }
BitBucketApiMock >> repositoriesOfProject: projectKey [
BitBucketApiMock >> repositoryProjectsOfProjectGroupId: projectKey [

| repos |
repos := '[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,58 @@ BitBucketModelImporterTest >> testGetContributionFromDiffsWithoutRemoved [
self assert: (contribution at: #deletions) equals: 0
]

{ #category : #tests }
BitBucketModelImporterTest >> testImportAndLoadLatestsCommitsOfProject [

| bitBucketApi glphModel bitBucketImporter project commits group repo firstCommit commit1 currentDate timestamp commit2 timestamp2 |
"Given"
bitBucketApi := BitBucketApiMock new.

glphModel := GLPHEModel new name: 'test'.

bitBucketImporter := BitBucketModelImporter new
bitBucketApi: bitBucketApi;
glhModel: glphModel;
withCommitDiffs: true.

group := GLHGroup new id: 1.
repo := GLHRepository new.
project := GLHProject new
group: group;
repository: repo.

commit1 := bitBucketApi commits1 first.
currentDate := DateAndTime today.
timestamp := (currentDate - 1 weeks) asUnixTime * 1000.
commit1 at: 'committerTimestamp' put: timestamp.

commit2 := bitBucketApi commit2.
timestamp2 := (currentDate - 4 weeks) asUnixTime * 1000.
commit2 at: 'committerTimestamp' put: timestamp2.


bitBucketApi commits: {
commit1.
commit2 }.

"When"
commits := bitBucketImporter importAndLoadLatestsCommitsOfProject:
project.

"Then"
self
assert: (bitBucketImporter glhModel allWithType: GLHCommit) size
equals: 1.

self assert: project repository commits size equals: 1.
firstCommit := project repository commits first.
self assert: firstCommit additions equals: 1
]

{ #category : #tests }
BitBucketModelImporterTest >> testImportCommitsOfProjectSinceUntil [

| bitBucketApi glphModel bitBucketImporter project commits group repo |
| bitBucketApi glphModel bitBucketImporter project commits group repo firstCommit |
"Given"
bitBucketApi := BitBucketApiMock new.

Expand All @@ -160,8 +208,10 @@ BitBucketModelImporterTest >> testImportCommitsOfProjectSinceUntil [
self
assert: (bitBucketImporter glhModel allWithType: GLHCommit) size
equals: 1.

self assert: project repository commits size equals: 1.

self assert: project repository commits size equals: 1.
firstCommit := project repository commits first.
self assert: firstCommit additions equals: 1
]

{ #category : #tests }
Expand Down Expand Up @@ -282,7 +332,8 @@ BitBucketModelImporterTest >> testImportMergeRequestCommits [

"Then"
self deny: mergeRequest commits equals: nil.
self assert: mergeRequest commits equals: commits
self assert: mergeRequest commits equals: commits.
self assert: mergeRequest commits first additions equals: 1
]

{ #category : #tests }
Expand Down
14 changes: 7 additions & 7 deletions src/BitBucketHealth-Model-Importer/BitBucketApi.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Class {
}

{ #category : #'api - pull-requests' }
BitBucketApi >> activitiesOfPullRequest: pullRequestId inRepo: repositorySlug ofProject: projectKey [
BitBucketApi >> activitiesOfPullRequest: pullRequestId inRepoProjectId: repositorySlug ofProjectGroupId: projectKey [

^ self allValuesOfPath:
self basePath , '/projects/' , projectKey , '/repos/'
Expand Down Expand Up @@ -91,21 +91,21 @@ BitBucketApi >> client: anObject [
]

{ #category : #'api - pull-requests' }
BitBucketApi >> commitsOfPullRequest: pullRequestId ofRepo: repoSlug inProject: projectKey [
BitBucketApi >> commitsOfPullRequest: pullRequestId ofRepoProjectId: repoSlug inProjectGroupId: projectKey [
^ self allValuesOfPath: self basePath, '/projects/', projectKey, '/repos/', repoSlug, '/pull-requests/', pullRequestId printString, '/commits'.

]

{ #category : #'api - commits' }
BitBucketApi >> commitsOfRepo: repositorySlug inProject: projectKey since: since until: until [
BitBucketApi >> commitsOfRepoProjectId: repositorySlug inProjectGroupId: projectKey since: since until: until [
"/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/commits"

| results lastDate lastCommitterTimestamp commits |
self prepareZnClient.
self client path:
self basePath , '/projects/' , projectKey , '/repos/'
, repositorySlug , '/commits'.
self client queryAt: 'merges' put: 'exclude'.
"self client queryAt: 'merges' put: 'exclude'."

commits := OrderedCollection new.

Expand Down Expand Up @@ -134,7 +134,7 @@ BitBucketApi >> commitsOfRepo: repositorySlug inProject: projectKey since: since
]

{ #category : #'api - commits' }
BitBucketApi >> diffsOfCommit: commitID inRepo: repositorySlug inProject: projectKey [
BitBucketApi >> diffsOfCommit: commitID inRepoProjectId: repositorySlug inProjectGroupId: projectKey [

| results |
self prepareZnClient.
Expand Down Expand Up @@ -195,7 +195,7 @@ BitBucketApi >> projects [
]

{ #category : #'api - pull-requests' }
BitBucketApi >> pullRequestsOfRepo: repositorySlug inProject: projectKey since: since until: until [
BitBucketApi >> pullRequestsOfRepoProjectId: repositorySlug inProjectGroupId: projectKey since: since until: until [

| pullRequests results lastCommitterTimestamp lastDate |
self prepareZnClient.
Expand Down Expand Up @@ -231,7 +231,7 @@ BitBucketApi >> pullRequestsOfRepo: repositorySlug inProject: projectKey since:
]

{ #category : #'api - projects' }
BitBucketApi >> repositoriesOfProject: projectKey [
BitBucketApi >> repositoryProjectsOfProjectGroupId: projectKey [
^self allValuesOfPath: self basePath, '/projects/', projectKey, '/repos'.
]

Expand Down
Loading

0 comments on commit 6870d80

Please sign in to comment.