Skip to content
31 changes: 15 additions & 16 deletions src/BaselineOfGitLabHealth/BaselineOfGitLabHealth.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,16 @@ BaselineOfGitLabHealth >> defineJiraConnector: spec [

{ #category : #baselines }
BaselineOfGitLabHealth >> definePackages: spec [

"generic"

spec
package: 'GitProjectHealth-Model-Importer'
with: [ spec requires: #( 'GitlabAPI' ) ].
with: [ spec requires: #( 'GitLabHealth-Model' ) ].
spec
package: 'GitProjectHealth-Model-Importer-Tests'
with: [ spec requires: #( 'GitProjectHealth-Model-Importer' ) ].

"gitlab"
"model"
spec
package: 'GitLabHealth-Model';
package: 'GitLabHealth-Model-Extension'
Expand All @@ -148,34 +148,33 @@ BaselineOfGitLabHealth >> definePackages: spec [
package: 'GitLabHealth-Model-Generator';
package: 'GitLabHealth-Model-Inspector'
with: [ spec requires: #( 'GitLabHealth-Model-Visualization' ) ];
package: 'GitLabHealth-Model-Visualization';
package: 'GitLabHealth-Model-Visualization'.

"Gitlab importer"
spec
package: 'GitLabHealth-Model-Importer' with: [
spec requires:
#( 'NeoJSON' 'MoreLogger' 'GitProjectHealth-Model-Importer' ) ];
package: 'GitHubHealth-Model-Importer' with: [
spec requires:
#( 'NeoJSON' 'MoreLogger' 'GitProjectHealth-Model-Importer' ) ];
#( 'NeoJSON' 'MoreLogger' 'GitlabAPI' 'GitProjectHealth-Model-Importer' ) ];
package: 'GitLabHealth-Model-Importer-Tests' with: [
spec requires:
#( 'GitLabHealth-Model-Importer' 'GitHubHealth-Model-Importer' ) ].
spec
package: 'GitLabHealth-Model-Tests'
with: [ spec requires: #( 'GitLabHealth-Model' ) ].
spec
package: 'GitHubHealth-Model-Importer-Tests'
with: [ spec requires: #( 'GitHubHealth-Model-Importer' ) ].

"Bitbucket"
spec
package: 'BitBucketHealth-Model-Importer'
with: [ spec requires: #( 'BitbucketPharoAPI' ) ];
package: 'BitBucketHealth-Model-Importer' with: [
spec requires:
#( 'BitbucketPharoAPI' 'GitProjectHealth-Model-Importer' ) ];
package: 'BitBucketHealth-Model-Importer-Tests'
with: [ spec requires: #( 'BitBucketHealth-Model-Importer' ) ].

"github"
spec
package: 'GitHubHealth-Model-Importer'
with: [ spec requires: #( 'GithubAPI' ) ];
spec
package: 'GitHubHealth-Model-Importer' with: [
spec requires:
#( 'GithubAPI' 'NeoJSON' 'MoreLogger' 'GitProjectHealth-Model-Importer' ) ];
package: 'GitHubHealth-Model-Importer-Tests'
with: [ spec requires: #( 'GitHubHealth-Model-Importer' ) ].

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,38 +67,35 @@ CommitFrequencyMetricTest >> testCalculate [
CommitFrequencyMetricTest >> testCalculate1CommitByWeek [

| glhImporter result commitFrequency |

glhImporter := GLPHImporterMock new.

glhImporter commits: {
(GLHCommit new
glhImporter commits: {
(GLHCommit new
id: 1;
repository: project1 repository;
created_at: createdAt;
additions: 7;
commitCreator: user;
deletions: 5).
(GLHCommit new
(GLHCommit new
id: 2;
repository: project1 repository;
created_at: createdAt + 7 days;
additions: 7;
commitCreator: user;
deletions: 5).
(GLHCommit new
(GLHCommit new
id: 3;
repository: project1 repository;
created_at: createdAt + 7 days ;
created_at: createdAt + 7 days;
additions: 7;
commitCreator: user;
deletions: 5).
}.

deletions: 5) }.

commitFrequency := CommitFrequencyMetric new
user: user;
glhImporter: glhImporter;
setPeriodSince: createdAt asDate until: (createdAt + (7 + 7) days) asDate ;
setPeriodSince: since until: '09-18-2024';
over: Week.

"When"
Expand Down Expand Up @@ -141,8 +138,8 @@ CommitFrequencyMetricTest >> testCalculate1CommitByWeekFromAnotherUser [
commitFrequency := CommitFrequencyMetric new
user: user;
glhImporter: glhImporter;
setPeriodSince: createdAt asDate
until: (createdAt + (7 + 7) days) asDate;
setPeriodSince: since
until: '09-18-2024';
over: Week.

"When"
Expand Down
44 changes: 24 additions & 20 deletions src/GitLabHealth-Model-Analysis-Tests/GitAnalyzerLocalTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ GitAnalyzerLocalTest >> setUp [
gitAnalyzer := GitAnalyzer new onModel: glphModel.
fromCommit := GLHCommit new.
fromCommit short_id: 'testFromCommit'.
fromCommit created_at: ('3 August 2021' asDate).
"3 august 2021"
fromCommit created_at: (Date newDay: 3 month: 8 year: 2021).
glphModel add: fromCommit.
gitAnalyzer fromCommit: fromCommit.

gitAnalyzer fromCommit: fromCommit
]

{ #category : #test }
{ #category : #tests }
GitAnalyzerLocalTest >> testAnalyseCommentContributionsJavaComment [

| diffA diffARange addition |
Expand All @@ -46,7 +47,7 @@ GitAnalyzerLocalTest >> testAnalyseCommentContributionsJavaComment [
self assert: gitAnalyzer analyseCommentContribution equals: 1
]

{ #category : #test }
{ #category : #tests }
GitAnalyzerLocalTest >> testAnalyseCommentContributionsJavaContinueComment [

| diffA diffARange addition |
Expand All @@ -65,7 +66,7 @@ GitAnalyzerLocalTest >> testAnalyseCommentContributionsJavaContinueComment [
self assert: gitAnalyzer analyseCommentContribution equals: 1
]

{ #category : #test }
{ #category : #tests }
GitAnalyzerLocalTest >> testAnalyseCommentContributionsJavaStopComment [

| diffA diffARange addition |
Expand All @@ -84,7 +85,7 @@ GitAnalyzerLocalTest >> testAnalyseCommentContributionsJavaStopComment [
self assert: gitAnalyzer analyseCommentContribution equals: 1
]

{ #category : #test }
{ #category : #tests }
GitAnalyzerLocalTest >> testAnalyseCommentContributionsMixedMultipleComments [

| diffA diffARange addition additionB additionC |
Expand All @@ -111,7 +112,7 @@ GitAnalyzerLocalTest >> testAnalyseCommentContributionsMixedMultipleComments [
self assert: gitAnalyzer analyseCommentContribution equals: 2
]

{ #category : #test }
{ #category : #tests }
GitAnalyzerLocalTest >> testAnalyseCommentContributionsMultipleComments [

| diffA diffARange addition additionB additionC |
Expand All @@ -138,7 +139,7 @@ GitAnalyzerLocalTest >> testAnalyseCommentContributionsMultipleComments [
self assert: gitAnalyzer analyseCommentContribution equals: 3
]

{ #category : #test }
{ #category : #tests }
GitAnalyzerLocalTest >> testAnalyseCommentContributionsPythonComment [

| diffA diffARange addition |
Expand All @@ -157,7 +158,7 @@ GitAnalyzerLocalTest >> testAnalyseCommentContributionsPythonComment [
self assert: gitAnalyzer analyseCommentContribution equals: 1
]

{ #category : #test }
{ #category : #tests }
GitAnalyzerLocalTest >> testAnalyseCommentContributionsShouldBe0 [

| diffA diffARange addition |
Expand All @@ -176,7 +177,7 @@ GitAnalyzerLocalTest >> testAnalyseCommentContributionsShouldBe0 [
self assert: gitAnalyzer analyseCommentContribution equals: 0
]

{ #category : #test }
{ #category : #tests }
GitAnalyzerLocalTest >> testAnalyseCommentInSomeAroundCode [

| diffA diffARange addition |
Expand All @@ -195,7 +196,7 @@ GitAnalyzerLocalTest >> testAnalyseCommentInSomeAroundCode [
self assert: gitAnalyzer analyseCommentContribution equals: 0
]

{ #category : #test }
{ #category : #tests }
GitAnalyzerLocalTest >> testAnalyseCommentNotAnAddition [

| diffA diffARange addition |
Expand All @@ -214,32 +215,35 @@ GitAnalyzerLocalTest >> testAnalyseCommentNotAnAddition [
self assert: gitAnalyzer analyseCommentContribution equals: 0
]

{ #category : #test }
{ #category : #tests }
GitAnalyzerLocalTest >> testArrangeCommitsByDate [

| commitA2 commitA3 commitB result |
| commitA2 commitA3 commitB result threeAugust fourAugust |
threeAugust := Date newDay: 3 month: 8 year: 2021.
fourAugust := Date newDay: 4 month: 8 year: 2021.

commitA2 := GLHCommit new.
commitA2 short_id: 'testFromCommit2'.
commitA2 created_at: ('3 August 2021' asDate).
commitA2 created_at: threeAugust.
glphModel add: commitA2.

commitA3 := GLHCommit new.
commitA3 short_id: 'testFromCommit3'.
commitA3 created_at: ('3 August 2021' asDate).
commitA3 created_at: threeAugust.
glphModel add: commitA3.

commitB := GLHCommit new.
commitB short_id: 'testFromCommitB'.
commitB created_at: ('4 August 2021' asDate).
commitB created_at: fourAugust.
glphModel add: commitB.

result := gitAnalyzer arrangeCommitsByDate: {
fromCommit.
commitA2.
commitA3.
commitB }.

self assert: result size equals: 2.
self assert: (result at: '3 August 2021') size equals: 3.
self assert: (result at: '4 August 2021') size equals: 1.
self assert: (result at: threeAugust) size equals: 3.
self assert: (result at: fourAugust) size equals: 1
]
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ GitAnalyzerTest >> setUp [

glhImporter
importCommitsOfProject: projects first
since: since asDate
since: since
until: nil.

gitAnalyzer := GitAnalyzer new
Expand Down Expand Up @@ -106,8 +106,8 @@ GitAnalyzerTest >> testAnalyseCommitFrequencySinceUntil [
onProject: projects first;
analyseCommitFrequencySince: from asDate until: since asDate.

self assert: (res at: from) size equals: 1.
self assert: (res at: '14 May 2024') size equals: 4
self assert: (res values at: 1) size equals: 1.
self assert: (res values at: 2) size equals: 4
]

{ #category : #tests }
Expand Down
89 changes: 82 additions & 7 deletions src/GitLabHealth-Model-Analysis-Tests/MetricTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ MetricTest >> setUp [
super setUp.

"Put here a common initialization logic for tests"
createdAt := '2024-09-04T10:24:11.803+02:00' asDateAndTime.
closedAt := '2024-09-04T11:24:11.803+02:00' asDateAndTime.
mergedAt := '2024-09-04T11:24:11.803+02:00' asDateAndTime.
updatedAt := '2024-09-04T11:24:11.803+02:00' asDateAndTime.

since := '2024-09-04'.
until := '2024-09-05'
createdAt := '2024-09-04T10:24:11.803' asDateAndTime.
closedAt := '2024-09-04T11:24:11.803' asDateAndTime.
mergedAt := '2024-09-04T11:24:11.803' asDateAndTime.
updatedAt := '2024-09-04T11:24:11.803' asDateAndTime.
"mm-dd-yyyy"
since := '09-04-2024'.
until := '09-05-2024'
]

{ #category : #tests }
Expand All @@ -43,3 +43,78 @@ MetricTest >> testName [
"Then"
self assert: name equals: 'ProjectMetric'.
]

{ #category : #tests }
MetricTest >> testTransformDateTo [

| metric startingDate aWeekDateAndTime |
metric := Metric new.
aWeekDateAndTime := '2024-09-04T11:24:11.803+02:00' asDateAndTime.

startingDate := Date starting:
'2024-09-01T00:00:00.000+00:00' asDateAndTime.

self
assert: (metric transformDate: aWeekDateAndTime to: Week)
equals: startingDate
]

{ #category : #tests }
MetricTest >> testTransformDateToMonth [

| metric startingDate aWeekDateAndTime |
metric := Metric new.
aWeekDateAndTime := '2024-09-17T00:00:00.000+00:00' asDateAndTime.

startingDate := Date starting:
'2024-09-01T00:00:00.000+00:00' asDateAndTime.

self
assert: (metric transformDate: aWeekDateAndTime to: Month)
equals: startingDate
]

{ #category : #tests }
MetricTest >> testTransformDateToSameDate [

| metric startingDate aWeekDateAndTime |
metric := Metric new.
aWeekDateAndTime := '2024-09-01T00:00:00.000+00:00' asDateAndTime.

startingDate := Date starting:
'2024-09-01T00:00:00.000+00:00' asDateAndTime.

self
assert: (metric transformDate: aWeekDateAndTime to: Week)
equals: startingDate
]

{ #category : #tests }
MetricTest >> testTransformDateToSameDateWithOffset [

| metric startingDate aWeekDateAndTime |
metric := Metric new.
aWeekDateAndTime := '2024-09-01T00:00:00.000+02:00' asDateAndTime.

startingDate := Date starting:
'2024-09-01T00:00:00.000+00:00' asDateAndTime.

self
assert: (metric transformDate: aWeekDateAndTime to: Week)
equals: startingDate
]

{ #category : #tests }
MetricTest >> testTransformDateToWithDate [

| metric startingDate aWeekDateAndTime |
metric := Metric new.
aWeekDateAndTime := Date starting: '2024-09-04T11:24:11.803+02:00' asDateAndTime.

startingDate := Date starting:
'2024-09-01T00:00:00.000+00:00' asDateAndTime.

self
assert: (metric transformDate: aWeekDateAndTime to: Week)
equals: startingDate
]
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ActiveBranchesProjectMetric >> calculate [

dateOver := self transformDate: commit created_at to: over.
groupedByDate
at: dateOver printString
at: dateOver
ifPresent: [ :v | v add: commit created_at ] ].

groupedByDate := groupedByDate collect: [ :group | group size ].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ AutoCodeReviewCommitFrequencyProjectMetric >> calculate [
(c title beginsWith: '[ACR]') ifTrue: [
| dateOver |
dateOver := self transformDate: c created_at to: over.
groupedByDate at: dateOver printString ifPresent: [ :v | v add: c ]
groupedByDate at: dateOver ifPresent: [ :v | v add: c ]
]
].

Expand Down
Loading
Loading