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

moosetechnology / GitProjectHealth / 14222354556

02 Apr 2025 02:35PM UTC coverage: 72.557% (+0.2%) from 72.341%
14222354556

Pull #180

github

web-flow
Merge 0b4d70e17 into 9e642ecfa
Pull Request #180: add import projects to bitbucket

81 of 100 new or added lines in 4 files covered. (81.0%)

35 existing lines in 2 files now uncovered.

15464 of 21313 relevant lines covered (72.56%)

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 - projects' }
168
GitModelImporter >> importProject: id [
169
        "id can be a string or an integer depending on the APi implementation"
170

171
        "return the project created or retrieved"
172

173
        ^ self subclassResponsibility
174
]
175

176
{ #category : #'import - projects' }
NEW
177
GitModelImporter >> importProjects: aCollectionOfProjectID [
×
NEW
178

×
NEW
179

×
NEW
180
        ^ aCollectionOfProjectID collect: [ :id | self importProject: id ]
×
NEW
181
]
×
182

183
{ #category : #initialization }
184
GitModelImporter >> initialize [
1✔
185

1✔
186
        super initialize.
1✔
187
        self withCommitsSince: (Date today - 1 week) asDateAndTime.
1✔
188
                userCatalogue := GLHUserCatalogueV2 new
1✔
189
                                 anImporter: self;
1✔
190
                                 yourself.
1✔
191
]
1✔
192

193
{ #category : #'as yet unclassified' }
UNCOV
194
GitModelImporter >> makeGlobal [
×
UNCOV
195
        ^ self makeGlobal: DateAndTime now printString.
×
UNCOV
196
]
×
197

198
{ #category : #'as yet unclassified' }
UNCOV
199
GitModelImporter >> makeGlobal: aLabel [ 
×
200

×
201
        currentImporter := GithubModelImporter importers ifNil: [ OrderedDictionary new ].
×
202
        currentImporter at: aLabel put: self. 
×
UNCOV
203
        ^ currentImporter 
×
UNCOV
204
]
×
205

206
{ #category : #parsing }
207
GitModelImporter >> parseDiffString: aDiff [
1✔
208
        "parse diff string to create entities for each lines"
1✔
209

1✔
210
        | lines range index firstChangeRange |
1✔
211
        lines := aDiff diffString lines.
1✔
212
        index := 0.
1✔
213
        range := nil.
1✔
214

1✔
215
        lines ifEmpty: [ ^ aDiff diffRanges ].
1✔
216
        lines := self filterCommitChanges: lines.
1✔
217
        lines ifEmpty: [ ^ aDiff diffRanges ].
1✔
218
        (lines first beginsWith: '@@') ifFalse: [ ^ aDiff diffRanges ].
1✔
219

1✔
220
        lines do: [ :line |
1✔
221
                | aChange |
1✔
222
                firstChangeRange := false.
1✔
223
                (line trim beginsWith: #'@@') ifTrue: [
1✔
224
                        range := GLHDiffRange newFrom: line.
1✔
225
                        firstChangeRange := true.
1✔
226
                        range := aDiff diffRanges add: range unless: [ :existing :new |
1✔
227
                                         existing originalLineRange = new originalLineRange and: [
1✔
228
                                                 existing newLineRange = new newLineRange ] ] ].
1✔
229

1✔
230
                self withCommitDiffs ifTrue: [
1✔
231
                        firstChangeRange ifFalse: [
1✔
232
                                aChange := GLHChange newFrom: line.
1✔
233
                                aChange relativeIndex: index.
1✔
234
                                aChange := range changes add: aChange unless: [ :existing :new |
1✔
235
                                                   existing sourceCode = new sourceCode and: [
1✔
236
                                                           existing index = new index ] ].
1✔
237
                                index := index + 1 ] ] ].
1✔
238

1✔
239
        "add changes to the diff range"
1✔
240
        aDiff diffRanges do: [ :diffRange |
1✔
241
                self glhModel addAll: diffRange changes unless: [ :existing :new |
1✔
242
                        existing diffRange mooseID = new diffRange mooseID and: [
1✔
243
                                existing sourceCode = new sourceCode and: [
1✔
244
                                        existing index = new index ] ] ] ].
1✔
245

1✔
246
        ^ aDiff diffRanges
1✔
247
]
1✔
248

249
{ #category : #accessing }
250
GitModelImporter >> repoApi [
1✔
251

1✔
252
        ^ repoApi
1✔
253
]
1✔
254

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

1✔
258
        repoApi := anObject
1✔
259
]
1✔
260

261
{ #category : #accessing }
262
GitModelImporter >> userCatalogue [
1✔
263
        ^ userCatalogue 
1✔
264
]
1✔
265

266
{ #category : #accessing }
UNCOV
267
GitModelImporter >> userCatalogue: aGLHUserCatalogue [
×
UNCOV
268

×
UNCOV
269
        userCatalogue := aGLHUserCatalogue.
×
UNCOV
270
        aGLHUserCatalogue anImporter: self. 
×
UNCOV
271
]
×
272

273
{ #category : #accessing }
274
GitModelImporter >> withCommitDiffs [
1✔
275

1✔
276
        ^ withCommitDiffs
1✔
277
]
1✔
278

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

1✔
282
        withCommitDiffs := anObject
1✔
283
]
1✔
284

285
{ #category : #accessing }
UNCOV
286
GitModelImporter >> withCommitsSince [
×
UNCOV
287

×
UNCOV
288
        ^ withCommitsSince
×
UNCOV
289
]
×
290

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

1✔
295
        "(GitlabModelImporter new withCommitsSince: 1 week ) >>> (Date today - 1 week) asDateAndTime"
1✔
296

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

1✔
299
        (someDays isKindOf: DateAndTime)
1✔
300
                ifTrue: [ withCommitsSince := someDays ]
1✔
301
                ifFalse: [
1✔
302
                withCommitsSince := (DateAndTime today - someDays) ].
1✔
303
        ^ withCommitsSince
1✔
304
]
1✔
305

306
{ #category : #accessing }
307
GitModelImporter >> withFiles [
1✔
308

1✔
309
        ^ withFiles
1✔
310
]
1✔
311

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

1✔
315
        withFiles := anObject
1✔
316
]
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