1
0
Fork 0

allow regex in path definition for clonedev

This commit is contained in:
Luca Bilke 2024-02-27 01:21:24 +01:00
parent 372b4a0116
commit d39af3d181
2 changed files with 55 additions and 56 deletions

View file

@ -1,25 +1,36 @@
# token_cmd: "secret-tool lookup gitea api_token"
lookups: lookups:
- name: "gitea_owned_repos" - name: "gitea_owned_repos"
api_url: "https://git.snaile.de/api/v1" api_url: "https://git.snaile.de/api/v1"
endpoint: "repos" endpoint: "repos"
url_type: "ssh_url" url_field: "ssh_url"
token_cmd: "secret-tool lookup gitea api_token" token_cmd: "rbw get 'Gitea Snailed' -f 'Clonedev PAT'"
block_unsorted: 0 block_unsorted: jalse
targets: targets:
- "orgs/snailed" - "orgs/snailed"
- "users/luca" - "users/luca"
extra_headers: extra_headers:
- "Authorization: token ${TOKEN}" - "Authorization: token ${TOKEN}"
- name: "github_starred_repos" # - name: "github_starred_repos"
api_url: "https://api.github.com" # api_url: "https://api.github.com"
endpoint: "starred" # endpoint: "starred"
url_type: "ssh_url" # url_field: "ssh_url"
token_cmd: "secret-tool lookup github api_token" # token_cmd: "rbw get 'Github' -f 'Clonedev PAT'"
block_unsorted: 1 # block_unsorted: true
targets: # targets:
- "users/ssnailed" # - "users/ssnailed"
extra_headers: # extra_headers:
- "Authorization: Bearer ${TOKEN}" # - "Authorization: Bearer ${TOKEN}"
# - name: "tralios_gitlab"
# api_url: "https://gitlab.tralios.de/api/v4/"
# endpoint:
# url_field: "ssh_url_to_repo"
# token_cmd: "rbw get 'Gitlab Tralios' -f 'Clonedev PAT'"
# block_unsorted: true
# targets:
# -
# extra_headers:
# - "Authorization: Bearer ${TOKEN}"
extra_urls: extra_urls:
# - "https://git.kernel.org/pub/scm/git/git.git" # - "https://git.kernel.org/pub/scm/git/git.git"
@ -37,17 +48,6 @@ directories:
- "luca/st-custom" - "luca/st-custom"
- "luca/tokyonight-icons" - "luca/tokyonight-icons"
- "luca/tokyonight-theme" - "luca/tokyonight-theme"
- path: "${XDG_DOCUMENTS_DIR}/dev/server"
repos:
- "snailed/ansible-example"
- "snailed/ansible-homelab"
- "snailed/dotfiles-server"
- "snailed/qbittorrent-natpmp-docker"
- "snailed/papermc-docker"
- "snailed/server-resources"
- "snailed/void-packages-custom"
- "snailed/xbps-builder"
- "spantaleev/matrix-docker-ansible-deploy"
- path: "${XDG_DOCUMENTS_DIR}/dev/nvim" - path: "${XDG_DOCUMENTS_DIR}/dev/nvim"
repos: repos:
- "snailed/taolf" - "snailed/taolf"
@ -59,10 +59,21 @@ directories:
- path: "${XDG_DOCUMENTS_DIR}/dev" - path: "${XDG_DOCUMENTS_DIR}/dev"
repos: repos:
- "void-linux/void-packages" - "void-linux/void-packages"
- path: "${XDG_DOCUMENTS_DIR}/dev/server"
repos:
- "snailed/ansible-example"
- "snailed/ansible-homelab"
- "snailed/qbittorrent-natpmp-docker"
- "snailed/papermc-docker"
- "snailed/server-resources"
- "snailed/void-packages-custom"
- "snailed/xbps-builder"
- "luca/dotfiles-server"
- "spantaleev/matrix-docker-ansible-deploy"
unsorted_directory: "${XDG_DOCUMENTS_DIR}/dev/unsorted" unsorted_directory: "${XDG_DOCUMENTS_DIR}/dev/unsorted"
block_repos: skip_repos:
- "luca/dotfiles" - "luca/dotfiles"
- "luca/pinentry-dmenu-custom" - "luca/pinentry-dmenu-custom"
- "snailed/matrix-inventory" - "snailed/matrix-inventory"

View file

@ -134,37 +134,21 @@ sub process_urls($handle) {
next; next;
} }
next if (grep({ $_ eq $repo{fullname} } @{$conf{skip_repos}})); next if ( grep( $_ eq $repo{fullname}, @{ $conf{skip_repos} } ) );
my $path; my $path;
for my $directory ( @{ $conf{directories} } ) { DIRS: for my $directory ( @{ $conf{directories} } ) {
if (grep({ $_ eq $repo{fullname} } @{ %$directory{repos} })) { for my $regex ( @{ $directory->{repos} } ) {
$path = %$directory{path}; if ( $repo{fullname} =~ /$regex/ ) {
last; $repo{path} = `printf $directory->{path}/$repo{name}`;
last DIRS;
}
} }
} }
if ( !$handles[$handle]{lookup} ) { if (!$repo{path} && $conf{lookups}[ $handles[$handle]{lookup} ]{block_unsorted}) {
if ($path) {
$repo{path} = `printf $path/$repo{name}`;
}
else {
$repo{path} = `printf $conf{unsorted_directory}/$repo{name}`;
}
}
elsif ( !$conf{lookups}[ $handles[$handle]{lookup} ]{block_unsorted}
&& $repo{path} )
{
$repo{path} = `printf $conf{unsorted_directory}/$repo{name}`; $repo{path} = `printf $conf{unsorted_directory}/$repo{name}`;
} }
elsif ($path) {
$repo{path} = `printf $path/$repo{name}`;
}
else {
warning("Skipping $repo{fullname}");
next;
}
my $clone_hook = "$conf{hook_dir}/clone/$repo{owner}:$repo{name}"; my $clone_hook = "$conf{hook_dir}/clone/$repo{owner}:$repo{name}";
my $pull_hook = "$conf{hook_dir}/pull/$repo{owner}:$repo{name}"; my $pull_hook = "$conf{hook_dir}/pull/$repo{owner}:$repo{name}";
@ -175,15 +159,15 @@ sub process_urls($handle) {
} }
$handles[$handle]{memory} = \@tmp; $handles[$handle]{memory} = \@tmp;
} }
#
# sub dump($handle) { sub dump($handle) {
# print("------ Handle $handle ------\n"); print("------ Handle $handle ------\n");
# print Dumper( $handles[$handle]->{memory} ); print Dumper( $handles[$handle]->{memory} );
# } }
sub folder_is_empty($directory) { sub folder_is_empty($directory) {
opendir( my $dh, $directory ) or return 1; opendir( my $dh, $directory ) or return 1;
return scalar( grep { $_ ne "." && $_ ne ".." } readdir($dh) ) == 0; return scalar( grep( $_ ne "." && $_ ne "..", readdir($dh) ) ) == 0;
} }
sub handle_repos($handle) { sub handle_repos($handle) {
@ -235,6 +219,9 @@ sub read_conf() {
if ( !$hashref->{hook_dir} ) { if ( !$hashref->{hook_dir} ) {
$hashref->{hook_dir} = "$configdir/hooks"; $hashref->{hook_dir} = "$configdir/hooks";
} }
for my $dir (@{$hashref->{directories}}) {
grep(s/\//\\\//, @{$dir->{repos}});
}
%conf = %$hashref; %conf = %$hashref;
} }
@ -265,7 +252,8 @@ for my $i ( keys @{ $conf{lookups} } ) {
add_callback( $last_handle, \&json_decode ); add_callback( $last_handle, \&json_decode );
add_callback( $last_handle, \&url_filter ); add_callback( $last_handle, \&url_filter );
add_callback( $last_handle, \&process_urls ); add_callback( $last_handle, \&process_urls );
add_callback( $last_handle, \&handle_repos ); add_callback( $last_handle, \&dump );
# add_callback( $last_handle, \&handle_repos );
} }
} }