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

moosetechnology / GitProjectHealth / 11232222252

08 Oct 2024 09:07AM UTC coverage: 56.272% (-2.7%) from 58.976%
11232222252

Pull #80

github

web-flow
Merge 8e34931c3 into 1b1a26437
Pull Request #80: Feature/commit import bit bucket

134 of 270 new or added lines in 6 files covered. (49.63%)

368 existing lines in 3 files now uncovered.

8609 of 15299 relevant lines covered (56.27%)

0.56 hits per line

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

69.23
/src/GitProjectHealth-Model-Importer/GPModelImporter.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 : #GPModelImporter,
9
        #superclass : #Object,
10
        #instVars : [
11
                'withCommitsSince',
12
                'withFiles',
13
                'glhModel',
14
                'userCatalogue',
15
                'repoApi'
16
        ],
17
        #classVars : [
18
                'currentImporter'
19
        ],
20
        #category : #'GitProjectHealth-Model-Importer'
21
}
22

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

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

33
{ #category : #accessing }
34
GPModelImporter >> beWithFiles [
×
35

×
36
        withFiles := true
×
37
]
×
38

39
{ #category : #accessing }
40
GPModelImporter >> beWithoutFiles [
×
41

×
42
        withFiles := false
×
43
]
×
44

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

51
{ #category : #equality }
52
GPModelImporter >> blockForDiffEquality [
1✔
53
        ^ [ :existing :new |
1✔
54
                        existing diffString size = new diffString size and: [
1✔
55
                                existing diffString = new diffString ] ]
1✔
56
]
1✔
57

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

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

67
{ #category : #equality }
68
GPModelImporter >> blockOnIdEquality [
1✔
69

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

74
{ #category : #equality }
75
GPModelImporter >> blockOnNameEquality [
1✔
76

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

80
{ #category : #commit }
81
GPModelImporter >> chainsCommitsFrom: commitsCollection [
×
82

×
83
        | dic |
×
84
        ('Chains ' , commitsCollection size printString , ' commits')
×
85
                recordInfo.
×
86

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

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

102
{ #category : #'as yet unclassified' }
103
GPModelImporter >> filterCommitChanges: aCollection [
1✔
104

1✔
105
        ^ aCollection reject: [ :line |
1✔
106
                  | trimmedLine |
1✔
107
                  trimmedLine := line trimLeft.
1✔
108
                  (trimmedLine beginsWith: '---') or: [
1✔
109
                          (trimmedLine beginsWith: '+++') or: [
1✔
110
                                  trimmedLine beginsWith: '\ No newline at end of file' ] ] ]
1✔
111
]
1✔
112

113
{ #category : #accessing }
114
GPModelImporter >> glhModel [
1✔
115

1✔
116
        ^ glhModel
1✔
117
]
1✔
118

119
{ #category : #accessing }
120
GPModelImporter >> glhModel: anObject [
1✔
121

1✔
122
        glhModel := anObject
1✔
123
]
1✔
124

125
{ #category : #import }
126
GPModelImporter >> importDiffRangesForDiff: aGLHDiff [
1✔
127

1✔
128
        | diffRanges |
1✔
129
        aGLHDiff diffRanges ifNotEmpty: [
1✔
130
                ('Diffs already imported for ' , aGLHDiff printString) recordInfo.
1✔
131
                ^ aGLHDiff diffRanges ].
1✔
132

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

1✔
136
        diffRanges := self glhModel
1✔
137
                              addAll: (self parseDiffString: aGLHDiff)
1✔
138
                              unless: self blockForDiffRangeEquality.
1✔
139
        ^ aGLHDiff diffRanges
1✔
140
                  addAll: diffRanges
1✔
141
                  unless: self blockForDiffRangeEquality
1✔
142
]
1✔
143

144
{ #category : #initialization }
145
GPModelImporter >> initialize [
1✔
146

1✔
147
        super initialize.
1✔
148
        self withCommitsSince: (Date today - 1 week) asDateAndTime.
1✔
149
                userCatalogue := GLHUserCatalogueV2 new
1✔
150
                                 anImporter: self;
1✔
151
                                 yourself.
1✔
152
]
1✔
153

154
{ #category : #'as yet unclassified' }
155
GPModelImporter >> makeGlobal [
×
156
        ^ self makeGlobal: DateAndTime now printString.
×
157
]
×
158

159
{ #category : #'as yet unclassified' }
160
GPModelImporter >> makeGlobal: aLabel [ 
×
161

×
162
        currentImporter := GHModelImporter importers ifNil: [ OrderedDictionary new ].
×
163
        currentImporter at: aLabel put: self. 
×
164
        ^ currentImporter 
×
165
]
×
166

167
{ #category : #parsing }
168
GPModelImporter >> parseDiffString: aDiff [
1✔
169
        "parse diff string to create entities for each lines"
1✔
170

1✔
171
        | lines range index firstChangeRange |
1✔
172
        lines := aDiff diffString lines.
1✔
173
        index := 0.
1✔
174
        range := nil.
1✔
175

1✔
176
        lines ifEmpty: [ ^ aDiff diffRanges ].
1✔
177
        lines := self filterCommitChanges: lines.
1✔
178
        (lines first beginsWith: '@@') ifFalse: [ ^ aDiff diffRanges ].
1✔
179

1✔
180
        lines do: [ :line |
1✔
181
                | aChange |
1✔
182
                firstChangeRange := false.
1✔
183
                (line trim beginsWith: #'@@') ifTrue: [
1✔
184
                        range := GLPHEDiffRange newFrom: line.
1✔
185
                        firstChangeRange := true.
1✔
186
                        range := aDiff diffRanges add: range unless: [ :existing :new |
1✔
187
                                         existing originalLineRange = new originalLineRange and: [
1✔
188
                                                 existing newLineRange = new newLineRange ] ] ].
1✔
189

1✔
190
                self withCommitDiffs ifTrue: [
1✔
191
                        firstChangeRange ifFalse: [
1✔
192
                                aChange := GLPHEChange newFrom: line.
1✔
193
                                aChange relativeIndex: index.
1✔
194
                                aChange := range changes add: aChange unless: [ :existing :new |
1✔
195
                                                   existing sourceCode = new sourceCode and: [
1✔
196
                                                           existing index = new index ] ].
1✔
197
                                index := index + 1 ] ] ].
1✔
198

1✔
199
        "add changes to the diff range"
1✔
200
        aDiff diffRanges do: [ :diffRange |
1✔
201
                self glhModel addAll: diffRange changes unless: [ :existing :new |
1✔
202
                        existing diffRange mooseID = new diffRange mooseID and: [
1✔
203
                                existing sourceCode = new sourceCode and: [
1✔
204
                                        existing index = new index ] ] ] ].
1✔
205

1✔
206
        ^ aDiff diffRanges
1✔
207
]
1✔
208

209
{ #category : #accessing }
210
GPModelImporter >> repoApi [
1✔
211

1✔
212
        ^ repoApi
1✔
213
]
1✔
214

215
{ #category : #accessing }
NEW
216
GPModelImporter >> repoApi: anObject [
×
NEW
217

×
NEW
218
        repoApi := anObject
×
NEW
219
]
×
220

221
{ #category : #accessing }
222
GPModelImporter >> userCatalogue [
1✔
223
        ^ userCatalogue 
1✔
224
]
1✔
225

226
{ #category : #accessing }
NEW
227
GPModelImporter >> userCatalogue: aGLHUserCatalogue [
×
NEW
228

×
NEW
229
        userCatalogue := aGLHUserCatalogue.
×
NEW
230
        aGLHUserCatalogue anImporter: self. 
×
NEW
231
]
×
232

233
{ #category : #accessing }
234
GPModelImporter >> withCommitsSince [
×
235

×
236
        ^ withCommitsSince
×
237
]
×
238

239
{ #category : #accessing }
240
GPModelImporter >> withCommitsSince: anObject [
1✔
241

1✔
242
        withCommitsSince := anObject
1✔
243
]
1✔
244

245
{ #category : #accessing }
246
GPModelImporter >> withFiles [
1✔
247

1✔
248
        ^ withFiles
1✔
249
]
1✔
250

251
{ #category : #accessing }
252
GPModelImporter >> withFiles: anObject [
1✔
253

1✔
254
        withFiles := anObject
1✔
255
]
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