Skip to content

Commit ec0b122

Browse files
committed
Allow organizational repos to be backed up instead of user
1 parent 6322da5 commit ec0b122

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

bin/github-backup

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ GetOptions(
1616
"l|list" => \$opts{list},
1717
"r|repos" => \$opts{repos},
1818
"i|issues" => \$opts{issues},
19+
"o|org=s" => \$opts{org},
20+
"a|all" => \$opts{all},
1921
"v|verbose" => \$opts{verbose},
2022
"h|help" => \$help,
2123
);
@@ -60,6 +62,8 @@ Options:
6062
-p | --proxy Optional proxy (https://proxy.example.com:PORT)
6163
-r | --repos Back up all of your repositories
6264
-i | --issues Back up all of your issues
65+
-o | --org Back up the repositories of this organisation
66+
-a | --all Back up all repositories for the authenticated user
6367
-h | --help Display this help page
6468
6569
EOF
@@ -69,7 +73,9 @@ my $gh = Github::Backup->new(
6973
api_user => $opts{user},
7074
token => $opts{token},
7175
dir => $opts{dir},
72-
proxy => $opts{proxy}
76+
proxy => $opts{proxy},
77+
org => $opts{org},
78+
all => $opts{all}
7379
);
7480

7581
if ($opts{list}) {

lib/Github/Backup.pm

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ has proxy => (
4242
has user => (
4343
is => 'rw',
4444
);
45+
has org => (
46+
is => 'rw',
47+
);
48+
has all => (
49+
is => 'rw',
50+
);
4551
has limit => (
4652
is => 'rw',
4753
);
@@ -102,7 +108,12 @@ sub list {
102108
my ($self) = @_;
103109

104110
if (! $self->{repo_list}) {
105-
my $repo_list = $self->gh->repos->list(user => $self->user);
111+
my %params = $self->all
112+
? ()
113+
: $self->org
114+
? (org => $self->org)
115+
: (user => $self->user); # GH API: only public repos for this user
116+
my $repo_list = $self->gh->repos->list(%params);
106117
while (my $repo = $repo_list->next) {
107118
push @{ $self->{repo_list} }, $repo;
108119
}

0 commit comments

Comments
 (0)