Skip to content

Commit a167313

Browse files
authored
Merge pull request #35 from grafana/34-gitlab-support
GitLab API support
2 parents 2212c26 + 3b00768 commit a167313

File tree

10 files changed

+212
-11
lines changed

10 files changed

+212
-11
lines changed

README.md

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ Check [k6 Extension Registry Concept](docs/registry.md) for information on desig
4141
- k6/x/faker
4242
categories:
4343
- data
44+
45+
- module: gitlab.com/szkiba/xk6-banner
46+
description: Print ASCII art banner from k6 test
47+
imports:
48+
- k6/x/banner
49+
categories:
50+
- misc
4451
```
4552
4653
<details>
@@ -70,7 +77,7 @@ Registry generated from the source above.
7077
"name": "xk6-dashboard",
7178
"owner": "grafana",
7279
"public": true,
73-
"stars": 323,
80+
"stars": 325,
7481
"topics": [
7582
"xk6",
7683
"xk6-official",
@@ -174,7 +181,7 @@ Registry generated from the source above.
174181
"name": "xk6-disruptor",
175182
"owner": "grafana",
176183
"public": true,
177-
"stars": 87,
184+
"stars": 88,
178185
"topics": [
179186
"chaos-engineering",
180187
"fault-injection",
@@ -244,6 +251,35 @@ Registry generated from the source above.
244251
},
245252
"tier": "community"
246253
},
254+
{
255+
"categories": [
256+
"misc"
257+
],
258+
"description": "Print ASCII art banner from k6 test",
259+
"imports": [
260+
"k6/x/banner"
261+
],
262+
"module": "gitlab.com/szkiba/xk6-banner",
263+
"products": [
264+
"oss"
265+
],
266+
"repo": {
267+
"description": "Print ASCII art banner from k6 test.",
268+
"homepage": "https://gitlab.com/szkiba/xk6-banner",
269+
"license": "MIT",
270+
"name": "xk6-banner",
271+
"owner": "szkiba",
272+
"public": true,
273+
"topics": [
274+
"xk6"
275+
],
276+
"url": "https://gitlab.com/szkiba/xk6-banner",
277+
"versions": [
278+
"v0.1.0"
279+
]
280+
},
281+
"tier": "community"
282+
},
247283
{
248284
"categories": [
249285
"misc"
@@ -261,7 +297,7 @@ Registry generated from the source above.
261297
"name": "k6",
262298
"owner": "grafana",
263299
"public": true,
264-
"stars": 24285,
300+
"stars": 24302,
265301
"topics": [
266302
"es6",
267303
"go",
@@ -441,15 +477,15 @@ Command line k6 extension registry generator.
441477
442478
The source of the extension registry contains only the most important properties of the extensions. The rest of the properties are collected by k6registry using the API of the extensions' git repository managers.
443479
444-
The source of the extension registry is read from the YAML format file specified as command line argument. If it is missing, the source is read from the standard input.
480+
The source of the extension registry is read from the YAML (or JSON) format file specified as command line argument. If it is missing, the source is read from the standard input.
445481
446482
Repository metadata is collected using the API of the extensions' git repository managers. Currently only the GitHub API is supported.
447483
448484
The output of the generation will be written to the standard output by default. The output can be saved to a file using the `-o/--out` flag.
449485

450486

451487
```
452-
k6registry [flags] [file]
488+
k6registry [flags] [source-file]
453489
```
454490
455491
### Flags

cmd/legacy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func legacyConvert(ctx context.Context) error {
3131

3232
content, _, _, err := client.Repositories.GetContents(
3333
ctx,
34-
"grafana",
34+
"szkiba",
3535
"k6-docs",
3636
"src/data/doc-extensions/extensions.json",
3737
nil,
@@ -248,6 +248,7 @@ var extOverrides = map[string]extOverride{ //nolint:gochecknoglobals
248248
"github.com/ydarias/xk6-nats": {},
249249
"go.k6.io/k6": {},
250250
"github.com/wosp-io/xk6-playwright": {module: "github.com/nicholasvuono/xk6-playwright"},
251+
"gitlab.com/szkiba/xk6-banner": {},
251252
}
252253

253254
var phrases = map[string]string{ //nolint:gochecknoglobals

cmd/load.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/Masterminds/semver"
1212
"github.com/google/go-github/v62/github"
1313
"github.com/grafana/k6registry"
14+
"github.com/xanzy/go-gitlab"
1415
"gopkg.in/yaml.v3"
1516
)
1617

@@ -102,6 +103,15 @@ func loadRepository(ctx context.Context, module string) (*k6registry.Repository,
102103
return repo, nil
103104
}
104105

106+
if strings.HasPrefix(module, glModulePrefix) {
107+
repo, err := loadGitLab(ctx, module)
108+
if err != nil {
109+
return nil, err
110+
}
111+
112+
return repo, nil
113+
}
114+
105115
return nil, fmt.Errorf("%w: %s", errUnsupportedModule, module)
106116
}
107117

@@ -170,8 +180,63 @@ func loadGitHub(ctx context.Context, module string) (*k6registry.Repository, err
170180
return repo, nil
171181
}
172182

183+
func loadGitLab(ctx context.Context, module string) (*k6registry.Repository, error) {
184+
client, err := gitlab.NewClient("")
185+
if err != nil {
186+
return nil, err
187+
}
188+
189+
pid := strings.TrimPrefix(module, glModulePrefix)
190+
191+
lic := true
192+
193+
proj, _, err := client.Projects.GetProject(pid, &gitlab.GetProjectOptions{License: &lic}, gitlab.WithContext(ctx))
194+
if err != nil {
195+
return nil, err
196+
}
197+
198+
repo := new(k6registry.Repository)
199+
200+
repo.Owner = proj.Namespace.FullPath
201+
repo.Name = proj.Name
202+
repo.Description = proj.Description
203+
repo.Stars = proj.StarCount
204+
repo.Archived = proj.Archived
205+
repo.Url = proj.WebURL
206+
repo.Homepage = proj.WebURL
207+
repo.Topics = proj.Topics
208+
repo.Public = len(proj.Visibility) == 0 || proj.Visibility == gitlab.PublicVisibility
209+
210+
if proj.License != nil {
211+
for key := range validLicenses {
212+
if strings.EqualFold(key, proj.License.Key) {
213+
repo.License = key
214+
}
215+
}
216+
}
217+
218+
rels, _, err := client.Releases.ListReleases(pid,
219+
&gitlab.ListReleasesOptions{
220+
ListOptions: gitlab.ListOptions{PerPage: 50},
221+
})
222+
if err != nil {
223+
return nil, err
224+
}
225+
226+
for _, rel := range rels {
227+
if _, err := semver.NewVersion(rel.TagName); err != nil {
228+
continue
229+
}
230+
231+
repo.Versions = append(repo.Versions, rel.TagName)
232+
}
233+
234+
return repo, nil
235+
}
236+
173237
const (
174238
ghModulePrefix = "github.com/"
239+
glModulePrefix = "gitlab.com/"
175240
k6Module = "go.k6.io/k6"
176241
k6Description = "A modern load testing tool, using Go and JavaScript"
177242
)

docs/example.json

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"name": "xk6-dashboard",
2020
"owner": "grafana",
2121
"public": true,
22-
"stars": 323,
22+
"stars": 325,
2323
"topics": [
2424
"xk6",
2525
"xk6-official",
@@ -123,7 +123,7 @@
123123
"name": "xk6-disruptor",
124124
"owner": "grafana",
125125
"public": true,
126-
"stars": 87,
126+
"stars": 88,
127127
"topics": [
128128
"chaos-engineering",
129129
"fault-injection",
@@ -193,6 +193,35 @@
193193
},
194194
"tier": "community"
195195
},
196+
{
197+
"categories": [
198+
"misc"
199+
],
200+
"description": "Print ASCII art banner from k6 test",
201+
"imports": [
202+
"k6/x/banner"
203+
],
204+
"module": "gitlab.com/szkiba/xk6-banner",
205+
"products": [
206+
"oss"
207+
],
208+
"repo": {
209+
"description": "Print ASCII art banner from k6 test.",
210+
"homepage": "https://gitlab.com/szkiba/xk6-banner",
211+
"license": "MIT",
212+
"name": "xk6-banner",
213+
"owner": "szkiba",
214+
"public": true,
215+
"topics": [
216+
"xk6"
217+
],
218+
"url": "https://gitlab.com/szkiba/xk6-banner",
219+
"versions": [
220+
"v0.1.0"
221+
]
222+
},
223+
"tier": "community"
224+
},
196225
{
197226
"categories": [
198227
"misc"
@@ -210,7 +239,7 @@
210239
"name": "k6",
211240
"owner": "grafana",
212241
"public": true,
213-
"stars": 24285,
242+
"stars": 24302,
214243
"topics": [
215244
"es6",
216245
"go",

docs/example.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,10 @@
3030
- k6/x/faker
3131
categories:
3232
- data
33+
34+
- module: gitlab.com/szkiba/xk6-banner
35+
description: Print ASCII art banner from k6 test
36+
imports:
37+
- k6/x/banner
38+
categories:
39+
- misc

docs/legacy.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,9 @@
402402
categories:
403403
- messaging
404404
- protocol
405+
- module: gitlab.com/szkiba/xk6-banner
406+
description: Print ASCII art banner from k6 test
407+
imports:
408+
- k6/x/banner
409+
categories:
410+
- misc

docs/registry.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ If the property is missing or empty in the source of the registry, it means that
101101
- k6/x/faker
102102
categories:
103103
- data
104+
105+
- module: gitlab.com/szkiba/xk6-banner
106+
description: Print ASCII art banner from k6 test
107+
imports:
108+
- k6/x/banner
109+
categories:
110+
- misc
104111
```
105112
106113
### Categories

go.mod

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/google/go-github/v62 v62.0.0
99
github.com/grafana/clireadme v0.1.0
1010
github.com/spf13/cobra v1.8.1
11+
github.com/xanzy/go-gitlab v0.107.0
1112
github.com/xeipuuv/gojsonschema v1.2.0
1213
golang.org/x/term v0.23.0
1314
gopkg.in/yaml.v3 v3.0.1
@@ -17,7 +18,10 @@ require (
1718
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
1819
github.com/cli/safeexec v1.0.0 // indirect
1920
github.com/cli/shurcooL-graphql v0.0.4 // indirect
21+
github.com/golang/protobuf v1.5.3 // indirect
2022
github.com/google/go-querystring v1.1.0 // indirect
23+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
24+
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
2125
github.com/henvic/httpretty v0.0.6 // indirect
2226
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2327
github.com/kr/text v0.2.0 // indirect
@@ -30,6 +34,11 @@ require (
3034
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e // indirect
3135
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
3236
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
37+
golang.org/x/net v0.17.0 // indirect
38+
golang.org/x/oauth2 v0.6.0 // indirect
3339
golang.org/x/sys v0.23.0 // indirect
3440
golang.org/x/text v0.13.0 // indirect
41+
golang.org/x/time v0.3.0 // indirect
42+
google.golang.org/appengine v1.6.7 // indirect
43+
google.golang.org/protobuf v1.29.1 // indirect
3544
)

0 commit comments

Comments
 (0)