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

moosetechnology / GitProjectHealth / 17262821407

27 Aug 2025 09:26AM UTC coverage: 73.322% (-1.6%) from 74.896%
17262821407

push

github

web-flow
Merge pull request #223 from moosetechnology/develop

Update main

1000 of 2102 new or added lines in 33 files covered. (47.57%)

28 existing lines in 2 files now uncovered.

18579 of 25339 relevant lines covered (73.32%)

0.73 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 - repositories' }
155
GitModelImporter >> importBranchesOf: aGLHProject [
156

157
        ^ self subclassResponsibility
158
]
159

160
{ #category : #import }
161
GitModelImporter >> importDiffRangesForDiff: aGLHDiff [
1✔
162

1✔
163
        | diffRanges |
1✔
164
        aGLHDiff diffRanges ifNotEmpty: [
1✔
165
                ('Diffs already imported for ' , aGLHDiff printString) recordInfo.
1✔
166
                ^ aGLHDiff diffRanges ].
1✔
167

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

1✔
171
        diffRanges := self glhModel
1✔
172
                              addAll: (self parseDiffString: aGLHDiff)
1✔
173
                              unless: self blockForDiffRangeEquality.
1✔
174
        ^ aGLHDiff diffRanges
1✔
175
                  addAll: diffRanges
1✔
176
                  unless: self blockForDiffRangeEquality
1✔
177
]
1✔
178

179
{ #category : #'import - groups' }
180
GitModelImporter >> importGroup: aGroupID [
181

182
        self subclassResponsibility
183
]
184

185
{ #category : #pipelines }
186
GitModelImporter >> importLatestPipelinesOfProject: aGLHProject [ 
×
187
        (self pipelinesOf: aGLHProject id withLimit:30) do: [ :pipeline |
×
188
                self glhModel add: pipeline unless: self blockOnIdEquality .
×
189
                aGLHProject pipelines add: pipeline unless: self blockOnIdEquality]
×
190
]
×
191

192
{ #category : #'import - notes' }
193
GitModelImporter >> importNotesfromMergeRequest: mergeRequest [
194

195
        self subclassResponsibility
196
]
197

198
{ #category : #'import - projects' }
199
GitModelImporter >> importProject: id [
200
        "id can be a string or an integer depending on the APi implementation"
201

202
        "return the project created or retrieved"
203

204
        ^ self subclassResponsibility
205
]
206

207
{ #category : #'import - projects' }
208
GitModelImporter >> importProjects: aCollectionOfProjectID [
×
209

×
210

×
211
        ^ aCollectionOfProjectID collect: [ :id | self importProject: id ]
×
212
]
×
213

214
{ #category : #initialization }
215
GitModelImporter >> initialize [
1✔
216

1✔
217
        super initialize.
1✔
218
        self withCommitsSince: (Date today - 1 week) asDateAndTime.
1✔
219
                userCatalogue := GLHUserCatalogueV2 new
1✔
220
                                 anImporter: self;
1✔
221
                                 yourself.
1✔
222
]
1✔
223

224
{ #category : #'as yet unclassified' }
225
GitModelImporter >> makeGlobal [
×
226
        ^ self makeGlobal: DateAndTime now printString.
×
227
]
×
228

229
{ #category : #'as yet unclassified' }
230
GitModelImporter >> makeGlobal: aLabel [ 
×
231

×
232
        currentImporter := GithubModelImporter importers ifNil: [ OrderedDictionary new ].
×
233
        currentImporter at: aLabel put: self. 
×
234
        ^ currentImporter 
×
235
]
×
236

237
{ #category : #parsing }
238
GitModelImporter >> parseDiffString: aDiff [
1✔
239
        "parse diff string to create entities for each lines"
1✔
240

1✔
241
        | lines range index firstChangeRange |
1✔
242
        lines := aDiff diffString lines.
1✔
243
        index := 0.
1✔
244
        range := nil.
1✔
245

1✔
246
        lines ifEmpty: [ ^ aDiff diffRanges ].
1✔
247
        lines := self filterCommitChanges: lines.
1✔
248
        lines ifEmpty: [ ^ aDiff diffRanges ].
1✔
249
        (lines first beginsWith: '@@') ifFalse: [ ^ aDiff diffRanges ].
1✔
250

1✔
251
        lines do: [ :line |
1✔
252
                | aChange |
1✔
253
                firstChangeRange := false.
1✔
254
                (line trim beginsWith: #'@@') ifTrue: [
1✔
255
                        range := GLHDiffRange newFrom: line.
1✔
256
                        firstChangeRange := true.
1✔
257
                        range := aDiff diffRanges add: range unless: [ :existing :new |
1✔
258
                                         existing originalLineRange = new originalLineRange and: [
1✔
259
                                                 existing newLineRange = new newLineRange ] ] ].
1✔
260

1✔
261
                self withCommitDiffs ifTrue: [
1✔
262
                        firstChangeRange ifFalse: [
1✔
263
                                aChange := GLHChange newFrom: line.
1✔
264
                                aChange relativeIndex: index.
1✔
265
                                aChange := range changes add: aChange unless: [ :existing :new |
1✔
266
                                                   existing sourceCode = new sourceCode and: [
1✔
267
                                                           existing index = new index ] ].
1✔
268
                                index := index + 1 ] ] ].
1✔
269

1✔
270
        "add changes to the diff range"
1✔
271
        aDiff diffRanges do: [ :diffRange |
1✔
272
                self glhModel addAll: diffRange changes unless: [ :existing :new |
1✔
273
                        existing diffRange mooseID = new diffRange mooseID and: [
1✔
274
                                existing sourceCode = new sourceCode and: [
1✔
275
                                        existing index = new index ] ] ] ].
1✔
276

1✔
277
        ^ aDiff diffRanges
1✔
278
]
1✔
279

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

1✔
283
        ^ repoApi
1✔
284
]
1✔
285

286
{ #category : #accessing }
287
GitModelImporter >> repoApi: anObject [
1✔
288

1✔
289
        repoApi := anObject
1✔
290
]
1✔
291

292
{ #category : #accessing }
293
GitModelImporter >> userCatalogue [
1✔
294
        ^ userCatalogue 
1✔
295
]
1✔
296

297
{ #category : #accessing }
298
GitModelImporter >> userCatalogue: aGLHUserCatalogue [
×
299

×
300
        userCatalogue := aGLHUserCatalogue.
×
301
        aGLHUserCatalogue anImporter: self. 
×
302
]
×
303

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

1✔
307
        ^ withCommitDiffs
1✔
308
]
1✔
309

310
{ #category : #accessing }
311
GitModelImporter >> withCommitDiffs: anObject [
1✔
312

1✔
313
        withCommitDiffs := anObject
1✔
314
]
1✔
315

316
{ #category : #accessing }
317
GitModelImporter >> withCommitsSince [
×
318

×
319
        ^ withCommitsSince
×
320
]
×
321

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

1✔
326
        "(GitlabModelImporter new withCommitsSince: 1 week ) >>> (Date today - 1 week) asDateAndTime"
1✔
327

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

1✔
330
        (someDays isKindOf: DateAndTime)
1✔
331
                ifTrue: [ withCommitsSince := someDays ]
1✔
332
                ifFalse: [
1✔
333
                withCommitsSince := (DateAndTime today - someDays) ].
1✔
334
        ^ withCommitsSince
1✔
335
]
1✔
336

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

1✔
340
        ^ withFiles
1✔
341
]
1✔
342

343
{ #category : #accessing }
344
GitModelImporter >> withFiles: anObject [
1✔
345

1✔
346
        withFiles := anObject
1✔
347
]
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