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

moosetechnology / GitProjectHealth / 14200534772

01 Apr 2025 04:06PM UTC coverage: 72.434% (+0.09%) from 72.341%
14200534772

Pull #180

github

web-flow
Merge c35407184 into 804573828
Pull Request #180: add import projects to bitbucket

78 of 83 new or added lines in 4 files covered. (93.98%)

28 existing lines in 2 files now uncovered.

15332 of 21167 relevant lines covered (72.43%)

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

165
        "return the project created or retrieved"
166

167
        ^ self subclassResponsibility
168
]
169

170
{ #category : #'import - projects' }
NEW
171
GitModelImporter >> importProjects: aCollectionOfProjectID [
×
NEW
172

×
NEW
173

×
NEW
174
        ^ aCollectionOfProjectID collect: [ :id | self importProject: id ]
×
NEW
175
]
×
176

177
{ #category : #initialization }
178
GitModelImporter >> initialize [
1✔
179

1✔
180
        super initialize.
1✔
181
        self withCommitsSince: (Date today - 1 week) asDateAndTime.
1✔
182
                userCatalogue := GLHUserCatalogueV2 new
1✔
183
                                 anImporter: self;
1✔
184
                                 yourself.
1✔
185
]
1✔
186

187
{ #category : #'as yet unclassified' }
188
GitModelImporter >> makeGlobal [
×
UNCOV
189
        ^ self makeGlobal: DateAndTime now printString.
×
UNCOV
190
]
×
191

192
{ #category : #'as yet unclassified' }
UNCOV
193
GitModelImporter >> makeGlobal: aLabel [ 
×
UNCOV
194

×
UNCOV
195
        currentImporter := GithubModelImporter importers ifNil: [ OrderedDictionary new ].
×
UNCOV
196
        currentImporter at: aLabel put: self. 
×
UNCOV
197
        ^ currentImporter 
×
UNCOV
198
]
×
199

200
{ #category : #parsing }
201
GitModelImporter >> parseDiffString: aDiff [
1✔
202
        "parse diff string to create entities for each lines"
1✔
203

1✔
204
        | lines range index firstChangeRange |
1✔
205
        lines := aDiff diffString lines.
1✔
206
        index := 0.
1✔
207
        range := nil.
1✔
208

1✔
209
        lines ifEmpty: [ ^ aDiff diffRanges ].
1✔
210
        lines := self filterCommitChanges: lines.
1✔
211
        lines ifEmpty: [ ^ aDiff diffRanges ].
1✔
212
        (lines first beginsWith: '@@') ifFalse: [ ^ aDiff diffRanges ].
1✔
213

1✔
214
        lines do: [ :line |
1✔
215
                | aChange |
1✔
216
                firstChangeRange := false.
1✔
217
                (line trim beginsWith: #'@@') ifTrue: [
1✔
218
                        range := GLHDiffRange newFrom: line.
1✔
219
                        firstChangeRange := true.
1✔
220
                        range := aDiff diffRanges add: range unless: [ :existing :new |
1✔
221
                                         existing originalLineRange = new originalLineRange and: [
1✔
222
                                                 existing newLineRange = new newLineRange ] ] ].
1✔
223

1✔
224
                self withCommitDiffs ifTrue: [
1✔
225
                        firstChangeRange ifFalse: [
1✔
226
                                aChange := GLHChange newFrom: line.
1✔
227
                                aChange relativeIndex: index.
1✔
228
                                aChange := range changes add: aChange unless: [ :existing :new |
1✔
229
                                                   existing sourceCode = new sourceCode and: [
1✔
230
                                                           existing index = new index ] ].
1✔
231
                                index := index + 1 ] ] ].
1✔
232

1✔
233
        "add changes to the diff range"
1✔
234
        aDiff diffRanges do: [ :diffRange |
1✔
235
                self glhModel addAll: diffRange changes unless: [ :existing :new |
1✔
236
                        existing diffRange mooseID = new diffRange mooseID and: [
1✔
237
                                existing sourceCode = new sourceCode and: [
1✔
238
                                        existing index = new index ] ] ] ].
1✔
239

1✔
240
        ^ aDiff diffRanges
1✔
241
]
1✔
242

243
{ #category : #accessing }
244
GitModelImporter >> repoApi [
1✔
245

1✔
246
        ^ repoApi
1✔
247
]
1✔
248

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

1✔
252
        repoApi := anObject
1✔
253
]
1✔
254

255
{ #category : #accessing }
256
GitModelImporter >> userCatalogue [
1✔
257
        ^ userCatalogue 
1✔
258
]
1✔
259

260
{ #category : #accessing }
UNCOV
261
GitModelImporter >> userCatalogue: aGLHUserCatalogue [
×
UNCOV
262

×
UNCOV
263
        userCatalogue := aGLHUserCatalogue.
×
UNCOV
264
        aGLHUserCatalogue anImporter: self. 
×
UNCOV
265
]
×
266

267
{ #category : #accessing }
268
GitModelImporter >> withCommitDiffs [
1✔
269

1✔
270
        ^ withCommitDiffs
1✔
271
]
1✔
272

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

1✔
276
        withCommitDiffs := anObject
1✔
277
]
1✔
278

279
{ #category : #accessing }
UNCOV
280
GitModelImporter >> withCommitsSince [
×
UNCOV
281

×
UNCOV
282
        ^ withCommitsSince
×
UNCOV
283
]
×
284

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

1✔
289
        "(GitlabModelImporter new withCommitsSince: 1 week ) >>> (Date today - 1 week) asDateAndTime"
1✔
290

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

1✔
293
        (someDays isKindOf: DateAndTime)
1✔
294
                ifTrue: [ withCommitsSince := someDays ]
1✔
295
                ifFalse: [
1✔
296
                withCommitsSince := (DateAndTime today - someDays) ].
1✔
297
        ^ withCommitsSince
1✔
298
]
1✔
299

300
{ #category : #accessing }
301
GitModelImporter >> withFiles [
1✔
302

1✔
303
        ^ withFiles
1✔
304
]
1✔
305

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

1✔
309
        withFiles := anObject
1✔
310
]
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