-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathrefresh_branch_cache
More file actions
33 lines (24 loc) · 772 Bytes
/
refresh_branch_cache
File metadata and controls
33 lines (24 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
use Path::Tiny;
use JSON;
my $json = JSON->new->pretty->canonical->utf8;
my $branch_cache_file = 'repo_def_branch.json';
unless (-f $branch_cache_file) {
die "Cache file ($branch_cache_file) doesn't exist. Stopping.\n";
}
my $repo_def_branch = $json->decode(path($branch_cache_file)->slurp_utf8);
OWNER:
for my $owner (keys %$repo_def_branch) {
for my $repo (keys %{ $repo_def_branch->{$owner} }) {
warn "$owner/$repo\n";
my $branch =
`gh repo view "$owner/$repo" --json defaultBranchRef -q .defaultBranchRef.name`;
# last OWNER if $?;
chomp $branch;
$repo_def_branch->{$owner}{$repo} = $branch;
}
}
path($branch_cache_file)->spew_utf8($json->encode($repo_def_branch));