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

moosetechnology / GitProjectHealth / 14404766613

11 Apr 2025 01:54PM UTC coverage: 72.997% (+0.5%) from 72.511%
14404766613

Pull #186

github

web-flow
Merge pull request #191 from moosetechnology/badetitou-patch-1

autoreneraku v1.0.10
Pull Request #186: Develop

195 of 300 new or added lines in 9 files covered. (65.0%)

10 existing lines in 1 file now uncovered.

15693 of 21498 relevant lines covered (73.0%)

0.73 hits per line

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

76.71
/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 : #equality }
53
GitModelImporter >> blockForDiffEquality [
1✔
54
        ^ [ :existing :new |
1✔
55
                        existing diffString size = new diffString size and: [
1✔
56
                                existing diffString = new diffString ] ]
1✔
57
]
1✔
58

59
{ #category : #'as yet unclassified' }
60
GitModelImporter >> blockForDiffRangeEquality [
1✔
61

1✔
62
        ^ [ :existing :new |
1✔
63
          existing diff mooseID = new diff mooseID and: [
1✔
64
                  existing originalLineRange = new originalLineRange and: [
1✔
65
                          existing newLineRange = new newLineRange ] ] ]
1✔
66
]
1✔
67

68
{ #category : #equality }
69
GitModelImporter >> blockOnIdEquality [
1✔
70

1✔
71
        ^ [ :existing :new |
1✔
72
          existing id = new id ]
1✔
73
]
1✔
74

75
{ #category : #equality }
76
GitModelImporter >> blockOnNameEquality [
1✔
77

1✔
78
        ^ self blockEqualityOn: #name
1✔
79
]
1✔
80

81
{ #category : #commit }
82
GitModelImporter >> chainsCommitsFrom: commitsCollection [
1✔
83

1✔
84
        | dic |
1✔
85
        ('Chains ' , commitsCollection size printString , ' commits')
1✔
86
                recordInfo.
1✔
87

1✔
88
        dic := ((self glhModel allWithType: GLHCommit) collect: [ :commit |
1✔
89
                        commit id -> commit ]) asSet asDictionary.
1✔
90

1✔
91
        commitsCollection do: [ :commit |
1✔
92
                commit parent_ids do: [ :parentId |
1✔
93
                        dic
1✔
94
                                at: parentId
1✔
95
                                ifPresent: [ :parentCommit |
1✔
96
                                        parentCommit childCommits
1✔
97
                                                add: commit
1✔
98
                                                unless: [ :existing :new | existing id = new id ] ]
1✔
99
                                ifAbsent: [  ] ] ].
1✔
100
        ^ commitsCollection
1✔
101
]
1✔
102

103
{ #category : #commit }
104
GitModelImporter >> completeImportedCommit: aGLHCommit [ 
×
105
        
×
106
        
×
107
        ('completing commit: ' , aGLHCommit short_id printString) recordInfo.
×
108
        self importCreatorOfCommit: aGLHCommit.
×
109

×
110
        self withCommitDiffs ifTrue: [
×
111
                | diffs |
×
112
                aGLHCommit diffs ifEmpty: [
×
113
                        diffs := self importDiffOfCommit: aGLHCommit.
×
114
                        self glhModel addAll: diffs unless: self blockForDiffEquality ] ].
×
115

×
116
        ^ aGLHCommit
×
117
]
×
118

119
{ #category : #'as yet unclassified' }
120
GitModelImporter >> filterCommitChanges: aCollection [
1✔
121

1✔
122
        ^ aCollection reject: [ :line |
1✔
123
                  | trimmedLine |
1✔
124
                  trimmedLine := line trimLeft.
1✔
125
                  (trimmedLine beginsWith: '---') or: [
1✔
126
                          (trimmedLine beginsWith: '+++') or: [
1✔
127
                                  trimmedLine beginsWith: '\ No newline at end of file' ] ] ]
1✔
128
]
1✔
129

130
{ #category : #accessing }
131
GitModelImporter >> glhModel [
1✔
132

1✔
133
        ^ glhModel
1✔
134
]
1✔
135

136
{ #category : #accessing }
137
GitModelImporter >> glhModel: anObject [
1✔
138

1✔
139
        glhModel := anObject
1✔
140
]
1✔
141

142
{ #category : #import }
143
GitModelImporter >> importDiffRangesForDiff: aGLHDiff [
1✔
144

1✔
145
        | diffRanges |
1✔
146
        aGLHDiff diffRanges ifNotEmpty: [
1✔
147
                ('Diffs already imported for ' , aGLHDiff printString) recordInfo.
1✔
148
                ^ aGLHDiff diffRanges ].
1✔
149

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

1✔
153
        diffRanges := self glhModel
1✔
154
                              addAll: (self parseDiffString: aGLHDiff)
1✔
155
                              unless: self blockForDiffRangeEquality.
1✔
156
        ^ aGLHDiff diffRanges
1✔
157
                  addAll: diffRanges
1✔
158
                  unless: self blockForDiffRangeEquality
1✔
159
]
1✔
160

161
{ #category : #'import - groups' }
162
GitModelImporter >> importGroup: aGroupID [
163

164
        self subclassResponsibility
165
]
166

167
{ #category : #'import - notes' }
168
GitModelImporter >> importNotesfromMergeRequest: mergeRequest [
169

170
        self subclassResponsibility
171
]
172

173
{ #category : #'import - projects' }
174
GitModelImporter >> importProject: id [
175
        "id can be a string or an integer depending on the APi implementation"
176

177
        "return the project created or retrieved"
178

179
        ^ self subclassResponsibility
180
]
181

182
{ #category : #'import - projects' }
NEW
183
GitModelImporter >> importProjects: aCollectionOfProjectID [
×
NEW
184

×
NEW
185

×
NEW
186
        ^ aCollectionOfProjectID collect: [ :id | self importProject: id ]
×
NEW
187
]
×
188

189
{ #category : #initialization }
190
GitModelImporter >> initialize [
1✔
191

1✔
192
        super initialize.
1✔
193
        self withCommitsSince: (Date today - 1 week) asDateAndTime.
1✔
194
                userCatalogue := GLHUserCatalogueV2 new
1✔
195
                                 anImporter: self;
1✔
196
                                 yourself.
1✔
197
]
1✔
198

199
{ #category : #'as yet unclassified' }
200
GitModelImporter >> makeGlobal [
×
201
        ^ self makeGlobal: DateAndTime now printString.
×
202
]
×
203

204
{ #category : #'as yet unclassified' }
205
GitModelImporter >> makeGlobal: aLabel [ 
×
206

×
207
        currentImporter := GithubModelImporter importers ifNil: [ OrderedDictionary new ].
×
208
        currentImporter at: aLabel put: self. 
×
209
        ^ currentImporter 
×
210
]
×
211

212
{ #category : #parsing }
213
GitModelImporter >> parseDiffString: aDiff [
1✔
214
        "parse diff string to create entities for each lines"
1✔
215

1✔
216
        | lines range index firstChangeRange |
1✔
217
        lines := aDiff diffString lines.
1✔
218
        index := 0.
1✔
219
        range := nil.
1✔
220

1✔
221
        lines ifEmpty: [ ^ aDiff diffRanges ].
1✔
222
        lines := self filterCommitChanges: lines.
1✔
223
        lines ifEmpty: [ ^ aDiff diffRanges ].
1✔
224
        (lines first beginsWith: '@@') ifFalse: [ ^ aDiff diffRanges ].
1✔
225

1✔
226
        lines do: [ :line |
1✔
227
                | aChange |
1✔
228
                firstChangeRange := false.
1✔
229
                (line trim beginsWith: #'@@') ifTrue: [
1✔
230
                        range := GLHDiffRange newFrom: line.
1✔
231
                        firstChangeRange := true.
1✔
232
                        range := aDiff diffRanges add: range unless: [ :existing :new |
1✔
233
                                         existing originalLineRange = new originalLineRange and: [
1✔
234
                                                 existing newLineRange = new newLineRange ] ] ].
1✔
235

1✔
236
                self withCommitDiffs ifTrue: [
1✔
237
                        firstChangeRange ifFalse: [
1✔
238
                                aChange := GLHChange newFrom: line.
1✔
239
                                aChange relativeIndex: index.
1✔
240
                                aChange := range changes add: aChange unless: [ :existing :new |
1✔
241
                                                   existing sourceCode = new sourceCode and: [
1✔
242
                                                           existing index = new index ] ].
1✔
243
                                index := index + 1 ] ] ].
1✔
244

1✔
245
        "add changes to the diff range"
1✔
246
        aDiff diffRanges do: [ :diffRange |
1✔
247
                self glhModel addAll: diffRange changes unless: [ :existing :new |
1✔
248
                        existing diffRange mooseID = new diffRange mooseID and: [
1✔
249
                                existing sourceCode = new sourceCode and: [
1✔
250
                                        existing index = new index ] ] ] ].
1✔
251

1✔
252
        ^ aDiff diffRanges
1✔
253
]
1✔
254

255
{ #category : #accessing }
256
GitModelImporter >> repoApi [
1✔
257

1✔
258
        ^ repoApi
1✔
259
]
1✔
260

261
{ #category : #accessing }
262
GitModelImporter >> repoApi: anObject [
1✔
263

1✔
264
        repoApi := anObject
1✔
265
]
1✔
266

267
{ #category : #accessing }
268
GitModelImporter >> userCatalogue [
1✔
269
        ^ userCatalogue 
1✔
270
]
1✔
271

272
{ #category : #accessing }
273
GitModelImporter >> userCatalogue: aGLHUserCatalogue [
×
274

×
275
        userCatalogue := aGLHUserCatalogue.
×
276
        aGLHUserCatalogue anImporter: self. 
×
277
]
×
278

279
{ #category : #accessing }
280
GitModelImporter >> withCommitDiffs [
1✔
281

1✔
282
        ^ withCommitDiffs
1✔
283
]
1✔
284

285
{ #category : #accessing }
286
GitModelImporter >> withCommitDiffs: anObject [
1✔
287

1✔
288
        withCommitDiffs := anObject
1✔
289
]
1✔
290

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

×
294
        ^ withCommitsSince
×
295
]
×
296

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

1✔
301
        "(GitlabModelImporter new withCommitsSince: 1 week ) >>> (Date today - 1 week) asDateAndTime"
1✔
302

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

1✔
305
        (someDays isKindOf: DateAndTime)
1✔
306
                ifTrue: [ withCommitsSince := someDays ]
1✔
307
                ifFalse: [
1✔
308
                withCommitsSince := (DateAndTime today - someDays) ].
1✔
309
        ^ withCommitsSince
1✔
310
]
1✔
311

312
{ #category : #accessing }
313
GitModelImporter >> withFiles [
1✔
314

1✔
315
        ^ withFiles
1✔
316
]
1✔
317

318
{ #category : #accessing }
319
GitModelImporter >> withFiles: anObject [
1✔
320

1✔
321
        withFiles := anObject
1✔
322
]
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