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/metrics interface #9

Merged
merged 5 commits into from
Jul 25, 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 @@ -43,7 +43,7 @@ GitAnalyzerLocalTest >> testAnalyseCommentContributionsJavaComment [
diffARange addChange: addition.
addition sourceCode: '+ // hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 1
self assert: gitAnalyzer analyseCommentContribution equals: 1
]

{ #category : #test }
Expand All @@ -62,7 +62,7 @@ GitAnalyzerLocalTest >> testAnalyseCommentContributionsJavaContinueComment [
diffARange addChange: addition.
addition sourceCode: '+ * hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 1
self assert: gitAnalyzer analyseCommentContribution equals: 1
]

{ #category : #test }
Expand All @@ -81,7 +81,7 @@ GitAnalyzerLocalTest >> testAnalyseCommentContributionsJavaStopComment [
diffARange addChange: addition.
addition sourceCode: '+ */ hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 1
self assert: gitAnalyzer analyseCommentContribution equals: 1
]

{ #category : #test }
Expand All @@ -108,7 +108,7 @@ GitAnalyzerLocalTest >> testAnalyseCommentContributionsMixedMultipleComments [
diffARange addChange: additionC.
additionC sourceCode: '+ // hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 2
self assert: gitAnalyzer analyseCommentContribution equals: 2
]

{ #category : #test }
Expand All @@ -135,7 +135,7 @@ GitAnalyzerLocalTest >> testAnalyseCommentContributionsMultipleComments [
diffARange addChange: additionC.
additionC sourceCode: '+ // hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 3
self assert: gitAnalyzer analyseCommentContribution equals: 3
]

{ #category : #test }
Expand All @@ -154,7 +154,7 @@ GitAnalyzerLocalTest >> testAnalyseCommentContributionsPythonComment [
diffARange addChange: addition.
addition sourceCode: '+ */ hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 1
self assert: gitAnalyzer analyseCommentContribution equals: 1
]

{ #category : #test }
Expand All @@ -173,7 +173,7 @@ GitAnalyzerLocalTest >> testAnalyseCommentContributionsShouldBe0 [
diffARange addChange: addition.
addition sourceCode: '+ hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 0
self assert: gitAnalyzer analyseCommentContribution equals: 0
]

{ #category : #test }
Expand All @@ -192,7 +192,7 @@ GitAnalyzerLocalTest >> testAnalyseCommentInSomeAroundCode [
diffARange addChange: addition.
addition sourceCode: '// hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 0
self assert: gitAnalyzer analyseCommentContribution equals: 0
]

{ #category : #test }
Expand All @@ -211,7 +211,7 @@ GitAnalyzerLocalTest >> testAnalyseCommentNotAnAddition [
diffARange addChange: addition.
addition sourceCode: '- // hello world'.

self assert: gitAnalyzer analyseCommentContributions equals: 0
self assert: gitAnalyzer analyseCommentContribution equals: 0
]

{ #category : #test }
Expand Down
12 changes: 6 additions & 6 deletions src/GitLabHealth-Model-Analysis-Tests/GitAnalyzerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ GitAnalyzerTest >> setUp [
glhApi: glphApi;
glhModel: glphModel;
withFiles: false;
withCommitsSince: 0 day;

withCommitDiffs: true.

glhImporter importProject: 57841283.
Expand Down Expand Up @@ -90,7 +90,7 @@ GitAnalyzerTest >> testAnalyseAmandment [
glhImporter: glhImporter;
onModel: glphModel;
maxChildCommit: 5;
analyseAmandment.
analyseDelayUntilFirstChurn.


self assert: res equals: tuesdayCommit
Expand Down Expand Up @@ -138,9 +138,7 @@ GitAnalyzerTest >> testChurnMetric [
| myCommits res wednesdayCommit mondayCommit tuesdayCommit codeJs churn4CodeJs |
glhImporter withCommitDiffs: true.

"commit chain
mondayCommit -> tuesdayCommit -> wednesdayCommit
"
"commit chain: mondayCommit -> tuesdayCommit -> wednesdayCommit "
wednesdayCommit := glhImporter
importCommitOfProject: projects first
withId:
Expand Down Expand Up @@ -178,6 +176,8 @@ GitAnalyzerTest >> testChurnMetric [
churn4CodeJs := codeJs value.

self assert: (churn4CodeJs at: #churnLoC) equals: 3 .
self assert: (churn4CodeJs at: #locContributed) equals: 7 .
self assert: (churn4CodeJs at: #churnFromInitialCommitLines) equals: 2 .
self assert: (churn4CodeJs at: #churnFromCommitCreatorOnly ) equals: 2.
self assert: (res at: #totalContribution) equals: 7.

]
98 changes: 59 additions & 39 deletions src/GitLabHealth-Model-Analysis/GitAnalyzer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,6 @@ Class {
#category : #'GitLabHealth-Model-Analysis'
}

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

| churn res access|

access := ('' join: {
'amandment'.
maxChildCommits }) asSymbol.

^ fromCommit cacheAt: access ifPresent: [ :v | v ] ifAbsentPut: [

('GitAnalyzer, analyse amandment onProject: ', onProject printString )
recordInfo.

churn := self analyseChurn.

res := self firstAmandmentFromChrun: churn.
res]
]

{ #category : #analyze }
GitAnalyzer >> analyseChurn [

Expand All @@ -48,6 +27,7 @@ GitAnalyzer >> analyseChurn [
visitChildCommits: fromCommit childCommits
toStoreThemIn: childCommits
upto: self maxChildCommits.
totalContribution add: fromCommit.
totalContribution := totalContribution sum: [ :commit | "nil if merge request commit"
commit additions ifNil: [ 0 ] ].
commitFiles := self
Expand All @@ -60,7 +40,7 @@ GitAnalyzer >> analyseChurn [
]

{ #category : #analyze }
GitAnalyzer >> analyseCommentContributions [
GitAnalyzer >> analyseCommentContribution [

| numberOfComments |
('GitAnalyzer, analyse comment contributions onProject: '
Expand Down Expand Up @@ -130,6 +110,27 @@ GitAnalyzer >> analyseCommitFrequencySince: since until: until [
^ commits
]

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

| churn res access|

access := ('' join: {
'amandment'.
maxChildCommits }) asSymbol.

^ fromCommit cacheAt: access ifPresent: [ :v | v ] ifAbsentPut: [

('GitAnalyzer, analyse amandment onProject: ', onProject printString )
recordInfo.

churn := self analyseChurn.

res := self firstAmandmentFromChrun: churn.
res]
]

{ #category : #analyze }
GitAnalyzer >> analyseMergeResquestValidation: aGLHPMergeRequest [

Expand Down Expand Up @@ -183,36 +184,55 @@ GitAnalyzer >> arrangeCommitsByDate: commits [
{ #category : #churn }
GitAnalyzer >> computeChurnOnFiles: aCollection [

| changesDic perFileChanges churns |
| changesDic perFileChanges churns initialAuthor followingAuthors|
"1 -> (a GLPHEChange -> NumberOfChurnDetected)"
changesDic := Dictionary new.

initialAuthor := fromCommit commitCreator.


perFileChanges := aCollection associations collect: [ :assoc |
assoc key
-> (self computeSpecificChurnOf: assoc value) ].


churns := perFileChanges collect: [ :assoc |
| churn file results |
| churnData file aLineOfChanges |
file := assoc key.
results := assoc value.
results values ifEmpty: [ churn := nil ] ifNotEmpty: [
| churnedContribution locContributed |
"churn contribution are the LoC that were affected by a churn"
churnedContribution := results values select: [ :a |
a value > 1 ].
locContributed := results values sum: [ :a | a value ].

churn := {
aLineOfChanges := assoc value.
churnData := aLineOfChanges values ifEmpty: [ nil ] ifNotEmpty: [
| churnedContribution churnSpecificFromCommit churnOfAuthorOnly |

"the total churn on any LoC affected"
churnedContribution := aLineOfChanges select: [ :a |
a value > 1 ].

"the churn that coccurs specifically on the loc introduced by the initial commit"
churnSpecificFromCommit := churnedContribution select: [ :a |
(a key collect: [ :loc |
loc diffRange diff commit ])
includes: fromCommit ].

"the churn made the author of the initial commits "
churnOfAuthorOnly := churnSpecificFromCommit select: [ :a |
(((a key collect: [ :loc |
loc diffRange diff commit commitCreator ]) asSet) difference: {initialAuthor} asSet ) isEmpty
].


{
(#churnFromInitialCommitLines
->
((churnSpecificFromCommit sum: #value) - churnSpecificFromCommit size)).
(#churnFromCommitCreatorOnly
->
((churnOfAuthorOnly sum: #value) - churnOfAuthorOnly size)).
(#churnLoC
->
((churnedContribution sum: [ :a | a value ])
- churnedContribution size)).
(#locContributed -> locContributed) }
asDictionary ].
((churnedContribution sum: #value)
- churnedContribution size))
} asDictionary ].

file -> churn ].
file -> churnData ].
churns := churns reject: [ :file2churn | file2churn value isNil ].

^ {
Expand Down
Loading
Loading