Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: git-push target for Makefile (via ExtUtils::MakeMaker)

by Aldebaran (Curate)
on May 31, 2019 at 06:31 UTC ( [id://11100764]=note: print w/replies, xml ) Need Help??


in reply to Re^2: git-push target for Makefile (via ExtUtils::MakeMaker)
in thread git-push target for Makefile (via ExtUtils::MakeMaker)

I frequently find myself trying to replicate what bliako posts. I was able to get the expected result with the github values hard-coded into the script and taking the repo name off of STDIN. I then wanted to shuffle those values out of the source and load them using Config:Tiny, and take the new repo name off of STDIN. Right now I'm failing. Source:

#!/usr/bin/perl use 5.011; use warnings; # original by bliako on 27/05/2019 PM node_id=11100309 ## embellishments don't work yet use Net::GitHub; use Data::Dumper; use Config::Tiny; my $ini_path = qw( /home/bob/Documents/html_template_data/3.values.ini + ); say "ini path is $ini_path"; my $sub_hash = "my_github"; my $Config = Config::Tiny->new; $Config = Config::Tiny->read( $ini_path, 'utf8' ); say Dumper $Config; # -> is optional between brackets my $github_login = $Config->{$sub_hash}{'email'}; my $github_username = $Config->{$sub_hash}{'username'}; my $github_password = $Config->{$sub_hash}{'password'}; say "login is $github_login"; say "password is $github_password"; print "$0 : enter value for reponame: "; my $github_reponame = <STDIN>; chomp($github_reponame); my $git = Net::GitHub->new( login => $github_username, pass => $github_password ); say "username is $github_username"; my $reposinfo = $git->repos->list($github_username); print Dumper($reposinfo); my %reposlist = map { lc $_->{'full_name'} =~ s|^${github_username}/||r => $_ } @$re +posinfo; print "Repos: " . join( ",", keys %reposlist ) . "\n"; if ( !defined $reposlist{ lc $github_reponame } ) { print "$0 : creating new repository '$github_reponame' ...\n"; my $ret = undef; eval { $ret = $git->repos->create( { name => $github_reponame, description => "change this to suit", } ); }; if ($@) { print STDERR "$0 : failed to create repository '$github_reponame' +: $@\n"; exit(1); } } __END__

Output:

$ ./2.github.pl ini path is /home/bob/Documents/html_template_data/3.values.ini $VAR1 = bless( { ... 'my_github' => { 'password' => 'redacted', 'email' => 'tblazer66@gmail.com', 'user' => 'TBlazer66' }, ... }, 'Config::Tiny' ); login is tblazer66@gmail.com password is redacted ./2.github.pl : enter value for reponame: 2.newrepo Undef did not pass type constraint "Str" (in $args->{"login"}) at /usr +/local/share/perl/5.26.1/Net/GitHub.pm line 10 "Str" is a subtype of "Value" "Value" is a subtype of "Defined" Undef did not pass type constraint "Defined" (in $args->{"login"}) "Defined" is defined as: (defined($_))

It seems like the problem is that I'm not getting values passed. I looked at line 10 of Github.pm is in the subroutine that wraps the arguments and sends them further:

$ cd /usr/local/share/perl/5.26.1/Net $ cat GitHub.pm package Net::GitHub; use Net::GitHub::V3; our $VERSION = '0.95'; our $AUTHORITY = 'cpan:FAYLAND'; sub new { my $class = shift; Net::GitHub::V3->new(@_); } 1; __END__

Question 1 is what gives with the values being undefined?

The obvious disadvantage of my method is that Makefile.PL now contains a target (git-push) which the end user should never need.

I spent a lot of time looking at ExtUtils::MakeMaker, and I'm wondering what the word "target" denotes. I had used it for the OS of the plaform you're developing for.

Thanks for your post, and thanks for your comments,

Replies are listed 'Best First'.
Re^4: git-push target for Makefile (via ExtUtils::MakeMaker)
by soonix (Canon) on May 31, 2019 at 07:32 UTC
    my $github_username = $Config->{$sub_hash}{'username'}; ... say "username is $github_username";
    and
    'user' => 'TBlazer66' ... login is tblazer66@gmail.com
    don't go together...
    • key 'user' vs. 'username'
    • say "username is ..." vs. "login is ..."
      key 'user' vs. 'username' don't go together...

      Du hast ein ganz genaues Auge, soonix, vielen Dank. I realize that I'm still nibbling at the edges of this topic, but sometimes I can't get going north and south until I get past some bonehead thing that someone else can better see. I removed the variable for login. For people like me who like to use Config::Tiny, this would be determined in the ini file.

      #!/usr/bin/perl use 5.011; use warnings; # original by bliako on 27/05/2019 PM node_id=11100309 # values imported by Config::Tiny by Aldebaran # repo_name supplied to STDIN use Net::GitHub; use Data::Dumper; use Config::Tiny; my $ini_path = qw( /home/bob/Documents/html_template_data/3.values.ini + ); say "ini path is $ini_path"; my $sub_hash = "my_github"; my $Config = Config::Tiny->new; $Config = Config::Tiny->read( $ini_path, 'utf8' ); say Dumper $Config; my $user = $Config->{$sub_hash}{'username'}; my $pass = $Config->{$sub_hash}{'password'}; print "$0 : enter value for reponame: "; my $repo_name = <STDIN>; chomp($repo_name); my $git = Net::GitHub->new( login => $user, pass => $pass ); say "username is $user"; my $reposinfo = $git->repos->list($user); print Dumper($reposinfo); my %reposlist = map { lc $_->{'full_name'} =~ s|^${user}/||r => $_ } @$reposinfo; print "Repos: " . join( ",", keys %reposlist ) . "\n"; if ( !defined $reposlist{ lc $repo_name } ) { print "$0 : creating new repository '$repo_name' ...\n"; my $ret = undef; eval { $ret = $git->repos->create( { name => $repo_name, description => "change this to suit", } ); }; if ($@) { print STDERR "$0 : failed to create repository '$repo_name' : $@\n +"; exit(1); } } __END__

      What is happening with this snippet?

      my %reposlist = map { lc $_->{'full_name'} =~ s|^${user}/||r => $_ } @$reposinfo; print "Repos: " . join( ",", keys %reposlist ) . "\n";

      The output is pretty clear but rather verbose:

      'created_at' => '2019-02-26T07:24:14Z', 'keys_url' => 'https://api.github.com/repos/TBlazer66/SSCC +E/keys{/key_id}', 'subscribers_url' => 'https://api.github.com/repos/TBlazer +66/SSCCE/subscribers', 'branches_url' => 'https://api.github.com/repos/TBlazer66/ +SSCCE/branches{/branch}', 'releases_url' => 'https://api.github.com/repos/TBlazer66/ +SSCCE/releases{/id}',

      Now I'm going to try to tackle the code in the original post....

Re^4: git-push target for Makefile (via ExtUtils::MakeMaker)
by bliako (Monsignor) on May 31, 2019 at 09:25 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11100764]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-26 07:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found