Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring/rename #81

Merged
merged 5 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Class {
}

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

^self pullRequestActivities
]
Expand Down Expand Up @@ -61,13 +61,13 @@ 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 |
Expand Down Expand Up @@ -382,7 +382,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 +1078,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
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
141 changes: 78 additions & 63 deletions src/BitBucketHealth-Model-Importer/BitBucketModelImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -57,50 +57,66 @@ BitBucketModelImporter >> completeImportedCommit: aCommit [
]

{ #category : #convert }
BitBucketModelImporter >> convertBitBucketDiffToGitDiff: response [
| bitbucketDiff gitDiff filePath fromHash toHash sourceLine sourceSpan destinationLine destinationSpan result|

fromHash := (response at: 'fromHash') ifNil: '' .
toHash := (response at: 'toHash') ifNil: ''.

gitDiff := ''.
"Iterate over each diff in 'diffs'"
result := (response at: #diffs) collect: [:diff |

"Extract file path, hashes"
filePath := (diff at: 'source') at: 'toString'.

"Build the diff header"
" gitDiff := gitDiff , 'diff --git a/', filePath, ' b/', filePath, String cr."
" gitDiff := gitDiff , 'index ', fromHash, '..', toHash, ' 100644', String cr."
gitDiff := gitDiff , '--- a/', filePath, String cr.
gitDiff := gitDiff , '+++ b/', filePath, String cr.

"Iterate over hunks"
(diff at: 'hunks') do: [:hunk |
sourceLine := hunk at: 'sourceLine'.
sourceSpan := hunk at: 'sourceSpan'.
destinationLine := hunk at: 'destinationLine'.
destinationSpan := hunk at: 'destinationSpan'.

"Hunk header"
gitDiff := gitDiff , ('@@ -{1},{2} +{3},{4} @@' format: { sourceLine. sourceSpan. destinationLine. destinationSpan }), String cr.

"Iterate over segments"
(hunk at: 'segments') do: [:segment |
(segment at: 'lines') do: [:line |
(segment at: 'type') = 'REMOVED'
ifTrue: [ gitDiff := gitDiff , '-', (line at: 'line'), String cr ].
(segment at: 'type') = 'ADDED'
ifTrue: [ gitDiff := gitDiff , '+', (line at: 'line'), String cr ].
].
].
].
GLHDiff new diffString: gitDiff; new_path: filePath; old_path: 'filePath'.
].

^ result
BitBucketModelImporter >> convertBitBucketDiffToGitDiff: response [

| bitbucketDiff filePath fromHash toHash sourceLine sourceSpan destinationLine destinationSpan result filePathSource filePathDestination |
fromHash := (response at: 'fromHash') ifNil: ''.
toHash := (response at: 'toHash') ifNil: ''.


"Iterate over each diff in 'diffs'"
result := (response at: #diffs) collect: [ :diff | "Extract file path, hashes"
|gitDiff|
gitDiff := ''.
filePathSource := (diff at: 'source')
ifNil: ''
ifNotNil: [ :source |
source at: 'toString' ].
filePathDestination := (diff at: 'destination')
ifNil: ''
ifNotNil: [ :destination |
destination at: 'toString' ].

"Build the diff header"
" gitDiff := gitDiff , 'diff --git a/', filePath, ' b/', filePath, String cr."
" gitDiff := gitDiff , 'index ', fromHash, '..', toHash, ' 100644', String cr."
gitDiff := gitDiff , '--- a/' , filePathSource , String cr.
gitDiff := gitDiff , '+++ b/' , filePathDestination
, String cr.

"Iterate over hunks"
(diff at: 'hunks') do: [ :hunk |
sourceLine := hunk at: 'sourceLine'.
sourceSpan := hunk at: 'sourceSpan'.
destinationLine := hunk at: 'destinationLine'.
destinationSpan := hunk at: 'destinationSpan'.

"Hunk header"
gitDiff := gitDiff
, ('@@ -{1},{2} +{3},{4} @@' format: {
sourceLine.
sourceSpan.
destinationLine.
destinationSpan }) , String cr.

"Iterate over segments"
(hunk at: 'segments') do: [ :segment |
(segment at: 'lines') do: [ :line |
(segment at: 'type') = 'CONTEXT' ifTrue: [
gitDiff := gitDiff , (line at: 'line')
, String cr ].
(segment at: 'type') = 'REMOVED' ifTrue: [
gitDiff := gitDiff , '-' , (line at: 'line')
, String cr ].
(segment at: 'type') = 'ADDED' ifTrue: [
gitDiff := gitDiff , '+' , (line at: 'line')
, String cr ] ] ] ].
GLHDiff new
diffString: gitDiff;
old_path: filePathSource;
new_path: filePathDestination ].

^ result
]

{ #category : #'private - api' }
Expand Down Expand Up @@ -153,8 +169,8 @@ BitBucketModelImporter >> importCommitsOfProject: aGLHProject since: since until

| commits |
commits := self repoApi
commitsOfRepo: aGLHProject id
inProject: aGLHProject group id
commitsOfRepoProjectId: aGLHProject id
inProjectGroupId: aGLHProject group id
since: since
until: until.

Expand All @@ -163,19 +179,18 @@ BitBucketModelImporter >> importCommitsOfProject: aGLHProject since: since until
glhCommit := self parseCommitIntoGLHCommit: commit.
commitDiffs := self repoApi
diffsOfCommit: glhCommit id
inRepo: aGLHProject id
inProject: aGLHProject group id.
inRepoProjectId: aGLHProject id
inProjectGroupId: aGLHProject group id.

contribution := self getContributionFromDiffs:
(commitDiffs at: #diffs).
glhCommit additions: (contribution at: #additions).
glhCommit deletions: (contribution at: #deletions).
glhCommit ].

aGLHProject repository commits: commits.
self glhModel addAll: commits unless: self blockOnIdEquality.

^ commits

commits := self glhModel addAll: commits unless: self blockOnIdEquality.
^ aGLHProject repository commits addAll: commits unless: self blockOnIdEquality.
]

{ #category : #'import - projects' }
Expand All @@ -187,15 +202,15 @@ BitBucketModelImporter >> importContributedProjectsOfUser: aGLHUser [

"get all repos of projects"
repositories := projects flatCollect: [ :project |
self repoApi repositoriesOfProject:
self repoApi repositoryProjectsOfProjectGroupId:
(project at: #key) ].


"get all commits of repo"
repositoriesCommits := repositories collect: [ :repository |
repository -> (self repoApi
commitsOfRepo: (repository at: #slug)
inProject:
commitsOfRepoProjectId: (repository at: #slug)
inProjectGroupId:
((repository at: #project) at: #key)
since: DateAndTime now - 10 days
until: DateAndTime now) ].
Expand Down Expand Up @@ -261,8 +276,8 @@ BitBucketModelImporter >> importDiffOfCommit: aCommit [
('Import diff of commit: ' , aCommit short_id printString) recordInfo.
result := self repoApi
diffsOfCommit: aCommit id
inRepo: aCommit repository project id
inProject: aCommit repository project group id.
inRepoProjectId: aCommit repository project id
inProjectGroupId: aCommit repository project group id.

diffsResult := self convertBitBucketDiffToGitDiff: result.

Expand All @@ -281,8 +296,8 @@ BitBucketModelImporter >> importMergeRequestCommits: mergeRequest [
| commits |
commits := self repoApi
commitsOfPullRequest: mergeRequest id
ofRepo: mergeRequest project id
inProject: mergeRequest project group id.
ofRepoProjectId: mergeRequest project id
inProjectGroupId: mergeRequest project group id.

commits := commits collect: [ :commit |
self parseCommitIntoGLHCommit: commit ].
Expand All @@ -297,16 +312,16 @@ BitBucketModelImporter >> importMergeRequests: aGLHProject since: fromDate until

| pullRequests |
pullRequests := self repoApi
pullRequestsOfRepo: aGLHProject id
inProject: aGLHProject group id
pullRequestsOfRepoProjectId: aGLHProject id
inProjectGroupId: aGLHProject group id
since: fromDate
until: toDate.

pullRequests := pullRequests collect: [ :pullRequest |
self parsePullRequestIntoGLPHEMergeRequest:
pullRequest ].

self glhModel addAll: pullRequests unless: self blockOnIdEquality.
pullRequests := self glhModel addAll: pullRequests unless: self blockOnIdEquality.

^ pullRequests
]
Expand All @@ -325,8 +340,8 @@ BitBucketModelImporter >> importMergeResquestMerger: mergeRequest [

activities := self repoApi
activitiesOfPullRequest: mergeRequest id
inRepo: mergeRequest project id
ofProject: mergeRequest project group id.
inRepoProjectId: mergeRequest project id
ofProjectGroupId: mergeRequest project group id.

mergeActivity := activities detect: [ :activity |
(activity at: #action) = 'MERGED' ].
Expand Down
Loading
Loading