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

moosetechnology / GitProjectHealth / 11517203313

25 Oct 2024 11:17AM UTC coverage: 58.26% (-0.06%) from 58.322%
11517203313

Pull #100

github

web-flow
Merge f1caec6bc into cf47b4a59
Pull Request #100: use repoApi: instead of several other api name

73 of 157 new or added lines in 10 files covered. (46.5%)

10 existing lines in 1 file now uncovered.

9437 of 16198 relevant lines covered (58.26%)

0.58 hits per line

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

22.83
/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 [
×
19

×
20
        ^ currentAPI
×
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 [
×
37

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

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

×
46
        ^ self client get
×
47
]
×
48

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

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

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

×
59
        ^ self client get
×
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' }
NEW
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' }
NEW
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 }
NEW
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 }
NEW
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 }
NEW
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' }
NEW
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 : #'as yet unclassified' }
NEW
270
GLHApi >> contributedProjectsOfUserId: anUserID orderBy: orderByAttribute simple: simpleBoolean sort: AscOrDesc perPage: perPageNumber page: pageIndex [ 
×
271
        
×
272
        self client path: self baseAPIUrl , '/users/', anUserID printString, '/contributed_projects'.
×
273

×
274
        orderByAttribute ifNotNil: [
×
275
                self client queryAt: #order_by put: orderByAttribute ].
×
276
        simpleBoolean ifNotNil: [ self client queryAt: #simple put: simpleBoolean ].
×
277
        AscOrDesc ifNotNil: [ self client queryAt: #sort put: AscOrDesc ].
×
278
        perPageNumber ifNotNil: [ self client queryAt: #per_page put: perPageNumber ].
×
279
        pageIndex ifNotNil: [ self client queryAt: #page put: pageIndex ].
×
280
        
×
281
        
×
282
        ^ self client get.
×
283
]
×
284

285
{ #category : #'api - branches' }
NEW
286
GLHApi >> createBranch: newBranchName forProject: aProjectID fromBranch: refBranchName [
×
287

×
288
        self client url:
×
289
                self baseAPIUrl , '/projects/' , aProjectID printString
×
290
                , '/repository/branches'.
×
291
        self client queryAt: #ref put: refBranchName.
×
292
        self client queryAt: #branch put: newBranchName.
×
293
        ^ self client post
×
294
]
×
295

296
{ #category : #'api - branches' }
NEW
297
GLHApi >> deleteBranch: branchName forProject: aProjectID [
×
298

×
299
        self client url:
×
300
                self baseAPIUrl , '/projects/' , aProjectID printString
×
301
                , '/repository/branches/' , branchName.
×
302
        ^ self client delete
×
303
]
×
304

305
{ #category : #'api - projects' }
NEW
306
GLHApi >> editProject: aProjectID changeDefaultBranchTo: refBranchName [
×
307

×
308
        self client url:
×
309
                self baseAPIUrl , '/projects/' , aProjectID printString.
×
310
        self client queryAt: #default_branch put: refBranchName.
×
311
        ^ self client put
×
312
]
×
313

314
{ #category : #'api - projects' }
NEW
315
GLHApi >> editProject: aProjectID usingDictionary: aDictionaryOfNewParam [
×
316

×
317
        self client url:
×
318
                self baseAPIUrl , '/projects/' , aProjectID printString.
×
319
        aDictionaryOfNewParam keysAndValuesDo: [ :k :v | 
×
320
                self client queryAt: k put: v ].
×
321

×
322
        ^ self client put
×
323
]
×
324

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

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

×
331
        self client url:
×
332
                self baseAPIUrl , '/projects/' , aProjectId printString
×
333
                , '/repository/files/' , (aFilePath withoutPrefix: '/') urlEncoded
×
334
                , '/blame'.
×
335
        self client queryAt: #ref put: aRef.
×
336
        self client queryAt: #'range[start]' put: rangeStart.
×
337
        self client queryAt: #'range[end]' put: rangeEnd.
×
338

×
339
        ^ self client get
×
340
]
×
341

342
{ #category : #api }
343
GLHApi >> group: aGroupID [
1✔
344

1✔
345
        ^ self client get: self baseAPIUrl , '/groups/' , aGroupID printString
1✔
346
]
1✔
347

348
{ #category : #projects }
NEW
349
GLHApi >> importProjects: first after: after [ 
×
350
         | request query variables body response |
×
351

×
352
                
×
353

×
354
        query := 'query getAllProjects($first: Int!, $after: String) {
×
355
            projects(first: $first, after: $after) {
×
356
                pageInfo {
×
357
                    endCursor
×
358
                    hasNextPage
×
359
                }
×
360
                edges {
×
361
                    node {
×
362
                        id
×
363
                    }
×
364
                }
×
365
            }
×
366
        }'.
×
367

×
368
        variables := String streamContents: [ :stream |
×
369
            stream nextPutAll: '{'.
×
370
            stream
×
371
                nextPutAll: '"first": ', first printString, ',';
×
372
                nextPutAll: '"after": "', after, '"'.
×
373
            stream nextPutAll: '}'
×
374
        ].
×
375

×
376
        body := String streamContents: [ :stream |
×
377
            stream nextPutAll: '{'.
×
378
            stream
×
379
                nextPutAll: '"query": "', (' ' join: query lines) , '",';
×
380
                nextPutAll: '"variables": ', variables.
×
381
            stream nextPutAll: '}'
×
382
        ].
×
383

×
384
       response := client entity: (ZnEntity with: body); contentType: 'application/json'; 
×
385
            url: (self baseAPIUrl replaceSuffix: 'v4' with: 'graphql'); post.
×
386
        
×
387
        ^ response contents
×
388
]
×
389

390
{ #category : #initialization }
391
GLHApi >> initialize [
1✔
392

1✔
393
        self client: (ZnClient new
1✔
394
                         accept: ZnMimeType applicationJson;
1✔
395
                         yourself).
1✔
396

1✔
397
]
1✔
398

399
{ #category : #'api - jobs' }
NEW
400
GLHApi >> jobsOfProject: aProjectID ofPipelines: aPipelineID [
×
401

×
402
        ^ self client get:
×
403
                  self baseAPIUrl , '/projects/' , aProjectID printString
×
404
                  , '/pipelines/' , aPipelineID printString , '/jobs'
×
405
]
×
406

407
{ #category : #'api - groups' }
NEW
408
GLHApi >> listGroupsWithTopLevelOnly: topLevelOnly page: aPageNumber [
×
409
        "https://docs.gitlab.com/ee/api/groups.html#list-groups"
×
410

×
411
        self client url: self baseAPIUrl , '/groups'.
×
412
        topLevelOnly ifNotNil: [
×
413
                self client queryAt: #top_level_only put: topLevelOnly ].
×
414
        aPageNumber ifNotNil: [ self client queryAt: #page put: aPageNumber ].
×
415
        self client queryAt: #per_page put: 100.
×
416
        ^ self client get
×
417
]
×
418

419
{ #category : #'as yet unclassified' }
NEW
420
GLHApi >> makeGlobal [ 
×
421
                currentAPI := self
×
422
]
×
423

424
{ #category : #api }
425
GLHApi >> pipelinesOfProject: aProjectID [
1✔
426
        ^ self client get: self baseAPIUrl , '/projects/' , aProjectID printString, '/pipelines'
1✔
427
]
1✔
428

429
{ #category : #accessing }
NEW
430
GLHApi >> privateToken [
×
431

×
432
        ^ self client request headers at: #'PRIVATE-TOKEN'
×
433
]
×
434

435
{ #category : #accessing }
436
GLHApi >> privateToken: anObject [
1✔
437

1✔
438
        self client headerAt: #'PRIVATE-TOKEN' add: anObject
1✔
439
]
1✔
440

441
{ #category : #accessing }
NEW
442
GLHApi >> projects [
×
443
        "use GraphQL"
×
444
        
×
445
         | projectIds after hasNextPage response data edges pageInfo jsonParser |
×
446

×
447
        projectIds := Set new.
×
448
        after := ''.
×
449
        hasNextPage := true.
×
450
       " jsonParser := NeoJSONArray readFromString: self class."
×
451

×
452
        [ hasNextPage ] whileTrue: [
×
453
        
×
454
            response := self importProjects: 10 after: after.
×
455
            data := NeoJSONReader fromString: response.
×
456
            edges := (data at: 'data') at: 'projects' at: 'edges'.
×
457
            pageInfo := (data at: 'data') at: 'projects' at: 'pageInfo'.
×
458

×
459
            edges do: [:edge | |id| 
×
460
                                                id := (edge at: 'node' at: 'id'). 
×
461
                                                 projectIds add: id ].
×
462

×
463
            after := pageInfo at: 'endCursor'.
×
464
            hasNextPage := pageInfo at: 'hasNextPage'.
×
465
        ].
×
466

×
467
        ^ projectIds
×
468
]
×
469

470
{ #category : #projects }
NEW
471
GLHApi >> projects: aPerPageNumber page: aPageNumber [
×
472

×
473
        self projects: aPerPageNumber since: nil page: aPageNumber
×
474
]
×
475

476
{ #category : #projects }
NEW
477
GLHApi >> projects: aPerPageNumber since: since page: aPageNumber [
×
478

×
479
        self client path: self baseAPIUrl , '/projects/'.
×
480

×
481
        aPerPageNumber ifNotNil: [
×
482
                self client queryAt: #per_page put: aPerPageNumber ].
×
483
        aPageNumber ifNotNil: [ self client queryAt: #page put: aPageNumber ].
×
484

×
485
        ^ self client get
×
486
]
×
487

488
{ #category : #private }
NEW
489
GLHApi >> resetClient [
×
490

×
491
        | token |
×
492
        token := self privateToken.
×
493
        self client initialize.
×
494
        self privateToken: token.
×
495
        self client accept: ZnMimeType applicationJson
×
496
]
×
497

498
{ #category : #'api - groups' }
NEW
499
GLHApi >> subgroupsOfGroup: aGroupID [
×
500

×
501
        ^ self client get:
×
502
                  self baseAPIUrl , '/groups/' , aGroupID printString , '/subgroups'
×
503
]
×
504

505
{ #category : #'api - groups' }
506
GLHApi >> subgroupsOfGroup: aGroupID page: aPageNumber [
1✔
507

1✔
508
        self client url:
1✔
509
                self baseAPIUrl , '/groups/' , aGroupID printString , '/subgroups'.
1✔
510
        aPageNumber ifNotNil: [ self client queryAt: #page put: aPageNumber ].
1✔
511
        ^ self client get
1✔
512
]
1✔
513

514
{ #category : #api }
NEW
515
GLHApi >> treeOfRepository: aProjectID ofBranch: aBranchRef andPath: aPath [
×
516

×
517
        | result |
×
518
        self client url:
×
519
                self baseAPIUrl , '/projects/' , aProjectID printString
×
520
                , '/repository/tree'.
×
521
        aBranchRef ifNotNil: [ self client queryAt: #ref put: aBranchRef ].
×
522
        aPath ifNotNil: [ self client queryAt: #path put: aPath ].
×
523
        result := self client get.
×
524
        self resetClient.
×
525
        ^ result
×
526
]
×
527

528
{ #category : #api }
529
GLHApi >> user: aUserID [
1✔
530

1✔
531
        ^ self client get: self baseAPIUrl , '/users/' , aUserID printString
1✔
532
]
1✔
533

534
{ #category : #api }
NEW
535
GLHApi >> userWithUsername: anUsername [
×
536

×
537
        ^ self client get: self baseAPIUrl , '/users?username=' , anUsername
×
538
]
×
539

540
{ #category : #'as yet unclassified' }
NEW
541
GLHApi >> usersHuman: humans active: active withoutProjectBots: withoutBot perPage: perPage page: page [
×
542

×
543
        self client path: self baseAPIUrl , '/users/'.
×
544

×
545
        withoutBot ifNotNil: [
×
546
                self client queryAt: #without_project_bots put: withoutBot ].
×
547
        active ifNotNil: [ self client queryAt: #active put: active ].
×
548
        humans ifNotNil: [ self client queryAt: #humans put: humans ].
×
549
        perPage ifNotNil: [ self client queryAt: #per_page put: perPage ].
×
550
        page ifNotNil: [ self client queryAt: #page put: page ].
×
551
        ^ self client get
×
552
]
×
553

554
{ #category : #user }
NEW
555
GLHApi >> usersPerPage: perPage page: page [
×
556

×
557
        self client path: self baseAPIUrl , '/users/'.
×
558
        perPage ifNotNil: [ self client queryAt: #per_page put: perPage ].
×
559
        page ifNotNil: [ self client queryAt: #page put: page ].
×
560
        ^ self client get
×
561
]
×
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