• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

moosetechnology / GitProjectHealth / 16492733076

24 Jul 2025 09:10AM UTC coverage: 74.048% (+0.9%) from 73.181%
16492733076

Pull #219

github

web-flow
Merge 94ad9dfb1 into 55903cdcb
Pull Request #219: branch metrics

742 of 761 new or added lines in 12 files covered. (97.5%)

32 existing lines in 2 files now uncovered.

18475 of 24950 relevant lines covered (74.05%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

74.57
/src/GitProjectHealth-Model-Importer/GitModelImporter.class.st
1
"
2
I am a superclass for Model importer.
3
I am a try of normalization for the different importer.
4

5
I also define some contract so it is easier to switch from one importer to another
6
"
7
Class {
8
        #name : #GitModelImporter,
9
        #superclass : #Object,
10
        #instVars : [
11
                'withCommitsSince',
12
                'withFiles',
13
                'glhModel',
14
                'userCatalogue',
15
                'repoApi',
16
                'withCommitDiffs'
17
        ],
18
        #classVars : [
19
                'currentImporter'
20
        ],
21
        #category : #'GitProjectHealth-Model-Importer'
22
}
23

24
{ #category : #'accessing - global variables' }
25
GitModelImporter class >> importers [
×
26
        ^ currentImporter 
×
27
]
×
28

29
{ #category : #initialization }
30
GitModelImporter class >> reset [
×
31
        currentImporter := OrderedDictionary new.
×
32
]
×
33

34
{ #category : #accessing }
35
GitModelImporter >> beWithFiles [
×
36

×
37
        withFiles := true
×
38
]
×
39

40
{ #category : #accessing }
41
GitModelImporter >> beWithoutFiles [
×
42

×
43
        withFiles := false
×
44
]
×
45

46
{ #category : #'as yet unclassified' }
47
GitModelImporter >> blockEqualityOn: aSymbol [
1✔
48
        ^ [ :existing :new |
1✔
49
          (existing perform: aSymbol) = (new perform: aSymbol) ]
1✔
50
]
1✔
51

52
{ #category : #'as yet unclassified' }
NEW
53
GitModelImporter >> blockEqualityOn: aSymbol andOn: aSecondSymbol [
×
NEW
54
        ^ (self blockEqualityOn: aSymbol) and: [ self blockEqualityOn: aSecondSymbol ]
×
NEW
55
]
×
56

57
{ #category : #equality }
58
GitModelImporter >> blockForBranchEquality [
1✔
59
        ^ [ :existing :new |
1✔
60
          (existing name = new name) and: [ existing repository project id = new repository project id ] ]
1✔
61
        
1✔
62
]
1✔
63

64
{ #category : #equality }
65
GitModelImporter >> blockForDiffEquality [
1✔
66
        ^ [ :existing :new |
1✔
67
                        existing diffString size = new diffString size and: [
1✔
68
                                existing diffString = new diffString ] ]
1✔
69
]
1✔
70

71
{ #category : #'as yet unclassified' }
72
GitModelImporter >> blockForDiffRangeEquality [
1✔
73

1✔
74
        ^ [ :existing :new |
1✔
75
          existing diff mooseID = new diff mooseID and: [
1✔
76
                  existing originalLineRange = new originalLineRange and: [
1✔
77
                          existing newLineRange = new newLineRange ] ] ]
1✔
78
]
1✔
79

80
{ #category : #equality }
81
GitModelImporter >> blockOnIdEquality [
1✔
82

1✔
83
        ^ [ :existing :new |
1✔
84
          existing id = new id ]
1✔
85
]
1✔
86

87
{ #category : #equality }
88
GitModelImporter >> blockOnNameEquality [
1✔
89

1✔
90
        ^ self blockEqualityOn: #name
1✔
91
]
1✔
92

93
{ #category : #commit }
94
GitModelImporter >> chainsCommitsFrom: commitsCollection [
1✔
95

1✔
96
        | dic |
1✔
97
        ('Chains ' , commitsCollection size printString , ' commits')
1✔
98
                recordInfo.
1✔
99

1✔
100
        dic := ((self glhModel allWithType: GLHCommit) collect: [ :commit |
1✔
101
                        commit id -> commit ]) asSet asDictionary.
1✔
102

1✔
103
        commitsCollection do: [ :commit |
1✔
104
                commit parent_ids do: [ :parentId |
1✔
105
                        dic
1✔
106
                                at: parentId
1✔
107
                                ifPresent: [ :parentCommit |
1✔
108
                                        parentCommit childCommits
1✔
109
                                                add: commit
1✔
110
                                                unless: [ :existing :new | existing id = new id ] ]
1✔
111
                                ifAbsent: [  ] ] ].
1✔
112
        ^ commitsCollection
1✔
113
]
1✔
114

115
{ #category : #commit }
116
GitModelImporter >> completeImportedCommit: aGLHCommit [ 
×
117
        
×
118
        
×
119
        ('completing commit: ' , aGLHCommit short_id printString) recordInfo.
×
120
        self importCreatorOfCommit: aGLHCommit.
×
121

×
122
        self withCommitDiffs ifTrue: [
×
123
                | diffs |
×
124
                aGLHCommit diffs ifEmpty: [
×
125
                        diffs := self importDiffOfCommit: aGLHCommit.
×
126
                        self glhModel addAll: diffs unless: self blockForDiffEquality ] ].
×
127

×
128
        ^ aGLHCommit
×
129
]
×
130

131
{ #category : #'as yet unclassified' }
132
GitModelImporter >> filterCommitChanges: aCollection [
1✔
133

1✔
134
        ^ aCollection reject: [ :line |
1✔
135
                  | trimmedLine |
1✔
136
                  trimmedLine := line trimLeft.
1✔
137
                  (trimmedLine beginsWith: '---') or: [
1✔
138
                          (trimmedLine beginsWith: '+++') or: [
1✔
139
                                  trimmedLine beginsWith: '\ No newline at end of file' ] ] ]
1✔
140
]
1✔
141

142
{ #category : #accessing }
143
GitModelImporter >> glhModel [
1✔
144

1✔
145
        ^ glhModel
1✔
146
]
1✔
147

148
{ #category : #accessing }
149
GitModelImporter >> glhModel: anObject [
1✔
150

1✔
151
        glhModel := anObject
1✔
152
]
1✔
153

154
{ #category : #import }
155
GitModelImporter >> importDiffRangesForDiff: aGLHDiff [
1✔
156

1✔
157
        | diffRanges |
1✔
158
        aGLHDiff diffRanges ifNotEmpty: [
1✔
159
                ('Diffs already imported for ' , aGLHDiff printString) recordInfo.
1✔
160
                ^ aGLHDiff diffRanges ].
1✔
161

1✔
162
        ('Import changes of diff ' , aGLHDiff printString) recordInfo.
1✔
163
        "the import of 'diffRanges' entites is technically done inside the parseDiffString"
1✔
164

1✔
165
        diffRanges := self glhModel
1✔
166
                              addAll: (self parseDiffString: aGLHDiff)
1✔
167
                              unless: self blockForDiffRangeEquality.
1✔
168
        ^ aGLHDiff diffRanges
1✔
169
                  addAll: diffRanges
1✔
170
                  unless: self blockForDiffRangeEquality
1✔
171
]
1✔
172

173
{ #category : #'import - groups' }
174
GitModelImporter >> importGroup: aGroupID [
175

176
        self subclassResponsibility
177
]
178

179
{ #category : #pipelines }
180
GitModelImporter >> importLatestPipelinesOfProject: aGLHProject [ 
×
181
        (self pipelinesOf: aGLHProject id withLimit:30) do: [ :pipeline |
×
182
                self glhModel add: pipeline unless: self blockOnIdEquality .
×
183
                aGLHProject pipelines add: pipeline unless: self blockOnIdEquality]
×
184
]
×
185

186
{ #category : #'import - notes' }
187
GitModelImporter >> importNotesfromMergeRequest: mergeRequest [
188

189
        self subclassResponsibility
190
]
191

192
{ #category : #'import - projects' }
193
GitModelImporter >> importProject: id [
194
        "id can be a string or an integer depending on the APi implementation"
195

196
        "return the project created or retrieved"
197

198
        ^ self subclassResponsibility
199
]
200

201
{ #category : #'import - projects' }
202
GitModelImporter >> importProjects: aCollectionOfProjectID [
×
203

×
204

×
205
        ^ aCollectionOfProjectID collect: [ :id | self importProject: id ]
×
206
]
×
207

208
{ #category : #initialization }
209
GitModelImporter >> initialize [
1✔
210

1✔
211
        super initialize.
1✔
212
        self withCommitsSince: (Date today - 1 week) asDateAndTime.
1✔
213
                userCatalogue := GLHUserCatalogueV2 new
1✔
214
                                 anImporter: self;
1✔
215
                                 yourself.
1✔
216
]
1✔
217

218
{ #category : #'as yet unclassified' }
219
GitModelImporter >> makeGlobal [
×
220
        ^ self makeGlobal: DateAndTime now printString.
×
221
]
×
222

223
{ #category : #'as yet unclassified' }
224
GitModelImporter >> makeGlobal: aLabel [ 
×
225

×
226
        currentImporter := GithubModelImporter importers ifNil: [ OrderedDictionary new ].
×
227
        currentImporter at: aLabel put: self. 
×
228
        ^ currentImporter 
×
229
]
×
230

231
{ #category : #parsing }
232
GitModelImporter >> parseDiffString: aDiff [
1✔
233
        "parse diff string to create entities for each lines"
1✔
234

1✔
235
        | lines range index firstChangeRange |
1✔
236
        lines := aDiff diffString lines.
1✔
237
        index := 0.
1✔
238
        range := nil.
1✔
239

1✔
240
        lines ifEmpty: [ ^ aDiff diffRanges ].
1✔
241
        lines := self filterCommitChanges: lines.
1✔
242
        lines ifEmpty: [ ^ aDiff diffRanges ].
1✔
243
        (lines first beginsWith: '@@') ifFalse: [ ^ aDiff diffRanges ].
1✔
244

1✔
245
        lines do: [ :line |
1✔
246
                | aChange |
1✔
247
                firstChangeRange := false.
1✔
248
                (line trim beginsWith: #'@@') ifTrue: [
1✔
249
                        range := GLHDiffRange newFrom: line.
1✔
250
                        firstChangeRange := true.
1✔
251
                        range := aDiff diffRanges add: range unless: [ :existing :new |
1✔
252
                                         existing originalLineRange = new originalLineRange and: [
1✔
253
                                                 existing newLineRange = new newLineRange ] ] ].
1✔
254

1✔
255
                self withCommitDiffs ifTrue: [
1✔
256
                        firstChangeRange ifFalse: [
1✔
257
                                aChange := GLHChange newFrom: line.
1✔
258
                                aChange relativeIndex: index.
1✔
259
                                aChange := range changes add: aChange unless: [ :existing :new |
1✔
260
                                                   existing sourceCode = new sourceCode and: [
1✔
261
                                                           existing index = new index ] ].
1✔
262
                                index := index + 1 ] ] ].
1✔
263

1✔
264
        "add changes to the diff range"
1✔
265
        aDiff diffRanges do: [ :diffRange |
1✔
266
                self glhModel addAll: diffRange changes unless: [ :existing :new |
1✔
267
                        existing diffRange mooseID = new diffRange mooseID and: [
1✔
268
                                existing sourceCode = new sourceCode and: [
1✔
269
                                        existing index = new index ] ] ] ].
1✔
270

1✔
271
        ^ aDiff diffRanges
1✔
272
]
1✔
273

274
{ #category : #accessing }
275
GitModelImporter >> repoApi [
1✔
276

1✔
277
        ^ repoApi
1✔
278
]
1✔
279

280
{ #category : #accessing }
281
GitModelImporter >> repoApi: anObject [
1✔
282

1✔
283
        repoApi := anObject
1✔
284
]
1✔
285

286
{ #category : #accessing }
287
GitModelImporter >> userCatalogue [
1✔
288
        ^ userCatalogue 
1✔
289
]
1✔
290

291
{ #category : #accessing }
292
GitModelImporter >> userCatalogue: aGLHUserCatalogue [
×
293

×
294
        userCatalogue := aGLHUserCatalogue.
×
295
        aGLHUserCatalogue anImporter: self. 
×
296
]
×
297

298
{ #category : #accessing }
299
GitModelImporter >> withCommitDiffs [
1✔
300

1✔
301
        ^ withCommitDiffs
1✔
302
]
1✔
303

304
{ #category : #accessing }
305
GitModelImporter >> withCommitDiffs: anObject [
1✔
306

1✔
307
        withCommitDiffs := anObject
1✔
308
]
1✔
309

310
{ #category : #accessing }
311
GitModelImporter >> withCommitsSince [
×
312

×
313
        ^ withCommitsSince
×
314
]
×
315

316
{ #category : #accessing }
317
GitModelImporter >> withCommitsSince: someDays [
1✔
318
        "substract the current date with a given number of days. Use to retrieve the commits submit in the last giving days"
1✔
319

1✔
320
        "(GitlabModelImporter new withCommitsSince: 1 week ) >>> (Date today - 1 week) asDateAndTime"
1✔
321

1✔
322
        "(GitlabModelImporter new withCommitsSince: 30 day ) >>> (Date today - 30 day) asDateAndTime"
1✔
323

1✔
324
        (someDays isKindOf: DateAndTime)
1✔
325
                ifTrue: [ withCommitsSince := someDays ]
1✔
326
                ifFalse: [
1✔
327
                withCommitsSince := (DateAndTime today - someDays) ].
1✔
328
        ^ withCommitsSince
1✔
329
]
1✔
330

331
{ #category : #accessing }
332
GitModelImporter >> withFiles [
1✔
333

1✔
334
        ^ withFiles
1✔
335
]
1✔
336

337
{ #category : #accessing }
338
GitModelImporter >> withFiles: anObject [
1✔
339

1✔
340
        withFiles := anObject
1✔
341
]
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc