...
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
module gitresolver
|
||||
|
||||
// GitUrlResolver interface defines the contract for resolving git URLs to local paths
|
||||
pub interface GitUrlResolver {
|
||||
// get_repo_path resolves a git URL to a local repository path
|
||||
// and optionally pulls/resets the repository
|
||||
get_repo_path(url string, pull bool, reset bool) !string
|
||||
}
|
||||
|
||||
// Global registry for git URL resolver implementation
|
||||
__global (
|
||||
git_resolver ?GitUrlResolver
|
||||
)
|
||||
|
||||
// register_resolver sets the global git URL resolver implementation
|
||||
pub fn register_resolver(resolver GitUrlResolver) {
|
||||
git_resolver = resolver
|
||||
}
|
||||
|
||||
// get_resolver returns the registered git URL resolver
|
||||
pub fn get_resolver() !GitUrlResolver {
|
||||
if resolver := git_resolver {
|
||||
return resolver
|
||||
} else {
|
||||
return error('No git URL resolver has been registered. Make sure to import and initialize the gittools module.')
|
||||
}
|
||||
}
|
||||
|
||||
// resolve_git_url is a convenience function that uses the registered resolver
|
||||
pub fn resolve_git_url(url string, pull bool, reset bool) !string {
|
||||
resolver := get_resolver()!
|
||||
return resolver.get_repo_path(url, pull, reset)
|
||||
}
|
||||
@@ -3,7 +3,6 @@ module playbook
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.core.gitresolver
|
||||
// import freeflowuniverse.herolib.core.base
|
||||
// import freeflowuniverse.herolib.ui.console
|
||||
|
||||
|
||||
@@ -1,54 +1,213 @@
|
||||
module playcmds
|
||||
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.core.playbook { PlayBook }
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
pub fn play_git(mut plbook playbook.PlayBook) ! {
|
||||
for action in plbook.find(filter: 'gittools.*')! {
|
||||
play_git_action(action)!
|
||||
}
|
||||
@[params]
|
||||
pub struct PlayArgs {
|
||||
pub mut:
|
||||
heroscript string
|
||||
heroscript_path string
|
||||
plbook ?PlayBook
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn play_git_action(action playbook.Action) !playbook.Action {
|
||||
// console.print_debug("play git action: ${action}")
|
||||
pub fn play(args_ PlayArgs) ! {
|
||||
mut args := args_
|
||||
mut plbook := args.plbook or {
|
||||
playbook.new(text: args.heroscript, path: args.heroscript_path)!
|
||||
}
|
||||
|
||||
// Handle !!git.define action first to configure GitStructure
|
||||
define_actions := plbook.find(filter: 'git.define')!
|
||||
mut gs := if define_actions.len > 0 {
|
||||
mut p := define_actions[0].params
|
||||
coderoot := p.get_default('coderoot', '')!
|
||||
light := p.get_default_true('light')
|
||||
log := p.get_default_true('log')
|
||||
debug := p.get_default_false('debug')
|
||||
offline := p.get_default_false('offline')
|
||||
ssh_key_path := p.get_default('ssh_key_path', '')!
|
||||
reload := p.get_default_false('reload')
|
||||
|
||||
new(
|
||||
coderoot: coderoot
|
||||
light: light
|
||||
log: log
|
||||
debug: debug
|
||||
offline: offline
|
||||
ssh_key_path: ssh_key_path
|
||||
reload: reload
|
||||
)!
|
||||
} else {
|
||||
// Initialize GitStructure with defaults
|
||||
new()!
|
||||
}
|
||||
|
||||
// Handle !!git.clone action
|
||||
clone_actions := plbook.find(filter: 'git.clone')!
|
||||
for action in clone_actions {
|
||||
mut p := action.params
|
||||
mut repo := p.get_default('repo', '')!
|
||||
mut account := p.get_default('account', '')!
|
||||
mut provider := p.get_default('provider', '')!
|
||||
// mut filter := p.get_default('filter', '')!
|
||||
mut url := p.get_default('url', '')!
|
||||
url := p.get('url')!
|
||||
coderoot := p.get_default('coderoot', '')!
|
||||
sshkey := p.get_default('sshkey', '')!
|
||||
light := p.get_default_true('light')
|
||||
recursive := p.get_default_false('recursive')
|
||||
|
||||
mut cmd := action.name
|
||||
|
||||
mut coderoot := ''
|
||||
if p.exists('coderoot') {
|
||||
coderoot = p.get_path_create('coderoot')!
|
||||
mut clone_args := GitCloneArgs{
|
||||
url: url
|
||||
sshkey: sshkey
|
||||
recursive: recursive
|
||||
light: light
|
||||
}
|
||||
if coderoot.len > 0 {
|
||||
gs = new(coderoot: coderoot)!
|
||||
}
|
||||
gs.clone(clone_args)!
|
||||
}
|
||||
|
||||
if (repo == '' || account == '' || provider == '') && url == '' {
|
||||
return error('need to specify repo, account and provider if url is not specified')
|
||||
}
|
||||
// Handle !!git.repo_action
|
||||
repo_actions := plbook.find(filter: 'git.repo_action')!
|
||||
for action in repo_actions {
|
||||
mut p := action.params
|
||||
filter_str := p.get_default('filter', '')!
|
||||
name := p.get_default('name', '')!
|
||||
account := p.get_default('account', '')!
|
||||
provider := p.get_default('provider', '')!
|
||||
action_type := p.get('action')!
|
||||
message := p.get_default('message', '')!
|
||||
branchname := p.get_default('branchname', '')!
|
||||
tagname := p.get_default('tagname', '')!
|
||||
submodules := p.get_default_false('submodules')
|
||||
error_ignore := p.get_default_false('error_ignore')
|
||||
|
||||
mut gs := gittools.get(coderoot: coderoot) or {
|
||||
return error("Could not load gittools on '${coderoot}'\n${err}")
|
||||
}
|
||||
|
||||
gitpath := gs.do(
|
||||
cmd: cmd
|
||||
filter: action.params.get_default('filter', '')!
|
||||
repo: repo
|
||||
mut repos := gs.get_repos(
|
||||
filter: filter_str
|
||||
name: name
|
||||
account: account
|
||||
provider: provider
|
||||
script: action.params.get_default_false('script')
|
||||
reset: action.params.get_default_false('reset')
|
||||
pull: action.params.get_default_false('pull')
|
||||
msg: action.params.get_default('message', '')!
|
||||
url: url
|
||||
)!
|
||||
console.print_debug('play git action: ${cmd} ${account}:${repo} path:${gitpath}')
|
||||
mut action2 := action
|
||||
action2.params.set('path', gitpath)
|
||||
action2.done = true
|
||||
return action2
|
||||
|
||||
if repos.len == 0 {
|
||||
if !error_ignore {
|
||||
return error('No repositories found for git.repo_action with filter: ${filter_str}, name: ${name}, account: ${account}, provider: ${provider}')
|
||||
}
|
||||
console.print_stderr('No repositories found for git.repo_action with filter: ${filter_str}, name: ${name}, account: ${account}, provider: ${provider}. Ignoring due to error_ignore: true.')
|
||||
continue
|
||||
}
|
||||
|
||||
for mut repo in repos {
|
||||
match action_type {
|
||||
'pull' {
|
||||
repo.pull(submodules: submodules) or {
|
||||
if !error_ignore {
|
||||
return error('Failed to pull repo ${repo.name}: ${err}')
|
||||
}
|
||||
console.print_stderr('Failed to pull repo ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
'commit' {
|
||||
repo.commit(message) or {
|
||||
if !error_ignore {
|
||||
return error('Failed to commit repo ${repo.name}: ${err}')
|
||||
}
|
||||
console.print_stderr('Failed to commit repo ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
'push' {
|
||||
repo.push() or {
|
||||
if !error_ignore {
|
||||
return error('Failed to push repo ${repo.name}: ${err}')
|
||||
}
|
||||
console.print_stderr('Failed to push repo ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
'reset' {
|
||||
repo.reset() or {
|
||||
if !error_ignore {
|
||||
return error('Failed to reset repo ${repo.name}: ${err}')
|
||||
}
|
||||
console.print_stderr('Failed to reset repo ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
'branch_create' {
|
||||
repo.branch_create(branchname) or {
|
||||
if !error_ignore {
|
||||
return error('Failed to create branch ${branchname} in repo ${repo.name}: ${err}')
|
||||
}
|
||||
console.print_stderr('Failed to create branch ${branchname} in repo ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
'branch_switch' {
|
||||
repo.branch_switch(branchname) or {
|
||||
if !error_ignore {
|
||||
return error('Failed to switch branch to ${branchname} in repo ${repo.name}: ${err}')
|
||||
}
|
||||
console.print_stderr('Failed to switch branch to ${branchname} in repo ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
'tag_create' {
|
||||
repo.tag_create(tagname) or {
|
||||
if !error_ignore {
|
||||
return error('Failed to create tag ${tagname} in repo ${repo.name}: ${err}')
|
||||
}
|
||||
console.print_stderr('Failed to create tag ${tagname} in repo ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
'tag_switch' {
|
||||
repo.tag_switch(tagname) or {
|
||||
if !error_ignore {
|
||||
return error('Failed to switch tag to ${tagname} in repo ${repo.name}: ${err}')
|
||||
}
|
||||
console.print_stderr('Failed to switch tag to ${tagname} in repo ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
'delete' {
|
||||
repo.delete() or {
|
||||
if !error_ignore {
|
||||
return error('Failed to delete repo ${repo.name}: ${err}')
|
||||
}
|
||||
console.print_stderr('Failed to delete repo ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
else {
|
||||
if !error_ignore {
|
||||
return error('Unknown git.repo_action: ${action_type}')
|
||||
}
|
||||
console.print_stderr('Unknown git.repo_action: ${action_type}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle !!git.list
|
||||
list_actions := plbook.find(filter: 'git.list')!
|
||||
for action in list_actions {
|
||||
mut p := action.params
|
||||
filter_str := p.get_default('filter', '')!
|
||||
name := p.get_default('name', '')!
|
||||
account := p.get_default('account', '')!
|
||||
provider := p.get_default('provider', '')!
|
||||
status_update := p.get_default_false('status_update')
|
||||
|
||||
gs.repos_print(
|
||||
filter: filter_str
|
||||
name: name
|
||||
account: account
|
||||
provider: provider
|
||||
status_update: status_update
|
||||
)!
|
||||
}
|
||||
|
||||
// Handle !!git.reload_cache
|
||||
reload_cache_actions := plbook.find(filter: 'git.reload_cache')!
|
||||
for action in reload_cache_actions {
|
||||
mut p := action.params
|
||||
coderoot := p.get_default('coderoot', '')!
|
||||
if coderoot.len > 0 {
|
||||
gs = new(coderoot: coderoot)!
|
||||
}
|
||||
gs.load(true)! // Force reload
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ module gittools
|
||||
import os
|
||||
import json
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.core.gitresolver
|
||||
|
||||
__global (
|
||||
gsinstances map[string]&GitStructure
|
||||
|
||||
@@ -1,212 +0,0 @@
|
||||
module gittools
|
||||
|
||||
import freeflowuniverse.herolib.core.playbook { PlayBook }
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
@[params]
|
||||
pub struct PlayArgs {
|
||||
pub mut:
|
||||
heroscript string
|
||||
heroscript_path string
|
||||
plbook ?PlayBook
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn play(args_ PlayArgs) ! {
|
||||
mut args := args_
|
||||
mut plbook := args.plbook or {
|
||||
playbook.new(text: args.heroscript, path: args.heroscript_path)!
|
||||
}
|
||||
|
||||
// Handle !!git.define action first to configure GitStructure
|
||||
define_actions := plbook.find(filter: 'git.define')!
|
||||
mut gs := if define_actions.len > 0 {
|
||||
mut p := define_actions[0].params
|
||||
coderoot := p.get_default('coderoot', '')!
|
||||
light := p.get_default_true('light')
|
||||
log := p.get_default_true('log')
|
||||
debug := p.get_default_false('debug')
|
||||
offline := p.get_default_false('offline')
|
||||
ssh_key_path := p.get_default('ssh_key_path', '')!
|
||||
reload := p.get_default_false('reload')
|
||||
|
||||
new(
|
||||
coderoot: coderoot
|
||||
light: light
|
||||
log: log
|
||||
debug: debug
|
||||
offline: offline
|
||||
ssh_key_path: ssh_key_path
|
||||
reload: reload
|
||||
)!
|
||||
} else {
|
||||
// Initialize GitStructure with defaults
|
||||
new()!
|
||||
}
|
||||
|
||||
// Handle !!git.clone action
|
||||
clone_actions := plbook.find(filter: 'git.clone')!
|
||||
for action in clone_actions {
|
||||
mut p := action.params
|
||||
url := p.get('url')!
|
||||
coderoot := p.get_default('coderoot', '')!
|
||||
sshkey := p.get_default('sshkey', '')!
|
||||
light := p.get_default_true('light')
|
||||
recursive := p.get_default_false('recursive')
|
||||
|
||||
mut clone_args := GitCloneArgs{
|
||||
url: url
|
||||
sshkey: sshkey
|
||||
recursive: recursive
|
||||
light: light
|
||||
}
|
||||
if coderoot.len > 0 {
|
||||
gs = new(coderoot: coderoot)!
|
||||
}
|
||||
gs.clone(clone_args)!
|
||||
}
|
||||
|
||||
// Handle !!git.repo_action
|
||||
repo_actions := plbook.find(filter: 'git.repo_action')!
|
||||
for action in repo_actions {
|
||||
mut p := action.params
|
||||
filter_str := p.get_default('filter', '')!
|
||||
name := p.get_default('name', '')!
|
||||
account := p.get_default('account', '')!
|
||||
provider := p.get_default('provider', '')!
|
||||
action_type := p.get('action')!
|
||||
message := p.get_default('message', '')!
|
||||
branchname := p.get_default('branchname', '')!
|
||||
tagname := p.get_default('tagname', '')!
|
||||
submodules := p.get_default_false('submodules')
|
||||
error_ignore := p.get_default_false('error_ignore')
|
||||
|
||||
mut repos := gs.get_repos(
|
||||
filter: filter_str
|
||||
name: name
|
||||
account: account
|
||||
provider: provider
|
||||
)!
|
||||
|
||||
if repos.len == 0 {
|
||||
if !error_ignore {
|
||||
return error('No repositories found for git.repo_action with filter: ${filter_str}, name: ${name}, account: ${account}, provider: ${provider}')
|
||||
}
|
||||
console.print_stderr('No repositories found for git.repo_action with filter: ${filter_str}, name: ${name}, account: ${account}, provider: ${provider}. Ignoring due to error_ignore: true.')
|
||||
continue
|
||||
}
|
||||
|
||||
for mut repo in repos {
|
||||
match action_type {
|
||||
'pull' {
|
||||
repo.pull(submodules: submodules) or {
|
||||
if !error_ignore {
|
||||
return error('Failed to pull repo ${repo.name}: ${err}')
|
||||
}
|
||||
console.print_stderr('Failed to pull repo ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
'commit' {
|
||||
repo.commit(message) or {
|
||||
if !error_ignore {
|
||||
return error('Failed to commit repo ${repo.name}: ${err}')
|
||||
}
|
||||
console.print_stderr('Failed to commit repo ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
'push' {
|
||||
repo.push() or {
|
||||
if !error_ignore {
|
||||
return error('Failed to push repo ${repo.name}: ${err}')
|
||||
}
|
||||
console.print_stderr('Failed to push repo ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
'reset' {
|
||||
repo.reset() or {
|
||||
if !error_ignore {
|
||||
return error('Failed to reset repo ${repo.name}: ${err}')
|
||||
}
|
||||
console.print_stderr('Failed to reset repo ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
'branch_create' {
|
||||
repo.branch_create(branchname) or {
|
||||
if !error_ignore {
|
||||
return error('Failed to create branch ${branchname} in repo ${repo.name}: ${err}')
|
||||
}
|
||||
console.print_stderr('Failed to create branch ${branchname} in repo ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
'branch_switch' {
|
||||
repo.branch_switch(branchname) or {
|
||||
if !error_ignore {
|
||||
return error('Failed to switch branch to ${branchname} in repo ${repo.name}: ${err}')
|
||||
}
|
||||
console.print_stderr('Failed to switch branch to ${branchname} in repo ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
'tag_create' {
|
||||
repo.tag_create(tagname) or {
|
||||
if !error_ignore {
|
||||
return error('Failed to create tag ${tagname} in repo ${repo.name}: ${err}')
|
||||
}
|
||||
console.print_stderr('Failed to create tag ${tagname} in repo ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
'tag_switch' {
|
||||
repo.tag_switch(tagname) or {
|
||||
if !error_ignore {
|
||||
return error('Failed to switch tag to ${tagname} in repo ${repo.name}: ${err}')
|
||||
}
|
||||
console.print_stderr('Failed to switch tag to ${tagname} in repo ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
'delete' {
|
||||
repo.delete() or {
|
||||
if !error_ignore {
|
||||
return error('Failed to delete repo ${repo.name}: ${err}')
|
||||
}
|
||||
console.print_stderr('Failed to delete repo ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
else {
|
||||
if !error_ignore {
|
||||
return error('Unknown git.repo_action: ${action_type}')
|
||||
}
|
||||
console.print_stderr('Unknown git.repo_action: ${action_type}. Ignoring due to error_ignore: true.')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle !!git.list
|
||||
list_actions := plbook.find(filter: 'git.list')!
|
||||
for action in list_actions {
|
||||
mut p := action.params
|
||||
filter_str := p.get_default('filter', '')!
|
||||
name := p.get_default('name', '')!
|
||||
account := p.get_default('account', '')!
|
||||
provider := p.get_default('provider', '')!
|
||||
status_update := p.get_default_false('status_update')
|
||||
|
||||
gs.repos_print(
|
||||
filter: filter_str
|
||||
name: name
|
||||
account: account
|
||||
provider: provider
|
||||
status_update: status_update
|
||||
)!
|
||||
}
|
||||
|
||||
// Handle !!git.reload_cache
|
||||
reload_cache_actions := plbook.find(filter: 'git.reload_cache')!
|
||||
for action in reload_cache_actions {
|
||||
mut p := action.params
|
||||
coderoot := p.get_default('coderoot', '')!
|
||||
if coderoot.len > 0 {
|
||||
gs = new(coderoot: coderoot)!
|
||||
}
|
||||
gs.load(true)! // Force reload
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user