11import { computed } from 'vue'
22import default_git_actions from '../default-git-actions.json'
3- import { combine_branches_from_branch_name , combine_branches_to_branch_name , config } from '../store'
3+ import { combine_branches_from_branch_name , combine_branches_to_branch_name } from '../store'
44import { git } from '../../bridge'
55import { default_origin } from '../store/repo'
6+ import config from '../store/config'
67
78/**
89 * @param actions {ConfigGitAction[]}
@@ -12,7 +13,7 @@ import { default_origin } from '../store/repo'
1213function apply_action_replacements ( actions , replacements = [ ] ) {
1314 let namespace = replacements . map ( ( [ k ] ) => k ) . join ( '-' ) || 'global'
1415 let replacements_by_type = replacements . reduce ( ( all , replacement ) =>
15- /** tsc doesn't understand of this */ ( ( /** @type {any } */ ( all ) [ typeof replacement [ 1 ] ] ??= [ ] ) . push ( replacement ) , all ) , /** @type {{string:[string,string][], function:[string,()=>Promise<string>][]} } */ ( { string : [ ] , function : [ ] } ) ) // eslint-disable-line jsdoc/valid-types
16+ /** tsc doesn't understand of this */ ( ( /** @type {any } */ ( all ) [ typeof replacement [ 1 ] ] ??= [ ] ) . push ( replacement ) , all ) , /** @type {{string:[string,string][], function:[string,()=>Promise<string>][]} } */ ( { string : [ ] , function : [ ] } ) )
1617 let apply_string_replacements = ( /** @type {string } */ txt ) =>
1718 replacements_by_type . string . reduce ( ( str , replacement ) =>
1819 str . replaceAll ( replacement [ 0 ] , replacement [ 1 ] ) , txt )
@@ -39,23 +40,27 @@ function apply_action_replacements(actions, replacements = []) {
3940
4041/** @type {Vue.Ref<GitAction[]> } */
4142export let global_actions = computed ( ( ) =>
42- apply_action_replacements ( default_git_actions [ 'actions.global' ] . concat ( config . value . actions ?. global || [ ] ) ) )
43+ apply_action_replacements ( /** @type {ConfigGitAction[] } */ ( default_git_actions [ 'actions.global' ] )
44+ . concat ( config . get_git_actions ( 'actions.global' ) ) ) )
4345export let commit_actions = ( /** @type {string } */ hash ) => computed ( ( ) => {
44- let config_commit_actions = default_git_actions [ 'actions.commit' ] . concat ( config . value . actions ?. commit || [ ] )
46+ let config_commit_actions = /** @type {ConfigGitAction[] } */ ( default_git_actions [ 'actions.commit' ] )
47+ . concat ( config . get_git_actions ( 'actions.commit' ) )
4548 return apply_action_replacements ( config_commit_actions , [
4649 [ '{COMMIT_HASH}' , hash ] ,
4750 [ '{COMMIT_BODY}' , ( ) =>
4851 git ( `show -s --format="%B" ${ hash } ` ) ] ,
4952 [ '{DEFAULT_REMOTE_NAME}' , default_origin . value || 'MISSING_REMOTE_NAME' ] ] )
5053} )
5154export let commits_actions = ( /** @type {string[] } */ hashes ) => computed ( ( ) => {
52- let config_commits_actions = default_git_actions [ 'actions.commits' ] . concat ( config . value . actions ?. commits || [ ] )
55+ let config_commits_actions = /** @type {ConfigGitAction[] } */ ( default_git_actions [ 'actions.commits' ] )
56+ . concat ( config . get_git_actions ( 'actions.commits' ) )
5357 return apply_action_replacements ( config_commits_actions , [
5458 [ '{COMMIT_HASHES}' , hashes . join ( ' ' ) ] ,
5559 [ '{DEFAULT_REMOTE_NAME}' , default_origin . value || 'MISSING_REMOTE_NAME' ] ] )
5660} )
5761export let branch_actions = ( /** @type {Branch } */ branch ) => computed ( ( ) => {
58- let config_branch_actions = default_git_actions [ 'actions.branch' ] . concat ( config . value . actions ?. branch || [ ] )
62+ let config_branch_actions = /** @type {ConfigGitAction[] } */ ( default_git_actions [ 'actions.branch' ] )
63+ . concat ( config . get_git_actions ( 'actions.branch' ) )
5964 return apply_action_replacements ( config_branch_actions , [
6065 [ '{BRANCH_ID}' , branch . id ] ,
6166 [ '{BRANCH_DISPLAY_NAME}' , branch . display_name ] ,
@@ -65,19 +70,22 @@ export let branch_actions = (/** @type {Branch} */ branch) => computed(() => {
6570 [ '{DEFAULT_REMOTE_NAME}' , default_origin . value || 'MISSING_REMOTE_NAME' ] ] )
6671} )
6772export let tag_actions = ( /** @type {string } */ tag_name ) => computed ( ( ) => {
68- let config_tag_actions = default_git_actions [ 'actions.tag' ] . concat ( config . value . actions ?. tag || [ ] )
73+ let config_tag_actions = /** @type {ConfigGitAction[] } */ ( default_git_actions [ 'actions.tag' ] )
74+ . concat ( config . get_git_actions ( 'actions.tag' ) )
6975 return apply_action_replacements ( config_tag_actions , [
7076 [ '{TAG_NAME}' , tag_name ] ,
7177 [ '{DEFAULT_REMOTE_NAME}' , default_origin . value || 'MISSING_REMOTE_NAME' ] ] )
7278} )
7379export let stash_actions = ( /** @type {string } */ stash_name ) => computed ( ( ) => {
74- let config_stash_actions = default_git_actions [ 'actions.stash' ] . concat ( config . value . actions ?. stash || [ ] )
80+ let config_stash_actions = /** @type {ConfigGitAction[] } */ ( default_git_actions [ 'actions.stash' ] )
81+ . concat ( config . get_git_actions ( 'actions.stash' ) )
7582 return apply_action_replacements ( config_stash_actions , [
7683 [ '{STASH_NAME}' , stash_name ] ,
7784 [ '{DEFAULT_REMOTE_NAME}' , default_origin . value || 'MISSING_REMOTE_NAME' ] ] )
7885} )
7986export let combine_branches_actions = computed ( ( ) => {
80- let config_combine_branches_actions = default_git_actions [ 'actions.branch-drop' ] . concat ( config . value . actions ?. [ 'branch-drop' ] || [ ] )
87+ let config_combine_branches_actions = /** @type {ConfigGitAction[] } */ ( default_git_actions [ 'actions.branch-drop' ] )
88+ . concat ( config . get_git_actions ( 'actions.branch-drop' ) )
8189 return apply_action_replacements ( config_combine_branches_actions , [
8290 [ '{SOURCE_BRANCH_NAME}' , combine_branches_from_branch_name . value ] ,
8391 [ '{TARGET_BRANCH_NAME}' , combine_branches_to_branch_name . value ] ,
0 commit comments