the base
This commit is contained in:
4
examples/core/openapi/gitea/gitea_client/client.v
Normal file
4
examples/core/openapi/gitea/gitea_client/client.v
Normal file
@@ -0,0 +1,4 @@
|
||||
module gitea_client
|
||||
|
||||
struct GiteaClient {
|
||||
}
|
||||
83
examples/core/openapi/gitea/gitea_client/factory.v
Normal file
83
examples/core/openapi/gitea/gitea_client/factory.v
Normal file
@@ -0,0 +1,83 @@
|
||||
module dagu
|
||||
|
||||
// import os
|
||||
import freeflowuniverse.crystallib.clients.httpconnection
|
||||
import os
|
||||
|
||||
struct GiteaClient[T] {
|
||||
base.Base[T]
|
||||
mut:
|
||||
connection &httpconnection.HTTPConnection
|
||||
}
|
||||
|
||||
struct Config {
|
||||
play.ConfigBase[T]
|
||||
url string
|
||||
}
|
||||
|
||||
//
|
||||
pub fn get(args PlayArgs) GiteaClient[Config] {
|
||||
mut client := GiteaClient[Config]{}
|
||||
client.init(args)!
|
||||
return client
|
||||
}
|
||||
|
||||
//
|
||||
pub fn heroplay(args PlayBookAddArgs) ! {
|
||||
// make session for configuring from heroscript
|
||||
mut session := play.session_new(session_name: 'config')!
|
||||
session.playbook_add(path: args.path, text: args.text, git_url: args.git_url)!
|
||||
for mut action in session.plbook.find(filter: 'gitea_client.define')! {
|
||||
mut p := action.params
|
||||
instance := p.get_default('instance', 'default')!
|
||||
mut cl := get(instance: instance)!
|
||||
mut cfg := cl.config()!
|
||||
mut config := p.decode[T]()!
|
||||
cl.config_save()!
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
pub fn (self GiteaClient[T]) config_interactive() ! {
|
||||
mut myui := ui.new()!
|
||||
console.clear()
|
||||
println('
|
||||
## Configure B2 Client')
|
||||
println('========================
|
||||
|
||||
')
|
||||
|
||||
mut cfg := self.config()!
|
||||
|
||||
self.instance = myui.ask_question(
|
||||
question: 'name for B2 (backblaze) client'
|
||||
default: self.instance
|
||||
)!
|
||||
|
||||
cfg.description = myui.ask_question(
|
||||
question: 'description'
|
||||
minlen: 0
|
||||
default: cfg.description
|
||||
)!
|
||||
cfg.keyid = myui.ask_question(
|
||||
question: 'keyid e.g. 003e2a7be6357fb0000000001'
|
||||
minlen: 5
|
||||
default: cfg.keyid
|
||||
)!
|
||||
|
||||
cfg.appkey = myui.ask_question(
|
||||
question: 'appkey e.g. K008UsdrYOAou2ulBHA8p4KBe/dL2n4'
|
||||
minlen: 5
|
||||
default: cfg.appkey
|
||||
)!
|
||||
|
||||
buckets := self.list_buckets()!
|
||||
bucket_names := buckets.map(it.name)
|
||||
|
||||
cfg.bucketname = myui.ask_dropdown(
|
||||
question: 'choose default bucket name'
|
||||
items: bucket_names
|
||||
)!
|
||||
|
||||
self.config_save()!
|
||||
}
|
||||
69
examples/core/openapi/gitea/gitea_client/methods.v
Normal file
69
examples/core/openapi/gitea/gitea_client/methods.v
Normal file
@@ -0,0 +1,69 @@
|
||||
module gitea_client
|
||||
|
||||
import json
|
||||
import net.http
|
||||
|
||||
// Repository operations
|
||||
pub fn (mut client GiteaClient) create_repo(name string, description string, private bool) !string {
|
||||
data := {
|
||||
'name': name
|
||||
'description': description
|
||||
'private': private.str()
|
||||
}
|
||||
|
||||
resp := client.connection.post('/api/v1/user/repos', json.encode(data))!
|
||||
return resp
|
||||
}
|
||||
|
||||
pub fn (mut client GiteaClient) get_repo(owner string, repo string) !string {
|
||||
resp := client.connection.get('/api/v1/repos/${owner}/${repo}')!
|
||||
return resp
|
||||
}
|
||||
|
||||
pub fn (mut client GiteaClient) list_repos() !string {
|
||||
resp := client.connection.get('/api/v1/user/repos')!
|
||||
return resp
|
||||
}
|
||||
|
||||
// User operations
|
||||
pub fn (mut client GiteaClient) get_user() !string {
|
||||
resp := client.connection.get('/api/v1/user')!
|
||||
return resp
|
||||
}
|
||||
|
||||
pub fn (mut client GiteaClient) list_users() !string {
|
||||
resp := client.connection.get('/api/v1/admin/users')!
|
||||
return resp
|
||||
}
|
||||
|
||||
// Organization operations
|
||||
pub fn (mut client GiteaClient) create_org(name string, description string) !string {
|
||||
data := {
|
||||
'username': name
|
||||
'description': description
|
||||
}
|
||||
|
||||
resp := client.connection.post('/api/v1/orgs', json.encode(data))!
|
||||
return resp
|
||||
}
|
||||
|
||||
pub fn (mut client GiteaClient) list_orgs() !string {
|
||||
resp := client.connection.get('/api/v1/orgs')!
|
||||
return resp
|
||||
}
|
||||
|
||||
// Issue operations
|
||||
pub fn (mut client GiteaClient) create_issue(owner string, repo string, title string, body string) !string {
|
||||
data := {
|
||||
'title': title
|
||||
'body': body
|
||||
}
|
||||
|
||||
resp := client.connection.post('/api/v1/repos/${owner}/${repo}/issues', json.encode(data))!
|
||||
return resp
|
||||
}
|
||||
|
||||
pub fn (mut client GiteaClient) list_issues(owner string, repo string) !string {
|
||||
resp := client.connection.get('/api/v1/repos/${owner}/${repo}/issues')!
|
||||
return resp
|
||||
}
|
||||
1
examples/core/openapi/gitea/gitea_client/model.v
Normal file
1
examples/core/openapi/gitea/gitea_client/model.v
Normal file
@@ -0,0 +1 @@
|
||||
module gitea_client
|
||||
14
examples/core/openapi/gitea/gitea_openapi.vsh
Normal file
14
examples/core/openapi/gitea/gitea_openapi.vsh
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import os
|
||||
import json
|
||||
import freeflowuniverse.crystallib.core.openapi.gen
|
||||
|
||||
const spec_path = '${os.dir(@FILE)}/openapi.json'
|
||||
|
||||
mod := gen.generate_client_module(
|
||||
api_name: 'Gitea'
|
||||
)!
|
||||
mod.write_v('${os.dir(@FILE)}/gitea_client',
|
||||
overwrite: true
|
||||
)!
|
||||
Reference in New Issue
Block a user