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

moosetechnology / GitProjectHealth / 10075779876

24 Jul 2024 11:28AM UTC coverage: 31.874% (-0.4%) from 32.312%
10075779876

Pull #9

github

web-flow
Merge 3f514973e into 30d38cc2f
Pull Request #9: Refactoring/metrics interface

84 of 391 new or added lines in 10 files covered. (21.48%)

13 existing lines in 2 files now uncovered.

2526 of 7925 relevant lines covered (31.87%)

0.32 hits per line

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

24.76
/src/GitLabHealth-Model-Importer/GLHApi.class.st
1
"
2
This is the API. I do not perform any kinds of JSON transformation
3
"
4
Class {
5
        #name : #GLHApi,
6
        #superclass : #Object,
7
        #instVars : [
8
                'baseAPIUrl',
9
                'client'
10
        ],
11
        #classVars : [
12
                'currentAPI'
13
        ],
14
        #category : #'GitLabHealth-Model-Importer'
15
}
16

17
{ #category : #accessing }
NEW
18
GLHApi class >> current [
×
NEW
19

×
NEW
20
        ^ currentAPI
×
NEW
21
]
×
22

23
{ #category : #accessing }
24
GLHApi >> baseAPIUrl [
1✔
25

1✔
26
        ^ baseAPIUrl
1✔
27
]
1✔
28

29
{ #category : #accessing }
30
GLHApi >> baseAPIUrl: anObject [
1✔
31

1✔
32
        baseAPIUrl := anObject
1✔
33
]
1✔
34

35
{ #category : #'as yet unclassified' }
NEW
36
GLHApi >> blamesOfProject: aProjectId forFile: filePath onBranch: branchRef onStartRange: start toEndRange: end [
×
NEW
37

×
NEW
38
        self client path:
×
NEW
39
                self baseAPIUrl , '/projects/' , aProjectId printString
×
NEW
40
                , '/repository/files/' , filePath urlEncoded , '/blame'.
×
NEW
41

×
NEW
42
        branchRef ifNotNil: [ self client queryAt: #'ref' put: branchRef ].
×
NEW
43
        start ifNotNil: [ self client queryAt: #'range[start]' put: start ].
×
NEW
44
        end ifNotNil: [ self client queryAt: #'range[end]' put: end ].
×
NEW
45

×
NEW
46
        ^ self client get
×
NEW
47
]
×
48

49
{ #category : #'as yet unclassified' }
NEW
50
GLHApi >> blamesOfProject: aProjectId forFile: filePath onStartRange: start toEndRange: end [
×
NEW
51

×
NEW
52
        self client path:
×
NEW
53
                self baseAPIUrl , '/projects/' , aProjectId printString
×
NEW
54
                , '/repository/files/' , filePath urlEncoded, '/blame'.
×
NEW
55

×
NEW
56
        start ifNotNil: [ self client queryAt: #'range[start]' put: start ].
×
NEW
57
        end ifNotNil: [ self client queryAt: #'range[end]' put: end ].
×
NEW
58

×
NEW
59
        ^ self client get
×
NEW
60
]
×
61

62
{ #category : #api }
63
GLHApi >> branchesOfRepository: aProjectID [
1✔
64

1✔
65
        ^ self client get:
1✔
66
                  self baseAPIUrl , '/projects/' , aProjectID printString
1✔
67
                  , '/repository/branches'
1✔
68
]
1✔
69

70
{ #category : #accessing }
71
GLHApi >> client [
1✔
72

1✔
73
        ^ client
1✔
74
]
1✔
75

76
{ #category : #accessing }
77
GLHApi >> client: anObject [
1✔
78

1✔
79
        client := anObject
1✔
80
]
1✔
81

82
{ #category : #'api - commits' }
83
GLHApi >> commit: commitSHA ofProject: aProjectId [
1✔
84

1✔
85
        self client path: (String streamContents: [ :str |
1✔
86
                         str
1✔
87
                                 << self baseAPIUrl;
1✔
88
                                 << '/projects/';
1✔
89
                                 << aProjectId asString;
1✔
90
                                 << '/repository/commits/';
1✔
91
                                 << commitSHA asString;
1✔
92
                                 << '' ]).
1✔
93

1✔
94
        ^ self client get
1✔
95
]
1✔
96

97
{ #category : #'api - commits' }
98
GLHApi >> commit: commitSHA ofProject: aProjectId withStat: stats [
×
99

×
100
        self client path: (String streamContents: [ :str |
×
101
                         str
×
102
                                 << self baseAPIUrl;
×
103
                                 << '/projects/';
×
104
                                 << aProjectId asString;
×
105
                                 << '/repository/commits/';
×
106
                                 << commitSHA asString;
×
107
                                 << '' ]).
×
108
                        
×
109

×
110
        stats ifNotNil: [ self client queryAt: #stats put: stats ].
×
111

×
112
        ^ self client get
×
113
]
×
114

115
{ #category : #'api - commits' }
116
GLHApi >> commitDiff: commitSHA ofProject: aProjectId unidiff: unidiff [
1✔
117

1✔
118
        self client path: (String streamContents: [ :str |
1✔
119
                         str
1✔
120
                                 << self baseAPIUrl;
1✔
121
                                 << '/projects/';
1✔
122
                                 << aProjectId asString;
1✔
123
                                 << '/repository/commits/';
1✔
124
                                 << commitSHA asString;
1✔
125
                                 << '/diff' ]).
1✔
126

1✔
127
        unidiff ifNotNil: [ self client queryAt: #unidiff put: unidiff ].
1✔
128

1✔
129
        ('Call: ' , self client request url asString) recordInfo.
1✔
130

1✔
131
        ^ self client get
1✔
132
]
1✔
133

134
{ #category : #'api - commits' }
135
GLHApi >> commitsOfProject: aProjectId [
×
136

×
137
        ^ self
×
138
                  commitsOfProject: aProjectId
×
139
                  forRefName: nil
×
140
                  since: nil
×
141
                  until: nil
×
142
                  path: nil
×
143
                  author: nil
×
144
                  all: nil
×
145
                  with_stats: nil
×
146
                  firstParent: nil
×
147
                  order: nil
×
148
                  trailers: nil
×
149
                  perPage: nil
×
150
                  page: nil
×
151
]
×
152

153
{ #category : #commits }
154
GLHApi >> commitsOfProject: anInteger forRefName: refName since: since [ 
×
155

×
156
        ^ self commitsOfProject: anInteger
×
157
                  forRefName: refName
×
158
                  since: since
×
159
                  until: nil
×
160
                  path: nil
×
161
                  author: nil
×
162
                  all: nil
×
163
                  with_stats: nil
×
164
                  firstParent: nil
×
165
                  order: nil
×
166
                  trailers: nil
×
167
                  perPage: nil
×
168
                  page: nil.
×
169
]
×
170

171
{ #category : #'api - commits' }
172
GLHApi >> commitsOfProject: aProjectId forRefName: refName since: since until: until path: aPath author: author all: aAllBoolean with_stats: withStateBoolean firstParent: firstParent order: orderString trailers: trailers perPage: aPerPageNumber page: aPageNumber [
1✔
173
        "https://docs.gitlab.com/ee/api/commits.html#list-repository-commits"
1✔
174

1✔
175
        self client path:
1✔
176
                self baseAPIUrl , '/projects/' , aProjectId printString
1✔
177
                , '/repository/commits'.
1✔
178
        refName ifNotNil: [ self client queryAt: #ref_name put: refName ].
1✔
179
        since ifNotNil: [ self client queryAt: #since put: since ].
1✔
180
        until ifNotNil: [ self client queryAt: #until put: until ].
1✔
181
        aPath ifNotNil: [ self client queryAt: #path put: aPath ].
1✔
182
        author ifNotNil: [ self client queryAt: #author put: author ].
1✔
183
        aAllBoolean ifNotNil: [ self client queryAt: #all put: aAllBoolean ].
1✔
184
        withStateBoolean ifNotNil: [
1✔
185
                self client queryAt: #with_stats put: withStateBoolean ].
1✔
186
        firstParent ifNotNil: [
1✔
187
                self client queryAt: #first_parent put: firstParent ].
1✔
188
        orderString ifNotNil: [ self client queryAt: #order put: orderString ].
1✔
189
        trailers ifNotNil: [ self client queryAt: #trailers put: trailers ].
1✔
190
        aPerPageNumber ifNotNil: [
1✔
191
                self client queryAt: #per_page put: aPerPageNumber ].
1✔
192
        aPageNumber ifNotNil: [ self client queryAt: #page put: aPageNumber ].
1✔
193

1✔
194
        ^ self client get
1✔
195
]
1✔
196

197
{ #category : #commits }
198
GLHApi >> commitsOfUser: aUserName inProject: anInteger [
×
199

×
200
        | name |
×
201
        name := (aUserName splitOn: ' ') collect: [ :part | part urlEncoded ].
×
202
        name := ' ' join: name.
×
203

×
204
        ^ self
×
205
                  commitsOfProject: anInteger
×
206
                  forRefName: nil
×
207
                  since: nil
×
208
                  until: nil
×
209
                  path: nil
×
210
                  author: name
×
211
                  all: nil
×
212
                  with_stats: nil
×
213
                  firstParent: nil
×
214
                  order: nil
×
215
                  trailers: nil
×
216
                  perPage: 1
×
217
                  page: 1
×
218

×
219
        "client path: self baseAPIUrl, '/projects/',anInteger printString,'/repository/commits/'. 
×
220
        client queryAt: #author put: name. 
×
221
        ^ client get. "
×
222
]
×
223

224
{ #category : #commits }
225
GLHApi >> commitsOfUser: aUserName inProject: anInteger since: since until: until [
×
226

×
227
        | name |
×
228
        name := (aUserName splitOn: ' ') collect: [ :part | part urlEncoded ].
×
229
        name := ' ' join: name.
×
230

×
231
        ^ self
×
232
                  commitsOfProject: anInteger
×
233
                  forRefName: nil
×
234
                  since: since
×
235
                  until: until
×
236
                  path: nil
×
237
                  author: name
×
238
                  all: nil
×
239
                  with_stats: nil
×
240
                  firstParent: nil
×
241
                  order: nil
×
242
                  trailers: nil
×
243
                  perPage: 1
×
244
                  page: 1
×
245

×
246
        "client path: self baseAPIUrl, '/projects/',anInteger printString,'/repository/commits/'. 
×
247
        client queryAt: #author put: name. 
×
248
        ^ client get. "
×
249
]
×
250

251
{ #category : #'api - repositories' }
252
GLHApi >> compareProject: aProjectID from: fromSha to: toSha fromProject: fromProjectID straight: straight unidiff: unidiff [
×
253

×
254
        self client path:
×
255
                self baseAPIUrl , '/projects/' , aProjectID printString
×
256
                , '/repository/compare'.
×
257

×
258
        self client queryAt: #from put: fromSha.
×
259
        self client queryAt: #to put: toSha.
×
260

×
261
        fromProjectID ifNotNil: [
×
262
                self client queryAt: #from_project_id put: fromProjectID ].
×
263
        straight ifNotNil: [ self client queryAt: #straight put: straight ].
×
264
        unidiff ifNotNil: [ self client queryAt: #unidiff put: unidiff ].
×
265

×
266
        ^ self client get
×
267
]
×
268

269
{ #category : #'api - branches' }
270
GLHApi >> createBranch: newBranchName forProject: aProjectID fromBranch: refBranchName [
×
271

×
272
        self client url:
×
273
                self baseAPIUrl , '/projects/' , aProjectID printString
×
274
                , '/repository/branches'.
×
275
        self client queryAt: #ref put: refBranchName.
×
276
        self client queryAt: #branch put: newBranchName.
×
277
        ^ self client post
×
278
]
×
279

280
{ #category : #'api - branches' }
281
GLHApi >> deleteBranch: branchName forProject: aProjectID [
×
282

×
283
        self client url:
×
284
                self baseAPIUrl , '/projects/' , aProjectID printString
×
285
                , '/repository/branches/' , branchName.
×
286
        ^ self client delete
×
287
]
×
288

289
{ #category : #'api - projects' }
290
GLHApi >> editProject: aProjectID changeDefaultBranchTo: refBranchName [
×
291

×
292
        self client url:
×
293
                self baseAPIUrl , '/projects/' , aProjectID printString.
×
294
        self client queryAt: #default_branch put: refBranchName.
×
295
        ^ self client put
×
296
]
×
297

298
{ #category : #'api - projects' }
299
GLHApi >> editProject: aProjectID usingDictionary: aDictionaryOfNewParam [
×
300

×
301
        self client url:
×
302
                self baseAPIUrl , '/projects/' , aProjectID printString.
×
303
        aDictionaryOfNewParam keysAndValuesDo: [ :k :v | 
×
304
                self client queryAt: k put: v ].
×
305

×
306
        ^ self client put
×
307
]
×
308

309
{ #category : #'api - repository files' }
310
GLHApi >> getFileBlameForProject: aProjectId andFilePath: aFilePath inRef: aRef fromLine: rangeStart toLine: rangeEnd [
×
311
        "filePath is converted here. So give a path such as ""path/to/file.md"""
×
312

×
313
        "https://docs.gitlab.com/ee/api/repository_files.html#get-file-blame-from-repository"
×
314

×
315
        self client url:
×
316
                self baseAPIUrl , '/projects/' , aProjectId printString
×
317
                , '/repository/files/' , (aFilePath withoutPrefix: '/') urlEncoded
×
318
                , '/blame'.
×
319
        self client queryAt: #ref put: aRef.
×
320
        self client queryAt: #'range[start]' put: rangeStart.
×
321
        self client queryAt: #'range[end]' put: rangeEnd.
×
322

×
323
        ^ self client get
×
324
]
×
325

326
{ #category : #api }
327
GLHApi >> group: aGroupID [
1✔
328

1✔
329
        ^ self client get: self baseAPIUrl , '/groups/' , aGroupID printString
1✔
330
]
1✔
331

332
{ #category : #projects }
333
GLHApi >> importProjects: first after: after [ 
×
334
         | request query variables body response |
×
335

×
336
                
×
337

×
338
        query := 'query getAllProjects($first: Int!, $after: String) {
×
339
            projects(first: $first, after: $after) {
×
340
                pageInfo {
×
341
                    endCursor
×
342
                    hasNextPage
×
343
                }
×
344
                edges {
×
345
                    node {
×
346
                        id
×
347
                    }
×
348
                }
×
349
            }
×
350
        }'.
×
351

×
352
        variables := String streamContents: [ :stream |
×
353
            stream nextPutAll: '{'.
×
354
            stream
×
355
                nextPutAll: '"first": ', first printString, ',';
×
356
                nextPutAll: '"after": "', after, '"'.
×
357
            stream nextPutAll: '}'
×
358
        ].
×
359

×
360
        body := String streamContents: [ :stream |
×
361
            stream nextPutAll: '{'.
×
362
            stream
×
363
                nextPutAll: '"query": "', (' ' join: query lines) , '",';
×
364
                nextPutAll: '"variables": ', variables.
×
365
            stream nextPutAll: '}'
×
366
        ].
×
367

×
368
       response := client entity: (ZnEntity with: body); contentType: 'application/json'; 
×
369
            url: (self baseAPIUrl replaceSuffix: 'v4' with: 'graphql'); post.
×
370
        
×
371
        ^ response contents
×
372
]
×
373

374
{ #category : #initialization }
375
GLHApi >> initialize [
1✔
376

1✔
377
        self client: (ZnClient new
1✔
378
                         accept: ZnMimeType applicationJson;
1✔
379
                         yourself).
1✔
380
        currentAPI:= self
1✔
381
]
1✔
382

383
{ #category : #'api - jobs' }
384
GLHApi >> jobsOfProject: aProjectID ofPipelines: aPipelineID [
×
385

×
386
        ^ self client get:
×
387
                  self baseAPIUrl , '/projects/' , aProjectID printString
×
388
                  , '/pipelines/' , aPipelineID printString , '/jobs'
×
389
]
×
390

391
{ #category : #'api - groups' }
392
GLHApi >> listGroupsWithTopLevelOnly: topLevelOnly page: aPageNumber [
×
393
        "https://docs.gitlab.com/ee/api/groups.html#list-groups"
×
394

×
395
        self client url: self baseAPIUrl , '/groups'.
×
396
        topLevelOnly ifNotNil: [
×
397
                self client queryAt: #top_level_only put: topLevelOnly ].
×
398
        aPageNumber ifNotNil: [ self client queryAt: #page put: aPageNumber ].
×
399
        self client queryAt: #per_page put: 100.
×
400
        ^ self client get
×
401
]
×
402

403
{ #category : #api }
404
GLHApi >> pipelinesOfProject: aProjectID [
1✔
405
        ^ self client get: self baseAPIUrl , '/projects/' , aProjectID printString, '/pipelines'
1✔
406
]
1✔
407

408
{ #category : #accessing }
409
GLHApi >> privateToken [
×
410

×
411
        ^ self client request headers at: #'PRIVATE-TOKEN'
×
412
]
×
413

414
{ #category : #accessing }
415
GLHApi >> privateToken: anObject [
1✔
416

1✔
417
        self client headerAt: #'PRIVATE-TOKEN' add: anObject
1✔
418
]
1✔
419

420
{ #category : #accessing }
421
GLHApi >> projects [
×
422
        "use GraphQL"
×
423
        
×
424
         | projectIds after hasNextPage response data edges pageInfo jsonParser |
×
425

×
426
        projectIds := Set new.
×
427
        after := ''.
×
428
        hasNextPage := true.
×
429
       " jsonParser := NeoJSONArray readFromString: self class."
×
430

×
431
        [ hasNextPage ] whileTrue: [
×
432
        
×
433
            response := self importProjects: 10 after: after.
×
434
            data := NeoJSONReader fromString: response.
×
435
            edges := (data at: 'data') at: 'projects' at: 'edges'.
×
436
            pageInfo := (data at: 'data') at: 'projects' at: 'pageInfo'.
×
437

×
438
            edges do: [:edge | |id| 
×
439
                                                id := (edge at: 'node' at: 'id'). 
×
440
                                                 projectIds add: id ].
×
441

×
442
            after := pageInfo at: 'endCursor'.
×
443
            hasNextPage := pageInfo at: 'hasNextPage'.
×
444
        ].
×
445

×
446
        ^ projectIds
×
447
]
×
448

449
{ #category : #projects }
450
GLHApi >> projects: aPerPageNumber page: aPageNumber [
×
451

×
452
        self projects: aPerPageNumber since: nil  page:  aPageNumber
×
453
]
×
454

455
{ #category : #projects }
456
GLHApi >> projects: aPerPageNumber since: since page: aPageNumber [
×
457

×
458
        self client path: self baseAPIUrl , '/projects/'.
×
459

×
460
        aPerPageNumber ifNotNil: [
×
461
                self client queryAt: #per_page put: aPerPageNumber ].
×
462
        aPageNumber ifNotNil: [ self client queryAt: #page put: aPageNumber ].
×
463

×
464
        ^ self client get
×
465
]
×
466

467
{ #category : #private }
468
GLHApi >> resetClient [
×
469

×
470
        | token |
×
471
        token := self privateToken.
×
472
        self client initialize.
×
473
        self privateToken: token.
×
474
        self client accept: ZnMimeType applicationJson
×
475
]
×
476

477
{ #category : #'api - groups' }
478
GLHApi >> subgroupsOfGroup: aGroupID [
×
479

×
480
        ^ self client get:
×
481
                  self baseAPIUrl , '/groups/' , aGroupID printString , '/subgroups'
×
482
]
×
483

484
{ #category : #'api - groups' }
485
GLHApi >> subgroupsOfGroup: aGroupID page: aPageNumber [
1✔
486

1✔
487
        self client url:
1✔
488
                self baseAPIUrl , '/groups/' , aGroupID printString , '/subgroups'.
1✔
489
        aPageNumber ifNotNil: [ self client queryAt: #page put: aPageNumber ].
1✔
490
        ^ self client get
1✔
491
]
1✔
492

493
{ #category : #api }
494
GLHApi >> treeOfRepository: aProjectID ofBranch: aBranchRef andPath: aPath [
×
495

×
496
        | result |
×
497
        self client url:
×
498
                self baseAPIUrl , '/projects/' , aProjectID printString
×
499
                , '/repository/tree'.
×
500
        aBranchRef ifNotNil: [ self client queryAt: #ref put: aBranchRef ].
×
501
        aPath ifNotNil: [ self client queryAt: #path put: aPath ].
×
502
        result := self client get.
×
503
        self resetClient.
×
504
        ^ result
×
505
]
×
506

507
{ #category : #api }
508
GLHApi >> user: aUserID [
1✔
509

1✔
510
        ^ self client get: self baseAPIUrl , '/users/' , aUserID printString
1✔
511
]
1✔
512

513
{ #category : #api }
514
GLHApi >> userWithUsername: anUsername [
×
515

×
516
        ^ self client get: self baseAPIUrl , '/users?username=' , anUsername
×
517
]
×
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