App/git/clean_forge_fork.pm untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 10 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 89 CC 5 SCAR 23.7
CC
5
Cov
0%
main
30.0
exit
2.0
BEGIN
2.0
CRAP 10.8
1 package App::git::clean_forge_fork;
2 # ABSTRACT: create tidy forks for pull requests
3 #
4 # Copyright (C) 2020 Sean Whitton <spwhitton@spwhitton.name>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or (at
9 # your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 $App::git::clean_forge_fork::VERSION = '0.005';
19 use 5.028;
20 use strict;
21 use warnings;
22  
23 use subs 'main';
24 use Term::UI;
25 use Getopt::Long;
26 use Git::Wrapper;
27 use API::GitForge qw(new_from_domain forge_access_token remote_forge_info);
28 use Try::Tiny;
29 use Cwd;
30  
31 my $exit_main = 0;
32  
33 CORE::exit main unless caller;
34  
35  
36 sub main {
37 shift if $_[0] and ref $_[0] eq "";
38 local @ARGV = @{ $_[0] } if $_[0] and ref $_[0] ne "";
39  
40 my $term = Term::ReadLine->new("brand");
41 my $upstream = "origin";
42 my $git = Git::Wrapper->new(getcwd);
43 #<<<
44 try {
45 $git->rev_parse({ git_dir => 1 });
46 } catch {
47 die "pwd doesn't look like a git repository ..\n";
48 };
49 #>>>
50 GetOptions "upstream=s" => \$upstream;
51  
52 my ($forge_domain, $upstream_repo) = remote_forge_info $upstream;
53 exit
54 unless $term->ask_yn(
55 prompt => "Do you want to submit changes against $upstream_repo?");
56  
57 my $forge = new_from_domain
58 domain => $forge_domain,
59 access_token => forge_access_token $forge_domain;
60 my $fork_uri = $forge->clean_fork($upstream_repo);
61 if (grep /\Afork\z/, $git->remote) {
62 $fork_uri eq ($git->remote(qw(get-url fork)))[0]
63 or die "fork remote exists but has wrong URI\n";
64 } else {
65 $git->remote(qw(add fork), $fork_uri);
66 }
67  
68 EXIT_MAIN:
69 return $exit_main;
70 }
71  
72 sub exit { $exit_main = shift // 0; goto EXIT_MAIN }
73  
74 __END__