diff --git a/src/BitBucketHealth-Model-Importer-Tests/BitBucketApiMock.class.st b/src/BitBucketHealth-Model-Importer-Tests/BitBucketApiMock.class.st index 687146b..006bd3a 100644 --- a/src/BitBucketHealth-Model-Importer-Tests/BitBucketApiMock.class.st +++ b/src/BitBucketHealth-Model-Importer-Tests/BitBucketApiMock.class.st @@ -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 ] @@ -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 | @@ -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 ] @@ -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 := '[ diff --git a/src/BitBucketHealth-Model-Importer/BitBucketApi.class.st b/src/BitBucketHealth-Model-Importer/BitBucketApi.class.st index b6a9726..bde9b12 100644 --- a/src/BitBucketHealth-Model-Importer/BitBucketApi.class.st +++ b/src/BitBucketHealth-Model-Importer/BitBucketApi.class.st @@ -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/' @@ -91,13 +91,13 @@ 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 | @@ -105,7 +105,7 @@ BitBucketApi >> commitsOfRepo: repositorySlug inProject: projectKey since: since 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. @@ -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. @@ -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. @@ -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'. ] diff --git a/src/BitBucketHealth-Model-Importer/BitBucketModelImporter.class.st b/src/BitBucketHealth-Model-Importer/BitBucketModelImporter.class.st index 82e4013..5d3c5d7 100644 --- a/src/BitBucketHealth-Model-Importer/BitBucketModelImporter.class.st +++ b/src/BitBucketHealth-Model-Importer/BitBucketModelImporter.class.st @@ -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' } @@ -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. @@ -163,8 +179,8 @@ 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). @@ -172,10 +188,9 @@ BitBucketModelImporter >> importCommitsOfProject: aGLHProject since: since until 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' } @@ -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) ]. @@ -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. @@ -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 ]. @@ -297,8 +312,8 @@ 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. @@ -306,7 +321,7 @@ BitBucketModelImporter >> importMergeRequests: aGLHProject since: fromDate until self parsePullRequestIntoGLPHEMergeRequest: pullRequest ]. - self glhModel addAll: pullRequests unless: self blockOnIdEquality. + pullRequests := self glhModel addAll: pullRequests unless: self blockOnIdEquality. ^ pullRequests ] @@ -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' ]. diff --git a/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st b/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st index 53f48d6..bf9174f 100644 --- a/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st +++ b/src/GitLabHealth-Model-Importer/GLHModelImporter.class.st @@ -580,7 +580,7 @@ GLHModelImporter >> importDiffOfCommit: aCommit [ 'Diff already importer: ' , aCommit short_id printString recordInfo. ^ aCommit diffs ]. ('Import diff of commit: ' , aCommit short_id printString) recordInfo. - result := self glhApi + result := self repoApi commitDiff: aCommit id ofProject: aCommit repository project id unidiff: true. @@ -671,14 +671,14 @@ GLHModelImporter >> importLastestCommitsOfProject: aGLHProject [ "limited to the last 50 commits" | results parsedResults | - results := self glhApi + results := self repoApi commitsOfProject: aGLHProject id forRefName: nil since: nil until: nil path: nil author: nil - all: nil + all: true with_stats: true firstParent: nil order: nil @@ -686,9 +686,13 @@ GLHModelImporter >> importLastestCommitsOfProject: aGLHProject [ perPage: 50 page: nil. parsedResults := self parseCommitsResult: results. - parsedResults := self glhModel addAll: parsedResults unless: self blockOnIdEquality. + parsedResults := self glhModel + addAll: parsedResults + unless: self blockOnIdEquality. - aGLHProject repository commits addAll: parsedResults unless: self blockOnIdEquality. + aGLHProject repository commits + addAll: parsedResults + unless: self blockOnIdEquality. "parsedResults do: [ :commit | commit repository: aGLHProject repository ]." @@ -791,7 +795,7 @@ GLHModelImporter >> importRepository: aGLHRepository [ ('import the repository of project ' , aGLHRepository project name) recordInfo. - resultBranches := self glhApi branchesOfRepository: + resultBranches := self repoApi branchesOfRepository: aGLHRepository project id. branches := self parseBranchesResult: resultBranches. @@ -1185,7 +1189,7 @@ GLHModelImporter >> pipelinesOf: aProjectID [ | result | ('Search pipelines of: ' , aProjectID printString) recordInfo. - result := self glhApi pipelinesOfProject: aProjectID. + result := self repoApi pipelinesOfProject: aProjectID. ^ self parsePipelinesResult: result . ] diff --git a/src/GitLabHealth-Model-Visualization/GLHCommitDistributionVisualization.class.st b/src/GitLabHealth-Model-Visualization/GLHCommitDistributionVisualization.class.st index f3b72a6..61ca65e 100644 --- a/src/GitLabHealth-Model-Visualization/GLHCommitDistributionVisualization.class.st +++ b/src/GitLabHealth-Model-Visualization/GLHCommitDistributionVisualization.class.st @@ -4,7 +4,7 @@ Class { #instVars : [ 'groupCommitBlock' ], - #category : 'GitLabHealth-Model-Visualization' + #category : #'GitLabHealth-Model-Visualization' } { #category : #'instance creation' } @@ -12,6 +12,7 @@ GLHCommitDistributionVisualization >> forCommits: commits [ | c lb oldestCommit horizontal commitGroups groupToCommitByDate alreadyAdded dates | c := RSCompositeChart new. + commits ifEmpty: [ ^ c canvas]. oldestCommit := commits last. dates := (oldestCommit committed_date to: Date today) dates. diff --git a/src/GitLabHealth-Model-Visualization/GLHProjectContributorVisualization.class.st b/src/GitLabHealth-Model-Visualization/GLHProjectContributorVisualization.class.st index 0f8e933..45cdfd6 100644 --- a/src/GitLabHealth-Model-Visualization/GLHProjectContributorVisualization.class.st +++ b/src/GitLabHealth-Model-Visualization/GLHProjectContributorVisualization.class.st @@ -107,7 +107,7 @@ GLHProjectContributorVisualization >> forProject: aGLHProject [ | c shapes legend | c := RSCanvas new. - shapes := ((aGLHProject toScope: GLHCommit) collect: #commitCreator) asSet collect: [:author | self createShapeForUser: author ]. + shapes := ((aGLHProject toScope: GLHCommit) collect: #commitCreator) asSet reject: #isNil thenCollect: [:author | self createShapeForUser: author ]. " shapes add: (self createShapeForProject: aGLHProject )." c addAll: shapes. diff --git a/src/GitLabProjectHealth-Model-Importer/GLPHModelImporter.class.st b/src/GitLabProjectHealth-Model-Importer/GLPHModelImporter.class.st index e076b47..2668ae8 100644 --- a/src/GitLabProjectHealth-Model-Importer/GLPHModelImporter.class.st +++ b/src/GitLabProjectHealth-Model-Importer/GLPHModelImporter.class.st @@ -367,7 +367,7 @@ GLPHModelImporter >> importProject: aProjectID [ | result projectResult | ('Import project with id: ' , aProjectID printString) recordInfo. - result := self glhApi project: aProjectID. + result := self repoApi project: aProjectID. projectResult := self parseProjectResult: result. ^ self completeImportProject: projectResult