Skip to content

Commit

Permalink
Merge 9ef24c9
Browse files Browse the repository at this point in the history
  • Loading branch information
HLAD Nicolas committed Jun 26, 2024
2 parents d8a5df8 + 9ef24c9 commit 1d2c206
Show file tree
Hide file tree
Showing 5 changed files with 304 additions and 56 deletions.
245 changes: 245 additions & 0 deletions src/GitLabHealth-Model-Analysis-Tests/GitAnalyzerLocalTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
Class {
#name : #GitAnalyzerLocalTest,
#superclass : #TestCase,
#instVars : [
'glphModel',
'glphApi',
'glhImporter',
'projects',
'gitAnalyzer',
'fromCommit'
],
#category : #'GitLabHealth-Model-Analysis-Tests'
}

{ #category : #running }
GitAnalyzerLocalTest >> setUp [

super setUp.

glphModel := GLPHEModel new.
gitAnalyzer := GitAnalyzer new onModel: glphModel.
fromCommit := GLHCommit new.
fromCommit short_id: 'testFromCommit'.
fromCommit created_at: ('3 August 2021' asDate).
glphModel add: fromCommit.

gitAnalyzer fromCommit: fromCommit.
]

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

| diffA diffARange addition |
diffA := GLHDiff new.
diffA new_path: 'new/test/path.txt'.
fromCommit addDiff: diffA.
glphModel add: diffA.
"Set DiffA ranges"
diffARange := glphModel newDiffRange.
diffA diffRanges: { diffARange }.

addition := glphModel newAddition.
diffARange addChange: addition.
addition sourceCode: '+ // hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 1
]

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

| diffA diffARange addition |
diffA := GLHDiff new.
diffA new_path: 'new/test/path.txt'.
fromCommit addDiff: diffA.
glphModel add: diffA.
"Set DiffA ranges"
diffARange := glphModel newDiffRange.
diffA diffRanges: { diffARange }.

addition := glphModel newAddition.
diffARange addChange: addition.
addition sourceCode: '+ * hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 1
]

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

| diffA diffARange addition |
diffA := GLHDiff new.
diffA new_path: 'new/test/path.txt'.
fromCommit addDiff: diffA.
glphModel add: diffA.
"Set DiffA ranges"
diffARange := glphModel newDiffRange.
diffA diffRanges: { diffARange }.

addition := glphModel newAddition.
diffARange addChange: addition.
addition sourceCode: '+ */ hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 1
]

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

| diffA diffARange addition additionB additionC |
diffA := GLHDiff new.
diffA new_path: 'new/test/path.txt'.
fromCommit addDiff: diffA.
glphModel add: diffA.
"Set DiffA ranges"
diffARange := glphModel newDiffRange.
diffA diffRanges: { diffARange }.

addition := glphModel newAddition.
diffARange addChange: addition.
addition sourceCode: '+ // hello world'.

additionB := glphModel newDeletion.
diffARange addChange: additionB.
additionB sourceCode: '- // hello world'.

additionC := glphModel newAddition.
diffARange addChange: additionC.
additionC sourceCode: '+ // hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 2
]

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

| diffA diffARange addition additionB additionC |
diffA := GLHDiff new.
diffA new_path: 'new/test/path.txt'.
fromCommit addDiff: diffA.
glphModel add: diffA.
"Set DiffA ranges"
diffARange := glphModel newDiffRange.
diffA diffRanges: { diffARange }.

addition := glphModel newAddition.
diffARange addChange: addition.
addition sourceCode: '+ // hello world'.

additionB := glphModel newAddition.
diffARange addChange: additionB.
additionB sourceCode: '+ // hello world'.

additionC := glphModel newAddition.
diffARange addChange: additionC.
additionC sourceCode: '+ // hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 3
]

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

| diffA diffARange addition |
diffA := GLHDiff new.
diffA new_path: 'new/test/path.txt'.
fromCommit addDiff: diffA.
glphModel add: diffA.
"Set DiffA ranges"
diffARange := glphModel newDiffRange.
diffA diffRanges: { diffARange }.

addition := glphModel newAddition.
diffARange addChange: addition.
addition sourceCode: '+ */ hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 1
]

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

| diffA diffARange addition |
diffA := GLHDiff new.
diffA new_path: 'new/test/path.txt'.
fromCommit addDiff: diffA.
glphModel add: diffA.
"Set DiffA ranges"
diffARange := glphModel newDiffRange.
diffA diffRanges: { diffARange }.

addition := glphModel newAddition.
diffARange addChange: addition.
addition sourceCode: '+ hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 0
]

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

| diffA diffARange addition |
diffA := GLHDiff new.
diffA new_path: 'new/test/path.txt'.
fromCommit addDiff: diffA.
glphModel add: diffA.
"Set DiffA ranges"
diffARange := glphModel newDiffRange.
diffA diffRanges: { diffARange }.

addition := glphModel newLineOfCode.
diffARange addChange: addition.
addition sourceCode: '// hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 0
]

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

| diffA diffARange addition |
diffA := GLHDiff new.
diffA new_path: 'new/test/path.txt'.
fromCommit addDiff: diffA.
glphModel add: diffA.
"Set DiffA ranges"
diffARange := glphModel newDiffRange.
diffA diffRanges: { diffARange }.

addition := glphModel newDeletion.
diffARange addChange: addition.
addition sourceCode: '- // hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 0
]

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

| commitA2 commitA3 commitB result |
commitA2 := GLHCommit new.
commitA2 short_id: 'testFromCommit2'.
commitA2 created_at: ('3 August 2021' asDate).
glphModel add: commitA2.

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

commitB := GLHCommit new.
commitB short_id: 'testFromCommitB'.
commitB created_at: ('4 August 2021' asDate).
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.
]
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ GitAnalyzerTest >> setUp [
importCommitsOProject: projects first
since: since asDate
until: nil.
gitAnalyzer := GitAnalyzer new
glhImporter: glhImporter;
onModel: glphModel.

gitAnalyzer := GitAnalyzer new
glhImporter: glhImporter;
onModel: glphModel
]

{ #category : #test }
Expand Down
69 changes: 35 additions & 34 deletions src/GitLabHealth-Model-Analysis/GitAnalyzer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Class {
#category : #'GitLabHealth-Model-Analysis'
}

{ #category : #'as yet unclassified' }
{ #category : #analyze }
GitAnalyzer >> analyseAmandment [
"return the first commit that modify the same lines of code as the fromCommit"

Expand All @@ -32,7 +32,7 @@ GitAnalyzer >> analyseAmandment [
res]
]

{ #category : #'as yet unclassified' }
{ #category : #analyze }
GitAnalyzer >> analyseChurn [

| commitFiles totalContribution childCommits access |
Expand All @@ -59,26 +59,21 @@ GitAnalyzer >> analyseChurn [
yourself ]
]

{ #category : #'as yet unclassified' }
{ #category : #analyze }
GitAnalyzer >> analyseCommentContributions [

| additions |
| numberOfComments |
('GitAnalyzer, analyse comment contributions onProject: '
, onProject printString) recordInfo.

additions := (fromCommit diffs collect: [ :diff |
diff diffRanges collect: [ :range |
range changes select: [ :change |
change class = GLPHEAddition ] ] ]) flattened
collect: [ :add | add sourceCode ].

additions := additions collect: [ :codeSource |
(codeSource withoutPrefix: '+') trimLeft ].
additions := additions select: [ :codeSource |
codeSource beginsWithAnyOf:
{ '#'. '//'. '/*'. '*'. '*/' } ].

^ additions size
numberOfComments := 0.
fromCommit diffs do: [ :diff |
diff diffRanges do: [ :range |
range changes do: [ :change |
((change isKindOf: GLPHEAddition) and: [
(change sourceCode withoutPrefix: '+') trimLeft
beginsWithAnyOf: { '#'. '//'. '/*'. '*'. '*/' } ]) ifTrue: [
numberOfComments := numberOfComments + 1 ] ] ] ].
^ numberOfComments
]

{ #category : #commit }
Expand All @@ -92,15 +87,15 @@ GitAnalyzer >> analyseCommitContribution [
(#deletion -> fromCommit deletions). } asDictionary
]

{ #category : #'as yet unclassified' }
{ #category : #analyze }
GitAnalyzer >> analyseCommitFrequencyFromCommits: initialCommits [

| commits response |

('GitAnalyzer, analyse commit Frequency on: ', onProject printString )
('GitAnalyzer, analyse commit Frequency on: ' , onProject printString)
recordInfo.

response := { (#numberOfCommit -> nil).

response := {
(#numberOfCommit -> nil).
(#frequency -> nil) } asDictionary.


Expand All @@ -111,7 +106,7 @@ GitAnalyzer >> analyseCommitFrequencyFromCommits: initialCommits [
^ commits
]

{ #category : #'as yet unclassified' }
{ #category : #analyze }
GitAnalyzer >> analyseCommitFrequencySince: since until: until [

| commits response |
Expand All @@ -135,7 +130,7 @@ GitAnalyzer >> analyseCommitFrequencySince: since until: until [
^ commits
]

{ #category : #'as yet unclassified' }
{ #category : #analyze }
GitAnalyzer >> analyseMergeResquestValidation: aGLHPMergeRequest [

| creationDate mergedDate response |
Expand Down Expand Up @@ -167,16 +162,22 @@ GitAnalyzer >> analyseMergeResquestValidation: aGLHPMergeRequest [
]

{ #category : #filter }
GitAnalyzer >> arrangeCommitsByDate: commits [
|date2commits|
date2commits := Dictionary new.

GitAnalyzer >> arrangeCommitsByDate: commits [

| date2commits |
date2commits := Dictionary new.

commits do: [ :commit |
|date|
date := commit created_at asDate.
date2commits at: date printString ifPresent: [ :v | v add: commit ] ifAbsentPut: [ OrderedCollection new add: commit; yourself. ].
].
^ date2commits.
| date |
date := commit created_at asDate.
date2commits
at: date printString
ifPresent: [ :v | v add: commit ]
ifAbsentPut: [
OrderedCollection new
add: commit;
yourself ] ].
^ date2commits
]

{ #category : #churn }
Expand Down
Loading

0 comments on commit 1d2c206

Please sign in to comment.