...
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
|
||||
example how to
|
||||
|
||||
```v
|
||||
pub fn (mut self GiteaClient) list_classifiers() ![]Classifier {
|
||||
req := httpconnection.Request{
|
||||
method: .get
|
||||
prefix: 'v1/classifiers'
|
||||
}
|
||||
//fetch the http client
|
||||
mut httpclient := self.httpclient()!
|
||||
response := httpclient.get(req)!
|
||||
classifiers := json.decode([]Classifier, response)!
|
||||
return classifiers
|
||||
}
|
||||
|
||||
```
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
!!hero_code.generate_client
|
||||
name:'gitea_client'
|
||||
name:'giteaclient'
|
||||
classname:'GiteaClient'
|
||||
singleton:0
|
||||
default:1
|
||||
@@ -1,12 +1,12 @@
|
||||
module gitea_client
|
||||
module giteaclient
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook { PlayBook }
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
__global (
|
||||
gitea_client_global map[string]&GiteaClient
|
||||
gitea_client_default string
|
||||
giteaclient_global map[string]&GiteaClient
|
||||
giteaclient_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
@@ -31,19 +31,19 @@ pub fn get(args_ ArgsGet) !&GiteaClient {
|
||||
mut obj := GiteaClient{
|
||||
name: args.name
|
||||
}
|
||||
if args.name !in gitea_client_global {
|
||||
if args.name !in giteaclient_global {
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('gitea_client', args.name)!
|
||||
heroscript := context.hero_config_get('giteaclient', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return gitea_client_global[args.name] or {
|
||||
println(gitea_client_global)
|
||||
return giteaclient_global[args.name] or {
|
||||
println(giteaclient_global)
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for gitea_client with name, is bug:${args.name}')
|
||||
panic('could not get config for giteaclient with name, is bug:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,34 +52,34 @@ pub fn set(o GiteaClient) ! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('gitea_client', o.name, heroscript)!
|
||||
context.hero_config_set('giteaclient', o.name, heroscript)!
|
||||
}
|
||||
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
return context.hero_config_exists('gitea_client', args.name)
|
||||
return context.hero_config_exists('giteaclient', args.name)
|
||||
}
|
||||
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_delete('gitea_client', args.name)!
|
||||
if args.name in gitea_client_global {
|
||||
// del gitea_client_global[args.name]
|
||||
context.hero_config_delete('giteaclient', args.name)!
|
||||
if args.name in giteaclient_global {
|
||||
// del giteaclient_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o GiteaClient) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
gitea_client_global[o.name] = &o2
|
||||
gitea_client_default = o.name
|
||||
giteaclient_global[o.name] = &o2
|
||||
giteaclient_default = o.name
|
||||
}
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
mut install_actions := plbook.find(filter: 'gitea_client.configure')!
|
||||
mut install_actions := plbook.find(filter: 'giteaclient.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
@@ -89,9 +89,9 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
}
|
||||
|
||||
// switch instance to be used for gitea_client
|
||||
// switch instance to be used for giteaclient
|
||||
pub fn switch(name string) {
|
||||
gitea_client_default = name
|
||||
giteaclient_default = name
|
||||
}
|
||||
|
||||
// helpers
|
||||
@@ -1,5 +1,5 @@
|
||||
// File: lib/clients/gitea_client/gitea_client_model.v
|
||||
module gitea_client
|
||||
// File: lib/clients/giteaclient/giteaclient_model.v
|
||||
module giteaclient
|
||||
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
@@ -36,6 +36,24 @@ fn obj_init(mycfg_ GiteaClient) !GiteaClient {
|
||||
if mycfg.url == '' {
|
||||
return error('url needs to be filled in for ${mycfg.name}')
|
||||
}
|
||||
if mycfg.url.starts_with('https://') {
|
||||
mycfg.url = mycfg.url.replace('https://', '')
|
||||
}
|
||||
if mycfg.url.starts_with('http://') {
|
||||
mycfg.url = mycfg.url.replace('http://', '')
|
||||
}
|
||||
mycfg.url = mycfg.url.trim_right('/')
|
||||
if mycfg.url.ends_with('/api/v1') {
|
||||
mycfg.url = mycfg.url.replace('/api/v1', '')
|
||||
}
|
||||
if mycfg.url.ends_with('/api') {
|
||||
mycfg.url = mycfg.url.replace('/api', '')
|
||||
}
|
||||
mycfg.url = "https://${mycfg.url}/api/v1"
|
||||
|
||||
if mycfg.secret.len == 0 {
|
||||
return error('secret needs to be filled in for ${mycfg.name}')
|
||||
}
|
||||
return mycfg
|
||||
}
|
||||
|
||||
@@ -1,29 +1,25 @@
|
||||
// File: lib/clients/gitea_client/methods.v
|
||||
module gitea_client
|
||||
// File: lib/clients/giteaclient/methods.v
|
||||
module giteaclient
|
||||
|
||||
import freeflowuniverse.herolib.core.httpconnection
|
||||
import json
|
||||
import net.http
|
||||
|
||||
// NOTE: This file should contain the implementation for all API endpoints from the swagger spec.
|
||||
// Each public method on GiteaClient corresponds to an API call.
|
||||
|
||||
//
|
||||
// Repository Operations
|
||||
//
|
||||
|
||||
// List a user's own repositories
|
||||
pub fn (mut client GiteaClient) user_list_repos() ![]Repository {
|
||||
$dbg;
|
||||
req := httpconnection.Request{
|
||||
method: .get
|
||||
prefix: '/user/repos'
|
||||
}
|
||||
mut http_client := client.httpclient()!
|
||||
return http_client.get_json_list_generic[Repository](req)!
|
||||
r:=http_client.get_json_list_generic[Repository](req)!
|
||||
$dbg;
|
||||
return r
|
||||
}
|
||||
|
||||
// Get a repository
|
||||
pub fn (mut client GiteaClient) get_repo(owner string, repo string) !&Repository {
|
||||
pub fn (mut client GiteaClient) get_repo(owner string, repo string) !Repository {
|
||||
req := httpconnection.Request{
|
||||
method: .get
|
||||
prefix: '/repos/${owner}/${repo}'
|
||||
@@ -33,7 +29,7 @@ pub fn (mut client GiteaClient) get_repo(owner string, repo string) !&Repository
|
||||
}
|
||||
|
||||
// Create a repository for the authenticated user.
|
||||
pub fn (mut client GiteaClient) create_current_user_repo(args CreateRepoOption) !&Repository {
|
||||
pub fn (mut client GiteaClient) create_current_user_repo(args CreateRepoOption) !Repository {
|
||||
req := httpconnection.Request{
|
||||
method: .post
|
||||
prefix: '/user/repos'
|
||||
@@ -59,7 +55,7 @@ pub fn (mut client GiteaClient) list_repo_issues(owner string, repo string) ![]I
|
||||
}
|
||||
|
||||
// Get an issue
|
||||
pub fn (mut client GiteaClient) get_issue(owner string, repo string, index i64) !&Issue {
|
||||
pub fn (mut client GiteaClient) get_issue(owner string, repo string, index i64) !Issue {
|
||||
req := httpconnection.Request{
|
||||
method: .get
|
||||
prefix: '/repos/${owner}/${repo}/issues/${index}'
|
||||
@@ -69,7 +65,7 @@ pub fn (mut client GiteaClient) get_issue(owner string, repo string, index i64)
|
||||
}
|
||||
|
||||
// Create an issue
|
||||
pub fn (mut client GiteaClient) create_issue(owner string, repo string, args CreateIssueOption) !&Issue {
|
||||
pub fn (mut client GiteaClient) create_issue(owner string, repo string, args CreateIssueOption) !Issue {
|
||||
req := httpconnection.Request{
|
||||
method: .post
|
||||
prefix: '/repos/${owner}/${repo}/issues'
|
||||
@@ -85,7 +81,7 @@ pub fn (mut client GiteaClient) create_issue(owner string, repo string, args Cre
|
||||
//
|
||||
|
||||
// get_user gets a user by username
|
||||
pub fn (mut client GiteaClient) get_user(username string) !&User {
|
||||
pub fn (mut client GiteaClient) get_user(username string) !User {
|
||||
req := httpconnection.Request{
|
||||
method: .get
|
||||
prefix: '/users/${username}'
|
||||
@@ -95,7 +91,7 @@ pub fn (mut client GiteaClient) get_user(username string) !&User {
|
||||
}
|
||||
|
||||
// get_current_user gets the authenticated user
|
||||
pub fn (mut client GiteaClient) get_current_user() !&User {
|
||||
pub fn (mut client GiteaClient) get_current_user() !User {
|
||||
req := httpconnection.Request{
|
||||
method: .get
|
||||
prefix: '/user'
|
||||
@@ -1,4 +1,4 @@
|
||||
module gitea_client
|
||||
module giteaclient
|
||||
|
||||
import time
|
||||
|
||||
@@ -27,9 +27,9 @@ pub:
|
||||
|
||||
pub struct Activity {
|
||||
pub:
|
||||
act_user &User
|
||||
act_user User
|
||||
act_user_id i64
|
||||
comment &Comment
|
||||
comment Comment
|
||||
comment_id i64
|
||||
content string
|
||||
created time.Time
|
||||
@@ -37,7 +37,7 @@ pub:
|
||||
is_private bool
|
||||
op_type string
|
||||
ref_name string
|
||||
repo &Repository
|
||||
repo Repository
|
||||
repo_id i64
|
||||
user_id i64
|
||||
}
|
||||
@@ -64,12 +64,12 @@ pub:
|
||||
pub struct AnnotatedTag {
|
||||
pub:
|
||||
message string
|
||||
object &AnnotatedTagObject
|
||||
object AnnotatedTagObject
|
||||
sha string
|
||||
tag string
|
||||
tagger &CommitUser
|
||||
tagger CommitUser
|
||||
url string
|
||||
verification &PayloadCommitVerification
|
||||
verification PayloadCommitVerification
|
||||
}
|
||||
|
||||
pub struct Attachment {
|
||||
@@ -93,7 +93,7 @@ pub:
|
||||
|
||||
pub struct Branch {
|
||||
pub:
|
||||
commit &PayloadCommit
|
||||
commit PayloadCommit
|
||||
effective_branch_protection_name string
|
||||
enable_status_check bool
|
||||
name string
|
||||
@@ -145,10 +145,10 @@ pub:
|
||||
|
||||
pub struct ChangeFilesOptions {
|
||||
pub:
|
||||
author &Identity
|
||||
author Identity
|
||||
branch string
|
||||
committer &Identity
|
||||
dates &CommitDateOptions
|
||||
committer Identity
|
||||
dates CommitDateOptions
|
||||
files []ChangeFileOperation
|
||||
message string
|
||||
new_branch string
|
||||
@@ -170,15 +170,15 @@ pub:
|
||||
|
||||
pub struct Commit {
|
||||
pub:
|
||||
author &User
|
||||
commit &RepoCommit
|
||||
committer &User
|
||||
author User
|
||||
commit RepoCommit
|
||||
committer User
|
||||
created time.Time
|
||||
files []CommitAffectedFiles
|
||||
html_url string
|
||||
parents []CommitMeta
|
||||
sha string
|
||||
stats &CommitStats
|
||||
stats CommitStats
|
||||
url string
|
||||
}
|
||||
|
||||
@@ -215,11 +215,26 @@ pub:
|
||||
name string
|
||||
}
|
||||
|
||||
pub struct Comment {
|
||||
pub:
|
||||
assets []Attachment
|
||||
body string
|
||||
created_at time.Time
|
||||
html_url string
|
||||
id i64
|
||||
issue_url string
|
||||
original_author string
|
||||
original_author_id i64
|
||||
pull_request_url string
|
||||
updated_at time.Time
|
||||
user User
|
||||
}
|
||||
|
||||
pub struct CreateIssueOption {
|
||||
pub:
|
||||
title string
|
||||
assignee string
|
||||
assignees []string
|
||||
assignees []string
|
||||
body string
|
||||
closed bool
|
||||
due_date time.Time
|
||||
@@ -250,21 +265,28 @@ pub:
|
||||
name string
|
||||
}
|
||||
|
||||
pub struct InternalTracker {
|
||||
pub:
|
||||
allow_only_contributors_to_track_time bool
|
||||
enable_issue_dependencies bool
|
||||
enable_time_tracker bool
|
||||
}
|
||||
|
||||
pub struct Issue {
|
||||
pub:
|
||||
id i64
|
||||
url string
|
||||
html_url string
|
||||
number i64
|
||||
user &User
|
||||
user User
|
||||
original_author string
|
||||
original_author_id i64
|
||||
title string
|
||||
body string
|
||||
ref string
|
||||
labels []Label
|
||||
milestone &Milestone
|
||||
assignee &User
|
||||
milestone Milestone
|
||||
assignee User
|
||||
assignees []User
|
||||
state string // StateType
|
||||
is_locked bool
|
||||
@@ -273,8 +295,8 @@ pub:
|
||||
updated_at time.Time
|
||||
closed_at time.Time
|
||||
due_date time.Time
|
||||
pull_request &PullRequestMeta
|
||||
repository &RepositoryMeta
|
||||
pull_request PullRequestMeta
|
||||
repository RepositoryMeta
|
||||
assets []Attachment
|
||||
pin_order i64
|
||||
}
|
||||
@@ -304,16 +326,59 @@ pub:
|
||||
due_on time.Time
|
||||
}
|
||||
|
||||
pub struct Organization {
|
||||
pub:
|
||||
avatar_url string
|
||||
description string
|
||||
email string
|
||||
full_name string
|
||||
id i64
|
||||
location string
|
||||
name string
|
||||
repo_admin_change_team_access bool
|
||||
username string
|
||||
visibility string
|
||||
website string
|
||||
}
|
||||
|
||||
pub struct PayloadCommitVerification {
|
||||
pub:
|
||||
payload string
|
||||
reason string
|
||||
signature string
|
||||
signer &PayloadUser
|
||||
signer PayloadUser
|
||||
verified bool
|
||||
}
|
||||
|
||||
|
||||
pub struct PayloadCommit {
|
||||
pub:
|
||||
added []string
|
||||
author PayloadUser
|
||||
committer PayloadUser
|
||||
id string
|
||||
message string
|
||||
modified []string
|
||||
removed []string
|
||||
timestamp time.Time
|
||||
url string
|
||||
verification PayloadCommitVerification
|
||||
}
|
||||
|
||||
pub struct PayloadUser {
|
||||
pub:
|
||||
email string
|
||||
name string
|
||||
username string
|
||||
}
|
||||
|
||||
pub struct Permission {
|
||||
pub:
|
||||
admin bool
|
||||
pull bool
|
||||
push bool
|
||||
}
|
||||
|
||||
pub struct PullRequestMeta {
|
||||
pub:
|
||||
merged bool
|
||||
@@ -324,18 +389,18 @@ pub:
|
||||
|
||||
pub struct RepoCommit {
|
||||
pub:
|
||||
author &CommitUser
|
||||
committer &CommitUser
|
||||
author CommitUser
|
||||
committer CommitUser
|
||||
message string
|
||||
tree &CommitMeta
|
||||
tree CommitMeta
|
||||
url string
|
||||
verification &PayloadCommitVerification
|
||||
verification PayloadCommitVerification
|
||||
}
|
||||
|
||||
pub struct Repository {
|
||||
pub:
|
||||
id i64
|
||||
owner &User
|
||||
owner User
|
||||
name string
|
||||
full_name string
|
||||
description string
|
||||
@@ -343,7 +408,7 @@ pub:
|
||||
private bool
|
||||
fork bool
|
||||
template bool
|
||||
parent &Repository
|
||||
parent_id i64
|
||||
mirror bool
|
||||
size i64
|
||||
language string
|
||||
@@ -365,9 +430,9 @@ pub:
|
||||
created_at time.Time
|
||||
updated_at time.Time
|
||||
archived_at time.Time
|
||||
permissions &Permission
|
||||
permissions Permission
|
||||
has_issues bool
|
||||
internal_tracker &InternalTracker
|
||||
internal_tracker InternalTracker
|
||||
has_wiki bool
|
||||
has_pull_requests bool
|
||||
has_projects bool
|
||||
@@ -388,7 +453,7 @@ pub:
|
||||
internal bool
|
||||
mirror_interval string
|
||||
mirror_updated time.Time
|
||||
repo_transfer &RepoTransfer
|
||||
repo_transfer RepoTransfer
|
||||
}
|
||||
pub struct RepositoryMeta {
|
||||
pub:
|
||||
@@ -398,6 +463,26 @@ pub:
|
||||
full_name string
|
||||
}
|
||||
|
||||
pub struct Team {
|
||||
pub:
|
||||
can_create_org_repo bool
|
||||
description string
|
||||
id i64
|
||||
includes_all_repositories bool
|
||||
name string
|
||||
organization Organization
|
||||
permission string
|
||||
units []string
|
||||
units_map map[string]string
|
||||
}
|
||||
|
||||
pub struct RepoTransfer {
|
||||
pub:
|
||||
doer User
|
||||
recipient User
|
||||
teams []Team
|
||||
}
|
||||
|
||||
pub struct User {
|
||||
pub:
|
||||
id i64
|
||||
@@ -1,5 +1,5 @@
|
||||
// File: lib/clients/gitea_client/readme.md
|
||||
# gitea_client
|
||||
// File: lib/clients/giteaclient/readme.md
|
||||
# giteaclient
|
||||
|
||||
This library provides a client for interacting with the Gitea API.
|
||||
|
||||
@@ -8,7 +8,7 @@ This library provides a client for interacting with the Gitea API.
|
||||
You can configure the client using a HeroScript file:
|
||||
|
||||
```hero
|
||||
!!gitea_client.configure
|
||||
!!giteaclient.configure
|
||||
name: 'default' // optional, 'default' is the default instance name
|
||||
url: 'https://git.ourworld.tf'
|
||||
secret: 'your-gitea-api-token'
|
||||
@@ -21,7 +21,7 @@ Save this content in your project's configuration (e.g., `~/.config/hero/config.
|
||||
Here's how to get the client and use its methods.
|
||||
|
||||
```vlang
|
||||
import freeflowuniverse.herolib.clients.gitea_client
|
||||
import freeflowuniverse.herolib.clients.giteaclient
|
||||
import freeflowuniverse.herolib.core.base
|
||||
|
||||
fn main() ! {
|
||||
@@ -29,12 +29,12 @@ fn main() ! {
|
||||
base.init()!
|
||||
|
||||
// Example configuration (can also be loaded from file)
|
||||
heroscript_config := "!!gitea_client.configure url:'https://gitea.com' secret:'...your_token...'"
|
||||
heroscript_config := "!!giteaclient.configure url:'https://gitea.com' secret:'...your_token...'"
|
||||
mut plbook := playbook.new(text: heroscript_config)!
|
||||
gitea_client.play(mut plbook)!
|
||||
giteaclient.play(mut plbook)!
|
||||
|
||||
// Get the default configured client
|
||||
mut client := gitea_client.get()!
|
||||
mut client := giteaclient.get()!
|
||||
|
||||
// Get the authenticated user
|
||||
user := client.get_current_user()!
|
||||
@@ -57,3 +57,8 @@ fn main() ! {
|
||||
println(' #${issue.number}: ${issue.title}')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
## tips
|
||||
|
||||
- to see the admin api: https://git.ourworld.tf/api/swagger
|
||||
Reference in New Issue
Block a user