| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # Create, Read, Update, Delete files, commits, issues, and web hooks on GitHub. | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Per: https://developer.github.com/v3/ | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # Philip R Brenan at gmail dot com, Appa Apps Ltd, 2017-2020 | ||||||||||||||||||||||||||||||||||||||||||
| 6 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 7 | #podDocumentation | ||||||||||||||||||||||||||||||||||||||||||
| 8 | package GitHub::Crud; | ||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use v5.16; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | our $VERSION = 20260213; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use warnings FATAL => qw(all); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Data::Dump qw(dump); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Data::Table::Text qw(:all !fileList); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Digest::SHA1 qw(sha1_hex); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Scalar::Util qw(blessed reftype looks_like_number); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Time::HiRes qw(time); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Encode qw(encode decode); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use utf8; # To allow utf8 constants for testing | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub url { "https://api.github.com/repos" } # Github repository api url | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
url: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub api { "https://api.github.com/" } # Github api url | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
api: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub accessFolder { q(/etc/GitHubCrudPersonalAccessToken) }; # Personal access tokens are stored in a file in this folder with the name of the userid of the L<GitHub> repository | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
accessFolder: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | my %shas; # L<SHA> digests already seen - used to optimize write and delete | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | sub specialFileData($) #P Do not encode or decode data with a known file signature | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | {my ($d) = @_; # String to check | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
specialFileData: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | my $h = ''; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | if ($d and length($d) > 8) # Read file magic number | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$d and length $d > 8
MC/DC0%0/2
$d and length $d > 8
$d
length $d > 8
Truth table0%0/3
A and B
A= $dB= length $d > 8
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | {for my $e(0..7) | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | {$h .= sprintf("%x", ord(substr($d, $e, 1))); | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | return 1 if $h =~ m(\A504b)i; # PK Zip | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | return 1 if $h =~ m(\Ad0cf11e0)i; # OLE files | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | return 1 if $h =~ m(\Affd8ff)i; # Jpg | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | return 1 if $h =~ m(\A89504e470d0a1a0a)i; # Png | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | return 1 if $h =~ m(\A4D546864)i; # Midi | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | return 1 if $h =~ m(\A49443340)i; # Mp3 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | return 1 if $d =~ m(\A.PNG); # Png | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | return 1 if $d =~ m(\ARIFF....WAVEfmt); # Wav | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | return 1 if $d =~ m(\A....ftypavif); # Avif | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 # Not a special file | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | sub GitHub::Crud::Response::new($$) #P Execute a request against L<GitHub> and decode the response | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | {my ($gitHub, $request) = @_; # Github, request string | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=21 SCAR=61.4
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my $R = bless {command=>$request}, "GitHub::Crud::Response"; # Construct the response | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $r; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | for my $i(1..10) # Request several times as lately, 2026-02-13, Github has been occasionally handing back empty responses | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | {$r = xxx $request, qr(HTTP); | |||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | last if $r; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | confess "No response to request:\n$request" if !$r; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $r =~ s/\r//gs; # Internet line ends | |||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my ($http, @r) = split /\n/, $r; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | while(@r > 2 and $http =~ "HTTP" and $http =~ /100/) # Continue messages | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
@r > 2 and $http =~ /HTTP/u and $http =~ /100/u
@r > 2 and $http =~ /HTTP/u
MC/DC0%0/3
@r > 2 and $http =~ /HTTP/u and $http =~ /100/u
@r > 2
$http =~ /HTTP/u
$http =~ /100/u
Truth table0%0/4
A and B and C
A= @r > 2B= $http =~ /HTTP/uC= $http =~ /100/u
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | {shift @r; $http = shift @r; | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ($http and $http =~ "HTTP" and $http =~ /200|201|404|409|422/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$http and $http =~ /HTTP/u and $http =~ /200|201|404|409|422/u
$http and $http =~ /HTTP/u
MC/DC0%0/3
$http and $http =~ /HTTP/u and $http =~ /200|201|404|409|422/u
$http
$http =~ /HTTP/u
$http =~ /200|201|404|409|422/u
Truth table0%0/4
A and B and C
A= $httpB= $http =~ /HTTP/uC= $http =~ /200|201|404|409|422/u
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | {my $ps = 0; # Parse the response | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my @data; | |||||||||||||||||||||||||||||||||||||||||
| 69 | my %can; | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | for(@r) | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | {if ($ps == 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | {if (length == 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | {$ps = 1; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | else | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | {my ($name, $content) = split /\s*:\s*/, $_, 2; # Parse each header | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $name =~ s/-/_/gs; # Translate - in names to _ | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ($R->can($name)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | {$R->$name = $content; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | else {$can{$name}++} # Update list of new methods required | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | else | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | {push @data, $_; | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if (keys %can) # List of new methods required | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | {lll "Add the following fields to package GitHub::Crud::Response, continuing ..."; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | say STDERR " $_=> undef," for(sort keys %can); | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if (@data) # Save any data | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | {my $j = join ' ', @data; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $p = $R->data = bless decodeJson($j), "GitHub::Crud::Response::Data"; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if (ref($p) =~ m/hash/is and my $c = $p->content) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref($p) =~ /hash/isu and my $c = $p->content
MC/DC0%0/2
ref($p) =~ /hash/isu and my $c = $p->content
ref($p) =~ /hash/isu
my $c = $p->content
Truth table0%0/3
A and B
A= ref($p) =~ /hash/isuB= my $c = $p->content
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | {$R->content = decodeBase64($c); # Decode the data | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | ($R->status) = split / /, $R->Status || $R->status || 200; # Save response status - github returns status == 0 when running as an action so we make it 200 | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$R->Status || $R->status || 200
$R->Status or $R->status
MC/DC0%0/2
$R->Status || $R->status || 200
$R->Status
$R->status
Truth table0%0/3
A or B
A= $R->StatusB= $R->status
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | return $gitHub->response = $R; # Return successful response | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | else | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | {confess "Unexpected response from GitHub:\n$r\n$request\n"; # Confess to failure | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | genHash(q(GitHub::Crud::Response), # Attributes describing a response from L<GitHub>. | |||||||||||||||||||||||||||||||||||||||||
| 113 | Accept_Ranges => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 114 | access_control_allow_origin => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 115 | Access_Control_Allow_Origin => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 116 | access_control_expose_headers => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 117 | Access_Control_Expose_Headers => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 118 | cache_control => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 119 | Cache_Control => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 120 | Connection => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 121 | content_length => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 122 | Content_Length => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 123 | content_security_policy => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 124 | Content_Security_Policy => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 125 | content_type => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 126 | Content_Type => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 127 | content => undef, # The actual content of the file from L<GitHub>. | ||||||||||||||||||||||||||||||||||||||||||
| 128 | data => undef, # The data received from L<GitHub>, normally in L<json> format. | ||||||||||||||||||||||||||||||||||||||||||
| 129 | date => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 130 | Date => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 131 | etag => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 132 | ETag => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 133 | Expires => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | last_modified => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 135 | Last_Modified => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 136 | Link => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 137 | Location => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 138 | referrer_policy => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 139 | Referrer_Policy => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 140 | server => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 141 | Server => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 142 | Source_Age => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 143 | Status => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | status => undef, # Our version of Status. | ||||||||||||||||||||||||||||||||||||||||||
| 145 | strict_transport_security => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 146 | Strict_Transport_Security => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 147 | vary => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 148 | Vary => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 149 | Via => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 150 | x_accepted_oauth_scopes => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 151 | X_Accepted_OAuth_Scopes => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 152 | X_Cache_Hits => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 153 | X_Cache => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 154 | x_content_type_options => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 155 | X_Content_Type_Options => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 156 | X_Content_Type => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 157 | X_Fastly_Request_ID => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 158 | x_frame_options => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 159 | X_Frame_Options => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 160 | X_Geo_Block_List => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 161 | x_github_media_type => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 162 | X_GitHub_Media_Type => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 163 | x_github_request_id => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 164 | X_GitHub_Request_Id => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 165 | x_oauth_scopes => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 166 | X_OAuth_Scopes => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 167 | x_ratelimit_limit => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 168 | X_RateLimit_Limit => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 169 | x_ratelimit_remaining => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 170 | X_RateLimit_Remaining => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 171 | x_ratelimit_reset => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 172 | X_RateLimit_Reset => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 173 | x_ratelimit_used => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 174 | X_RateLimit_Used => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 175 | X_Runtime_rack => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 176 | X_Served_By => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 177 | X_Timer => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 178 | x_xss_protection => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 179 | X_XSS_Protection => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 180 | x_ratelimit_resource => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 181 | x_github_api_version_selected => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 182 | x_accepted_github_permissions => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 183 | x_envoy_decorator_operation => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 184 | x_envoy_upstream_service_time => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 185 | x_internal_experiment_version_metadata => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 186 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | genHash(q(GitHub::Crud::Response::Data), # Response from a request made to L<GitHub>. | |||||||||||||||||||||||||||||||||||||||||
| 189 | command => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 190 | content => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 191 | documentation_url => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 192 | download_url => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 193 | encoding => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 194 | git => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 195 | git_url => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 196 | html => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 197 | html_url => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 198 | _links => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 199 | message => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 200 | name => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 201 | path => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 202 | self => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 203 | sha => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 204 | size => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 205 | type => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 206 | url => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 207 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | sub getSha($) #P Compute L<sha> for data after encoding any unicode characters as utf8. | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | {my ($data) = @_; # String possibly containing non ascii code points | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getSha: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | my $length = length($data); | |||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | utf8::encode($data) unless specialFileData($data); # Utf8 is assumed for things which are not known to be files containing images, sounds or other binary data in a well known format | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my $e = "blob $length\0$data"; # See: https://alblue.bandlem.com/2011/08/git-tip-of-week-objects.html | |||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my $r = eval{sha1_hex($e)}; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | confess $@ if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | $r | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | if (0) # Test L<sha> | |||||||||||||||||||||||||||||||||||||||||
| 221 | {my $sha = getSha(""); | ||||||||||||||||||||||||||||||||||||||||||
| 222 | my $Sha = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"; | ||||||||||||||||||||||||||||||||||||||||||
| 223 | unless($sha eq $Sha) | ||||||||||||||||||||||||||||||||||||||||||
| 224 | {confess "Wrong SHA: $sha". | ||||||||||||||||||||||||||||||||||||||||||
| 225 | "Should be: $Sha"; | ||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | confess "getSha success"; | ||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | sub shaKey($;$) #P Add a L<SHA> key to a L<url> | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | {my ($gitHub, $fileData) = @_; # Github, optional fileData to specify the file to use if it is not gitFile | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shaKey: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | filePath($gitHub->repository, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | $fileData ? ($fileData->path, $fileData->name) : $gitHub->gitFile) | ||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | sub saveSha($$) #P Save the L<sha> of a file | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | {my ($gitHub, $fileData) = @_; # Github, file details returned by list or exists | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
saveSha: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | $shas{$gitHub->shaKey($fileData)} = $fileData->sha; | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | sub copySha($) #P Save the L<sha> of a file just read to a file just about to be written | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | {my ($gitHub) = @_; # Github | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
copySha: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | $shas{$gitHub->shaKey} = $gitHub->response->data->sha; | |||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | sub getExistingSha($) #P Get the L<sha> of a file that already exists | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | {my ($gitHub) = @_; # Github | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getExistingSha: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | my $s = $shas{$gitHub->shaKey}; # Get the L<sha> from the cache | |||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | return $s if defined $s; # A special L<sha> of 0 means the file was deleted | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my $r = $gitHub->exists; # Get the L<sha> of the file via exists if the file exists | |||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | return $r->sha if $r; # L<sha> of existing file | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | undef # Undef if no such file | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | sub deleteSha($) #P Delete a L<sha> that is no longer valid | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | {my ($gitHub) = @_; # Github | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deleteSha: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $shas{$gitHub->shaKey} = undef # Mark the L<sha> as deleted | |||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | sub qm($) #P Quotemeta extended to include undef | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | {my ($s) = @_; # String to quote | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
qm: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | return '' unless $s; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $s =~ s((\'|\"|\\)) (\\$1)gs; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | $s =~ s(\s) (%20)gsr; # Url encode blanks | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | sub patKey($) #P Create an authorization header by locating an appropriate personal access token | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | {my ($gitHub) = @_; # GitHub | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
patKey: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | $gitHub->loadPersonalAccessToken unless $gitHub->personalAccessToken; # Load a personal access token if none has been supplied | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if (my $pat = $gitHub->personalAccessToken) # User supplied personal access token explicitly | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | {return "-H \"Authorization: token $pat\"" | |||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | confess "Personal access token required with scope \"public_repo\"". # We must have a personal access token to do anything useful! | |||||||||||||||||||||||||||||||||||||||||
| 277 | " as generated on page:\nhttps://github.com/settings/tokens"; | ||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | sub refOrBranch($$) #P Add a ref or branch keyword | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | {my ($gitHub, $ref) = @_; # Github, whether to use ref rather than branch | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
refOrBranch: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | my $b = $gitHub->branch; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | return "?ref=$b" if $ref and $b; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ref and $b
MC/DC0%0/2
$ref and $b
$ref
$b
Truth table0%0/3
A and B
A= $refB= $b
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | return "?branch=$b" if !$ref and $b; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $ref and $b
MC/DC0%0/2
not $ref and $b
not $ref
$b
Truth table0%0/3
not(A) and B
A= not $refB= $b
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | '' | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | sub gitHub(%) #P Create a test L<GitHub> object | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | {my (%options) = @_; # Options | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gitHub: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | GitHub::Crud::new | |||||||||||||||||||||||||||||||||||||||||
| 291 | (userid => q(philiprbrenan), | ||||||||||||||||||||||||||||||||||||||||||
| 292 | repository => q(aaa), | ||||||||||||||||||||||||||||||||||||||||||
| 293 | confessOnFailure => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 294 | @_); | ||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | #D1 Constructor # Create a L<GitHub> object with the specified attributes describing the interface with L<github>. | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | sub new(@) # Create a new L<GitHub> object with attributes as described at: L<GitHub::Crud Definition>. | ||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | {my (%attributes) = @_; # Attribute values | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | my $curl = qx(curl -V); # Check Curl | |||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | if ($curl =~ /command not found/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | {confess "Command curl not found" | |||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | my $g = genHash(__PACKAGE__, # Attributes describing the interface with L<github>. | |||||||||||||||||||||||||||||||||||||||||
| 308 | body => undef, #I The body of an issue. | ||||||||||||||||||||||||||||||||||||||||||
| 309 | branch => undef, #I Branch name (you should create this branch first) or omit it for the default branch which is usually 'master'. | ||||||||||||||||||||||||||||||||||||||||||
| 310 | confessOnFailure => undef, #I Confess to any failures | ||||||||||||||||||||||||||||||||||||||||||
| 311 | failed => undef, # Defined if the last request to L<GitHub> failed else B<undef>. | ||||||||||||||||||||||||||||||||||||||||||
| 312 | fileList => undef, # Reference to an array of files produced by L<list|/list>. | ||||||||||||||||||||||||||||||||||||||||||
| 313 | gitFile => undef, #I File name on L<GitHub> - this name can contain '/'. This is the file to be read from, written to, copied from, checked for existence or deleted. | ||||||||||||||||||||||||||||||||||||||||||
| 314 | gitFolder => undef, #I Folder name on L<GitHub> - this name can contain '/'. | ||||||||||||||||||||||||||||||||||||||||||
| 315 | message => undef, #I Optional commit message | ||||||||||||||||||||||||||||||||||||||||||
| 316 | nonRecursive => undef, #I Fetch only one level of files with L<list>. | ||||||||||||||||||||||||||||||||||||||||||
| 317 | personalAccessToken => undef, #I A personal access token with scope "public_repo" as generated on page: https://github.com/settings/tokens. | ||||||||||||||||||||||||||||||||||||||||||
| 318 | personalAccessTokenFolder => accessFolder, #I The folder into which to save personal access tokens. Set to B</etc/GitHubCrudPersonalAccessToken> by default. | ||||||||||||||||||||||||||||||||||||||||||
| 319 | private => undef, #I Whether the repository being created should be private or not. | ||||||||||||||||||||||||||||||||||||||||||
| 320 | readData => undef, # Data produced by L<read|/read>. | ||||||||||||||||||||||||||||||||||||||||||
| 321 | repository => undef, #I The name of the repository to be worked on minus the userid - you should create this repository first manually. | ||||||||||||||||||||||||||||||||||||||||||
| 322 | response => undef, # A reference to L<GitHub>'s response to the latest request. | ||||||||||||||||||||||||||||||||||||||||||
| 323 | secret => undef, #I The secret for a web hook - this is created by the creator of the web hook and remembered by L<GitHub>, | ||||||||||||||||||||||||||||||||||||||||||
| 324 | title => undef, #I The title of an issue. | ||||||||||||||||||||||||||||||||||||||||||
| 325 | webHookUrl => undef, #I The url for a web hook. | ||||||||||||||||||||||||||||||||||||||||||
| 326 | userid => undef, #I Userid on L<GitHub> of the repository to be worked on. | ||||||||||||||||||||||||||||||||||||||||||
| 327 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $g->$_ = $attributes{$_} for sort keys %attributes; | |||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $g | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | #D1 Files # File actions on the contents of L<GitHub> repositories. | ||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | sub list($) # List all the files contained in a L<GitHub> repository or all the files below a specified folder in the repository.\mRequired attributes: L<userid|/userid>, L<repository|/repository>.\mOptional attributes: L<gitFolder|/gitFolder>, L<refOrBranch|/refOrBranch>, L<nonRecursive|/nonRecursive>, L<patKey|/patKey>.\mUse the L<gitFolder|/gitFolder> parameter to specify the folder to start the list from, by default, the listing will start at the root folder of your repository.\mUse the L<nonRecursive|/nonRecursive> option if you require only the files in the start folder as otherwise all the folders in the start folder will be listed as well which might take some time.\mIf the list operation is successful, L<failed|/failed> is set to false and L<fileList|/fileList> is set to refer to an array of the file names found.\mIf the list operation fails then L<failed|/failed> is set to true and L<fileList|/fileList> is set to refer to an empty array.\mReturns the list of file names found or empty list if no files were found. | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | {my ($gitHub) = @_; # GitHub | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | my $r = sub # Get contents | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | {my $user = qm $gitHub->userid; $user or confess "userid required"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | my $repo = qm $gitHub->repository; $repo or confess "repository required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | my $path = qm $gitHub->gitFolder || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
&qm(scalar $gitHub->gitFolder) || ''
MC/DC0%0/1
&qm(scalar $gitHub->gitFolder) || ''
&qm(scalar $gitHub->gitFolder)
Truth table0%0/2
A
A= &qm(scalar $gitHub->gitFolder)
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my $bran = qm $gitHub->refOrBranch(1); | |||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | my $pat = $gitHub->patKey(0); | |||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | my $url = url; | |||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | my $s = filePath | |||||||||||||||||||||||||||||||||||||||||
| 346 | ("curl -si $pat $url", $user, $repo, qq(contents), $path.$bran); | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | GitHub::Crud::Response::new($gitHub, $s); | |||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | }->(); | |||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my $failed = $gitHub->failed = $r->status != 200; # Check response code | |||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | $failed and $gitHub->confessOnFailure and confess dump($gitHub); # Confess to any failure if so requested | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$failed and $gitHub->confessOnFailure
MC/DC0%0/2
$failed and $gitHub->confessOnFailure
$failed
$gitHub->confessOnFailure
Truth table0%0/3
A and B
A= $failedB= $gitHub->confessOnFailure
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | $gitHub->fileList = []; | |||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | if (!$failed and reftype($r->data) =~ m(array)i) # Array of file details | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $failed and builtin::reftype($r->data) =~ /array/iu
MC/DC0%0/2
not $failed and builtin::reftype($r->data) =~ /array/iu
not $failed
builtin::reftype($r->data) =~ /array/iu
Truth table0%0/3
not(A) and B
A= not $failedB= builtin::reftype($r->data) =~ /array/iu
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | {for(@{$r->data}) # Objectify and save L<sha> digests from file descriptions retrieved by this call | |||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | {bless $_, "GitHub::Crud::Response::Data"; | |||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | saveSha($gitHub, $_); | |||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | my $path = $gitHub->gitFolder || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$gitHub->gitFolder || ''
MC/DC0%0/1
$gitHub->gitFolder || ''
$gitHub->gitFolder
Truth table0%0/2
A
A= $gitHub->gitFolder
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | my @d = map{filePath $path, $_->name} grep {$_->type eq "dir"} @{$r->data};# Folders | |||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | my @f = map{filePath $path, $_->name} grep {$_->type eq "file"} @{$r->data};# Files | |||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | unless($gitHub->nonRecursive) # Get the contents of sub folders unless otherwise specified | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | {for my $d(@d) | |||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | {my $p = $gitHub->gitFolder = $d; | |||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | push @f, $gitHub->list; | |||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $gitHub->gitFolder = $path; # Restore path supplied by the user | |||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $gitHub->fileList = [@f]; # List of files not directories | |||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | @{$gitHub->fileList} | |||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | sub read($;$) # Read data from a file on L<GitHub>.\mRequired attributes: L<userid|/userid>, L<repository|/repository>.\mOptional attributes: L<gitFile|/gitFile> = the file to read, L<refOrBranch|/refOrBranch>, L<patKey|/patKey>.\mIf the read operation is successful, L<failed|/failed> is set to false and L<readData|/readData> is set to the data read from the file.\mIf the read operation fails then L<failed|/failed> is set to true and L<readData|/readData> is set to B<undef>.\mReturns the data read or B<undef> if no file was found. | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | {my ($gitHub, $File) = @_; # GitHub, file to read if not specified in gitFile | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | my $user = qm $gitHub->userid; $user or confess "userid required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | my $repo = qm $gitHub->repository; $repo or confess "repository required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | my $file = qm($File//$gitHub->gitFile); $file or confess "gitFile required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$File // $gitHub->gitFile
MC/DC0%0/2
$File // $gitHub->gitFile
$File
$gitHub->gitFile
Truth table0%0/3
A // B
A= $FileB= $gitHub->gitFile
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | my $bran = qm $gitHub->refOrBranch(1); | |||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | my $pat = $gitHub->patKey(0); | |||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | my $url = url; | |||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | my $s = filePath(qq(curl -si $pat $url), | |||||||||||||||||||||||||||||||||||||||||
| 387 | $user, $repo, qq(contents), $file.$bran); | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | my $r = GitHub::Crud::Response::new($gitHub, $s); # Get response from GitHub | |||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | my $failed = $gitHub->failed = $r->status != 200; # Check response code | |||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | $failed and $gitHub->confessOnFailure and confess dump($gitHub); # Confess to any failure if so requested | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$failed and $gitHub->confessOnFailure
MC/DC0%0/2
$failed and $gitHub->confessOnFailure
$failed
$gitHub->confessOnFailure
Truth table0%0/3
A and B
A= $failedB= $gitHub->confessOnFailure
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | if ($failed) # Decode data unless read failed | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | {$gitHub->readData = undef; | |||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | else # Decode data | ||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | {my $d = decodeBase64($r->data->content); | |||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | $gitHub->readData = specialFileData($d) ? $d : decode "UTF8", $d; # Convert to utf unless a known file format | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | $gitHub->readData | |||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | sub write($$;$) # Write the specified data into a file on L<GitHub>.\mRequired attributes: L<userid|/userid>, L<repository|/repository>, L<patKey|/patKey>. Either specify the target file on: L<GitHub> using the L<gitFile|/gitFile> attribute or supply it as the third parameter. Returns B<true> on success else L<undef>. | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | {my ($gitHub, $data, $File) = @_; # GitHub object, data to be written, optionally the name of the file on github | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: not called CC=18 SCAR=57.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | ▶ | unless($data) # No data supplied so delete the file | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | {if ($File) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | {my $file = $gitHub->file; | |||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | $gitHub->file = $File; | |||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | $gitHub->delete; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | $gitHub->file = $file; | |||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | else | ||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | {$gitHub->delete; | |||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | return 'empty'; # Success | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | my $pat = $gitHub->patKey(1); | |||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | my $user = qm $gitHub->userid; $user or confess "userid required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | my $repo = qm $gitHub->repository; $repo or confess "repository required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | my $file = qm($File//$gitHub->gitFile); $file or confess "gitFile required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$File // $gitHub->gitFile
MC/DC0%0/2
$File // $gitHub->gitFile
$File
$gitHub->gitFile
Truth table0%0/3
A // B
A= $FileB= $gitHub->gitFile
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | my $bran = qm $gitHub->refOrBranch(0) || '?'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
&qm(scalar $gitHub->refOrBranch(0)) || '?'
MC/DC0%0/1
&qm(scalar $gitHub->refOrBranch(0)) || '?'
&qm(scalar $gitHub->refOrBranch(0))
Truth table0%0/2
A
A= &qm(scalar $gitHub->refOrBranch(0))
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | my $mess = qm $gitHub->message; | |||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | if (!specialFileData($data)) # Send the data as utf8 unless it is a special file | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 1 | ▶ | {use Encode 'encode'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | $data = encode('UTF-8', $data); | |||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | my $url = url; | |||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | my $save = $gitHub->gitFile; # Save any existing file name as we might need to update it to get the sha if the target file was supplied as a parameter to this sub | |||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | ▶ | $gitHub->gitFile = $File if $File; # Set target file name so we can get its sha | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | my $s = getSha($data); # Get the L<sha> of the file locally | |||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | my $S = $gitHub->getExistingSha || ''; # Get the L<sha> of the file on github | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$gitHub->getExistingSha || ''
MC/DC0%0/1
$gitHub->getExistingSha || ''
$gitHub->getExistingSha
Truth table0%0/2
A
A= $gitHub->getExistingSha
| |||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | $gitHub->gitFile = $save; # Restore file name | |||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | my $sha = $S ? qq(, "sha": "$S") : q(); # L<sha> of existing file to replace if present | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | if ($s eq $S) # Duplicate if the L<sha>s match | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | {$gitHub->failed = undef; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | return "same "; # Matches created and updated | |||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | my $denc = encodeBase64($data) =~ s/\n//gsr; | |||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | my $branch = sub # It seems we must put the branch in the json file though the documentation seems to imply it can go in the url or the json | ||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | {my $b = $gitHub->branch; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | return qq(, "branch" : "$b") if $b; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | q() | |||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | }->(); | |||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | my $j = qq({"message": "$mess", "content": "$denc" $sha $branch}); | |||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | my $t = writeFile(undef, $j); # Write encoded content to temporary file | |||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | my $d = qq(-d @).$t; | |||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | my $u = filePath($url, $user, $repo, qw(contents), $file.$bran); | |||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | my $c = qq(curl -si -X PUT $pat $u $d); # Curl command | |||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | my $r = GitHub::Crud::Response::new($gitHub, $c); # Execute command to create response | |||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | unlink $t; # Cleanup | |||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | my $status = $r->status; # Check response code | |||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | my $success = $status == 200 ? ($S ? 'updated' : 'created') : undef; # Updated, created | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | $gitHub->failed = $success ? undef : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | ▶ | !$success and $gitHub->confessOnFailure and confess dump($gitHub); # Confess to any failure if so requested | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $success and $gitHub->confessOnFailure
MC/DC0%0/2
not $success and $gitHub->confessOnFailure
not $success
$gitHub->confessOnFailure
Truth table0%0/3
not(A) and B
A= not $successB= $gitHub->confessOnFailure
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | $success # Return true on success | |||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | sub readBlob($$) # Read a L<blob> from L<GitHub>.\mRequired attributes: L<userid|/userid>, L<repository|/repository>, L<patKey|/patKey>. Returns the content of the L<blob> identified by the specified L<sha>. | ||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | ▶ | {my ($gitHub, $sha) = @_; # GitHub object, data to be written | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readBlob: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | defined($sha) or confess "sha required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | my $pat = $gitHub->patKey(1); | |||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | my $user = qm $gitHub->userid; $user or confess "userid required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | ▶ | my $repo = qm $gitHub->repository; $repo or confess "repository required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | my $url = url; | |||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | my $u = filePath($url, $user, $repo, qw(git blobs), $sha); # Url | |||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | my $c = qq(curl -si $pat $u); # Curl command | |||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | my $r = GitHub::Crud::Response::new($gitHub, $c); # Execute command to create response | |||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | my $status = $r->status; # Check response code | |||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | my $success = $status == 200; | |||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | $gitHub->failed = $success ? undef : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | ▶ | !$success and $gitHub->confessOnFailure and confess dump($gitHub); # Confess to any failure if so requested | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $success and $gitHub->confessOnFailure
MC/DC0%0/2
not $success and $gitHub->confessOnFailure
not $success
$gitHub->confessOnFailure
Truth table0%0/3
not(A) and B
A= not $successB= $gitHub->confessOnFailure
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | ▶ | $success ? decodeBase64($gitHub->response->data->content) : undef # Return content on success else undef | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | sub writeBlob($$) # Write data into a L<GitHub> as a L<blob> that can be referenced by future commits.\mRequired attributes: L<userid|/userid>, L<repository|/repository>, L<patKey|/patKey>. Returns the L<sha> of the created L<blob> or L<undef> in a failure occurred. | ||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | {my ($gitHub, $data) = @_; # GitHub object, data to be written | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
writeBlob: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | defined($data) or confess "binary data required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | my $pat = $gitHub->patKey(1); | |||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | ▶ | my $user = qm $gitHub->userid; $user or confess "userid required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | my $repo = qm $gitHub->repository; $repo or confess "repository required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | my $url = url; | |||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | my $denc = encodeBase64($data) =~ s/\n//gsr; | |||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | my $t = writeTempFile(qq({"content": "$denc", "encoding" : "base64"})); # Write encoded content to temporary file | |||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | my $d = qq(-d @).$t; | |||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | my $u = filePath($url, $user, $repo, qw(git blobs)); | |||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | my $c = qq(curl -si -X POST $pat $u $d); # Curl command | |||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | my $r = GitHub::Crud::Response::new($gitHub, $c); # Execute command to create response | |||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | unlink $t; # Cleanup | |||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | my $status = $r->status; # Check response code | |||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | ▶ | my $success = $status == 200 ? 'updated' : $status == 201 ? 'created' : undef;# Updated, created | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | ▶ | $gitHub->failed = $success ? undef : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | ▶ | !$success and $gitHub->confessOnFailure and confess dump($gitHub); # Confess to any failure if so requested | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $success and $gitHub->confessOnFailure
MC/DC0%0/2
not $success and $gitHub->confessOnFailure
not $success
$gitHub->confessOnFailure
Truth table0%0/3
not(A) and B
A= not $successB= $gitHub->confessOnFailure
| |||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | ▶ | $success ? $gitHub->response->data->sha : undef # Return sha of blob on success | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||
| 514 | sub copy($$) # Copy a source file from one location to another target location in your L<GitHub> repository, overwriting the target file if it already exists.\mRequired attributes: L<userid|/userid>, L<repository|/repository>, L<patKey|/patKey>, L<gitFile|/gitFile> = the file to be copied.\mOptional attributes: L<refOrBranch|/refOrBranch>.\mIf the write operation is successful, L<failed|/failed> is set to false otherwise it is set to true.\mReturns B<updated> if the write updated the file, B<created> if the write created the file else B<undef> if the write failed. | ||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | ▶ | {my ($gitHub, $target) = @_; # GitHub object, the name of the file to be created | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
copy: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | ▶ | defined($target) or confess "Specify the name of the file to be copied to"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | my $r = $gitHub->read; # Read the content of the source file | |||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | ▶ | if (defined $r) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | {my $file = $gitHub->gitFile; # Save current source file | |||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | my $sha = $gitHub->response->data->sha; # L<sha> of last file read | |||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | $gitHub->gitFile = $target; # Set target file as current file | |||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | my $R = $gitHub->write($r); # Write content to target file | |||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | $gitHub->copySha; # Copy the L<sha> from the file just read | |||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | $gitHub->gitFile = $file; # Restore source file | |||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | return $R; # Return response from write | |||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||
| 527 | undef # Failed | ||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | sub exists($) # Test whether a file exists on L<GitHub> or not and returns an object including the B<sha> and B<size> fields if it does else L<undef>.\mRequired attributes: L<userid|/userid>, L<repository|/repository>, L<gitFile|/gitFile> file to test.\mOptional attributes: L<refOrBranch|/refOrBranch>, L<patKey|/patKey>. | ||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | ▶ | {my ($gitHub) = @_; # GitHub object | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exists: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | my @file = split /\//, $gitHub->gitFile; | |||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | ▶ | confess "gitFile required to name the file to be checked" unless @file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | pop @file; | |||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | my $folder = $gitHub->gitFolder; | |||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | my $nonRecursive = $gitHub->nonRecursive; | |||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | $gitHub->gitFolder = filePath(@file); | |||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | $gitHub->nonRecursive = 1; | |||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | my $r = $gitHub->list; # Get a file listing | |||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | $gitHub->gitFolder = $folder; | |||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | $gitHub->nonRecursive = $nonRecursive; | |||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | ▶ | if (!$gitHub->failed and reftype($gitHub->response->data) =~ m(array)i) # Look for requested file in file listing | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $gitHub->failed and builtin::reftype($gitHub->response->data) =~ /array/iu
MC/DC0%0/2
not $gitHub->failed and builtin::reftype($gitHub->response->data) =~ /array/iu
not $gitHub->failed
builtin::reftype($gitHub->response->data) =~ /array/iu
Truth table0%0/3
not(A) and B
A= not $gitHub->failedB= builtin::reftype($gitHub->response->data) =~ /array/iu
| |||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | {for(@{$gitHub->response->data}) | |||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | ▶ | {return $_ if $_->path eq $gitHub->gitFile; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||||
| 548 | undef | ||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | sub rename($$) # Rename a source file on L<GitHub> if the target file name is not already in use.\mRequired attributes: L<userid|/userid>, L<repository|/repository>, L<patKey|/patKey>, L<gitFile|/gitFile> = the file to be renamed.\mOptional attributes: L<refOrBranch|/refOrBranch>.\mReturns the new name of the file B<renamed> if the rename was successful else B<undef> if the rename failed. | ||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | ▶ | {my ($gitHub, $target) = @_; # GitHub object, the new name of the file | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rename: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | my $file = $gitHub->gitFile; | |||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | $gitHub->gitFile = $target; | |||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | ▶ | return undef if $gitHub->exists; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | $gitHub->gitFile = $file; | |||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | $gitHub->copy($target); | |||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | $gitHub->gitFile = $target; | |||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | ▶ | if ($gitHub->exists) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | {$gitHub->gitFile = $file; | |||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | ▶ | return $target if $gitHub->delete; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | confess "Failed to delete source file $file"; | |||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||
| 564 | undef | ||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | sub delete($) # Delete a file from L<GitHub>.\mRequired attributes: L<userid|/userid>, L<repository|/repository>, L<patKey|/patKey>, L<gitFile|/gitFile> = the file to be deleted.\mOptional attributes: L<refOrBranch|/refOrBranch>.\mIf the delete operation is successful, L<failed|/failed> is set to false otherwise it is set to true.\mReturns true if the delete was successful else false. | ||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | ▶ | {my ($gitHub) = @_; # GitHub object | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | my $pat = $gitHub->patKey(1); | |||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | ▶ | my $user = qm $gitHub->userid; $user or confess "userid required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | ▶ | my $repo = qm $gitHub->repository; $repo or confess "repository required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | ▶ | my $file = qm $gitHub->gitFile; $file or confess "file to delete required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | my $bran = qm $gitHub->refOrBranch(0); | |||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | my $url = url; | |||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | my $s = $gitHub->getExistingSha; # L<sha> of existing file or undef | |||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | ▶ | return 2 unless $s; # File already deleted | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | my $sha = ' -d \'{"message": "", "sha": "'. $s .'"}\''; | |||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | my $u = filePath($url, $user, $repo, qw(contents), $file.$bran.$sha); | |||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | my $d = "curl -si -X DELETE $pat $u"; | |||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | my $r = GitHub::Crud::Response::new($gitHub, $d); | |||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | my $success = $r->status == 200; # Check response code | |||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | ▶ | $gitHub->deleteSha if $success; # The L<sha> is no longer valid | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | ▶ | $gitHub->failed = $success ? undef : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | ▶ | !$success and $gitHub->confessOnFailure and confess dump($gitHub); # Confess to any failure if so requested | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $success and $gitHub->confessOnFailure
MC/DC0%0/2
not $success and $gitHub->confessOnFailure
not $success
$gitHub->confessOnFailure
Truth table0%0/3
not(A) and B
A= not $successB= $gitHub->confessOnFailure
| |||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | ▶ | $success ? 1 : undef # Return true on success | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||
| 590 | #D1 Repositories # Perform actions on L<github> repositories. | ||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||
| 592 | sub getRepository($) # Get the overall details of a repository | ||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | ▶ | {my ($gitHub) = @_; # GitHub object | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getRepository: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | my $pat = $gitHub->patKey(1); | |||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | ▶ | my $user = qm $gitHub->userid; $user or confess "userid required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | ▶ | my $repo = qm $gitHub->repository; $repo or confess "repository required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | my $url = url; | |||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | my $c = qq(curl -si $pat $url/$user/$repo); | |||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | my $r = GitHub::Crud::Response::new($gitHub, $c); | |||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | my $success = $r->status == 200; # Check response code | |||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | ▶ | !$success and $gitHub->confessOnFailure and confess dump([$gitHub, $c]); # Confess to any failure if so requested | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $success and $gitHub->confessOnFailure
MC/DC0%0/2
not $success and $gitHub->confessOnFailure
not $success
$gitHub->confessOnFailure
Truth table0%0/3
not(A) and B
A= not $successB= $gitHub->confessOnFailure
| |||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | $r | |||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | sub listCommits($) # List all the commits in a L<GitHub> repository.\mRequired attributes: L<userid|/userid>, L<repository|/repository>. | ||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | ▶ | {my ($gitHub) = @_; # GitHub object | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
listCommits: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | my $pat = $gitHub->patKey(1); | |||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | ▶ | my $user = qm $gitHub->userid; $user or confess "userid required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | ▶ | my $repo = qm $gitHub->repository; $repo or confess "repository required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | my $url = url; | |||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | my $c = qq(curl -si $pat $url/$user/$repo/branches); | |||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | my $r = GitHub::Crud::Response::new($gitHub, $c); | |||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | my $success = $r->status == 200; # Check response code | |||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | ▶ | !$success and $gitHub->confessOnFailure and confess dump($gitHub); # Confess to any failure if so requested | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $success and $gitHub->confessOnFailure
MC/DC0%0/2
not $success and $gitHub->confessOnFailure
not $success
$gitHub->confessOnFailure
Truth table0%0/3
not(A) and B
A= not $successB= $gitHub->confessOnFailure
| |||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | $r | |||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||
| 625 | sub listCommitShas($) # Create {commit name => sha} from the results of L</listCommits>. | ||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | ▶ | {my ($commits) = @_; # Commits from L</listCommits> | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
listCommitShas: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | ▶ | return undef unless my $data = $commits->data; # Commits array | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | {map {$$_{name} => $$_{commit}{sha}} @$data} # Commits hash | |||||||||||||||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||
| 632 | sub writeCommit($$@) # Write all the files in a B<$folder> (or just the the named files) into a L<GitHub> repository in parallel as a commit on the specified branch.\mRequired attributes: L<userid|/userid>, L<repository|/repository>, L<refOrBranch|/refOrBranch>. | ||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | ▶ | {my ($gitHub, $folder, @files) = @_; # GitHub object, file prefix to remove, files to write | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
writeCommit: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | ▶ | -d $folder or confess "No such folder"; # Folder does not exist | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | my $pat = $gitHub->patKey(1); | |||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | ▶ | my $user = qm $gitHub->userid; $user or confess "userid required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | ▶ | my $repo = qm $gitHub->repository; $repo or confess "repository required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | ▶ | my $bran = $gitHub->branch; $bran or confess "branch required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | my $url = url; | |||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||
| 643 | my @sha = processFilesInParallel sub # Create blobs for each file | ||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | ▶ | {my ($source) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | my $target = $gitHub->gitFile = swapFilePrefix($source, $folder); | |||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | [$source, $target, $gitHub->writeBlob(readBinaryFile($source))] | |||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | ▶ | }, undef, @files ? @files : searchDirectoryTreesForMatchingFiles($folder); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||
| 649 | my $tree = sub # Create the tree | ||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | ▶ | {my @t; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | for my $f(@sha) # Load files into a tree | |||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | {my ($s, $t, $b) = @$f; | |||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | push @t, <<END; | |||||||||||||||||||||||||||||||||||||||||
| 654 | {"path" : "$t", | ||||||||||||||||||||||||||||||||||||||||||
| 655 | "mode" : "100644", | ||||||||||||||||||||||||||||||||||||||||||
| 656 | "type" : "blob", | ||||||||||||||||||||||||||||||||||||||||||
| 657 | "sha" : "$b" | ||||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||
| 659 | END | ||||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | my $t = join ",\n", @t; # Assemble tree | |||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | my $j = qq({"tree" : [$t]}); # Json describing tree | |||||||||||||||||||||||||||||||||||||||||
| 664 | 0 | my $f = writeTempFile($j); # Write Json | |||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | my $c = qq(curl -si -X POST $pat -d \@$f $url/$user/$repo/git/trees); | |||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | my $r = GitHub::Crud::Response::new($gitHub, $c); | |||||||||||||||||||||||||||||||||||||||||
| 668 | 0 | my $success = $r->status == 201; # Check response code | |||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | unlink $f; # Cleanup | |||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | ▶ | $success or confess "Unable to create tree: ".dump($r); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | $r | |||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | }->(); | |||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||
| 676 | my $parents = sub # Prior commits | ||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | ▶ | {my %c = listCommitShas $gitHub->listCommits; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | my $b = $gitHub->branch; | |||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | ▶ | return '' unless my $s = $c{$b}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | qq(, "parents" : ["$s"]) | |||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | }->(); | |||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||
| 683 | my $commit = sub # Create a commit to hold the tree | ||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | ▶ | {my $s = $tree->data->sha; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | my $d = dateTimeStamp; | |||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | my $j = <<END; | |||||||||||||||||||||||||||||||||||||||||
| 687 | { "message" : "Committed by GitHub::Crud on: $d" | ||||||||||||||||||||||||||||||||||||||||||
| 688 | , "tree" : "$s" | ||||||||||||||||||||||||||||||||||||||||||
| 689 | $parents | ||||||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||||
| 691 | END | ||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | my $f = writeFile(undef, $j); # Write json | |||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | my $c = qq(curl -si -X POST $pat -d \@$f $url/$user/$repo/git/commits); # Execute json | |||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | my $r = GitHub::Crud::Response::new($gitHub, $c); | |||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | my $success = $r->status == 201; # Check response code | |||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | unlink $f; # Cleanup | |||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | ▶ | $success or confess "Unable to create commit: ".dump($r); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | $r | |||||||||||||||||||||||||||||||||||||||||
| 703 | 0 | }->(); | |||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||
| 705 | my $branch = sub # Update branch - if this fails we will try a force as the next step | ||||||||||||||||||||||||||||||||||||||||||
| 706 | 0 | ▶ | {my $s = $commit->data->sha; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | my $f = writeFile(undef, <<END); | |||||||||||||||||||||||||||||||||||||||||
| 708 | { | ||||||||||||||||||||||||||||||||||||||||||
| 709 | "ref": "refs/heads/$bran", | ||||||||||||||||||||||||||||||||||||||||||
| 710 | "sha": "$s" | ||||||||||||||||||||||||||||||||||||||||||
| 711 | } | ||||||||||||||||||||||||||||||||||||||||||
| 712 | END | ||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | my $c = qq(curl -si -X POST $pat -d \@$f $url/$user/$repo/git/refs); | |||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | my $r = GitHub::Crud::Response::new($gitHub, $c); | |||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | my $success = $r->status == 201; # Check response code | |||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | unlink $f; # Cleanup | |||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | $r | |||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | }->(); | |||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | my $status = $branch->status; # Creation status | |||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | ▶ | if ($branch->status == 201) {return $branch} # Branch created | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 723 | elsif ($branch->status == 422) # Update existing branch | ||||||||||||||||||||||||||||||||||||||||||
| 724 | {my $branchUpdate = sub | ||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | ▶ | {my $s = $commit->data->sha; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 726 | 0 | my $f = writeFile(undef, <<END); | |||||||||||||||||||||||||||||||||||||||||
| 727 | { "sha": "$s", | ||||||||||||||||||||||||||||||||||||||||||
| 728 | "force": true | ||||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||
| 730 | END | ||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | my $c = qq(curl -si -X PATCH $pat -d \@$f $url/$user/$repo/git/refs/heads/$bran); | |||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | my $r = GitHub::Crud::Response::new($gitHub, $c); | |||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | my $success = $r->status == 200; # Check response code | |||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | unlink $f; # Cleanup | |||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | ▶ | $success or confess "Unable to update branch: ".dump($r); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | $r | |||||||||||||||||||||||||||||||||||||||||
| 739 | 0 | }->(); | |||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | return $branchUpdate; | |||||||||||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | confess "Unable to create/update branch: $bran"; | |||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||
| 746 | sub listWebHooks($) # List web hooks associated with your L<GitHub> repository.\mRequired: L<userid|/userid>, L<repository|/repository>, L<patKey|/patKey>. \mIf the list operation is successful, L<failed|/failed> is set to false otherwise it is set to true.\mReturns true if the list operation was successful else false. | ||||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | ▶ | {my ($gitHub) = @_; # GitHub object | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
listWebHooks: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 748 | 0 | my $pat = $gitHub->patKey(1); | |||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | ▶ | my $user = qm $gitHub->userid; $user or confess "userid required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | ▶ | my $repo = qm $gitHub->repository; $repo or confess "repository required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 751 | 0 | my $bran = qm $gitHub->refOrBranch(0); | |||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | my $url = url; | |||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||
| 754 | 0 | my $u = filePath($url, $user, $repo, qw(hooks)); | |||||||||||||||||||||||||||||||||||||||||
| 755 | 0 | my $s = "curl -si $pat $u"; | |||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | my $r = GitHub::Crud::Response::new($gitHub, $s); | |||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | my $success = $r->status =~ m(200|201); # Present or not present | |||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | ▶ | $gitHub->failed = $success ? undef : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 759 | 0 | ▶ | !$success and $gitHub->confessOnFailure and confess dump($gitHub); # Confess to any failure if so requested | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $success and $gitHub->confessOnFailure
MC/DC0%0/2
not $success and $gitHub->confessOnFailure
not $success
$gitHub->confessOnFailure
Truth table0%0/3
not(A) and B
A= not $successB= $gitHub->confessOnFailure
| |||||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | ▶ | $success ? $gitHub->response->data : undef # Return reference to array of web hooks on success. If there are no web hooks set then the referenced array will be empty. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||
| 763 | sub createPushWebHook($) # Create a web hook for your L<GitHub> userid.\mRequired: L<userid|/userid>, L<repository|/repository>, L<url|/url>, L<patKey|/patKey>.\mOptional: L<secret|/secret>.\mIf the create operation is successful, L<failed|/failed> is set to false otherwise it is set to true.\mReturns true if the web hook was created successfully else false. | ||||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | ▶ | {my ($gitHub) = @_; # GitHub object | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
createPushWebHook: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | my $pat = $gitHub->patKey(1); | |||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | ▶ | my $user = qm $gitHub->userid; $user or confess "userid required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | ▶ | my $repo = qm $gitHub->repository; $repo or confess "repository required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | ▶ | my $webUrl = qm $gitHub->webHookUrl; $webUrl or confess "url required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | my $bran = qm $gitHub->refOrBranch(0); | |||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | my $secret = $gitHub->secret; | |||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | ▶ | my $sj = $secret ? qq(, "secret": "$secret") : ''; # Secret for Json | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 772 | 0 | my $url = url; | |||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | ▶ | $webUrl =~ m(\Ahttps?://) or confess # Check that we are using a url like thing for the web hook or complain | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 775 | "Web hook has no scheme, should start with https?:// not:\n$webUrl"; | ||||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||
| 777 | 0 | owf(my $tmpFile = temporaryFile(), my $json = <<END); # Write web hook definition | |||||||||||||||||||||||||||||||||||||||||
| 778 | {"name": "web", "active": true, "events": ["push"], | ||||||||||||||||||||||||||||||||||||||||||
| 779 | "config": {"url": "$webUrl", "content_type": "json" $sj} | ||||||||||||||||||||||||||||||||||||||||||
| 780 | } | ||||||||||||||||||||||||||||||||||||||||||
| 781 | END | ||||||||||||||||||||||||||||||||||||||||||
| 782 | 0 | my $d = q( -d @).$tmpFile; | |||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | my $u = filePath($url, $user, $repo, qw(hooks)); | |||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | my $s = "curl -si -X POST $pat $u $d"; # Create url | |||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | my $r = GitHub::Crud::Response::new($gitHub, $s); | |||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | my $success = $r->status == 201; # Check response code | |||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | unlink $tmpFile; # Cleanup | |||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | ▶ | $gitHub->failed = $success ? undef : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 790 | 0 | ▶ | !$success and $gitHub->confessOnFailure and confess dump($gitHub); # Confess to any failure if so requested | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $success and $gitHub->confessOnFailure
MC/DC0%0/2
not $success and $gitHub->confessOnFailure
not $success
$gitHub->confessOnFailure
Truth table0%0/3
not(A) and B
A= not $successB= $gitHub->confessOnFailure
| |||||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | ▶ | $success ? 1 : undef # Return true on success | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 792 | } | ||||||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||||||
| 794 | sub listRepositories($) # List the repositories accessible to a user on L<GitHub>.\mRequired: L<userid|/userid>.\mReturns details of the repositories. | ||||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | ▶ | {my ($gitHub) = @_; # GitHub object | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
listRepositories: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||
| 797 | 0 | my $pat = $gitHub->patKey(1); | |||||||||||||||||||||||||||||||||||||||||
| 798 | 0 | ▶ | my $user = qm $gitHub->userid; $user or confess "userid required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | my $url = api; | |||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | my $u = filePath($url, qw(user repos)); # Request url | |||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | my $s = "curl -si $pat $u"; # Create url | |||||||||||||||||||||||||||||||||||||||||
| 803 | 0 | my $r = GitHub::Crud::Response::new($gitHub, $s); | |||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | my $success = $r->status == 200; # Check response code | |||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | ▶ | $gitHub->failed = $success ? undef : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 806 | 0 | ▶ | !$success and $gitHub->confessOnFailure and confess dump($gitHub); # Confess to any failure if so requested | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $success and $gitHub->confessOnFailure
MC/DC0%0/2
not $success and $gitHub->confessOnFailure
not $success
$gitHub->confessOnFailure
Truth table0%0/3
not(A) and B
A= not $successB= $gitHub->confessOnFailure
| |||||||||||||||||||||||||||||||||||||||||||
| 807 | 0 | ▶ | $success ? $r->data->@* : undef # Return a list of repositories on success | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||
| 810 | sub createRepository($) # Create a repository on L<GitHub>.\mRequired: L<userid|/userid>, L<repository|/repository>.\mReturns true if the issue was created successfully else false. | ||||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | ▶ | {my ($gitHub) = @_; # GitHub object | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
createRepository: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | my $pat = $gitHub->patKey(1); | |||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | ▶ | my $user = qm $gitHub->userid; $user or confess "userid required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 814 | 0 | ▶ | my $repo = qm $gitHub->repository; $repo or confess "repository required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 815 | 0 | ▶ | my $private= $gitHub->private ? q(, "private":true) : q(); # Private or not | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | my $url = api; | |||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||
| 818 | 0 | my $json = qq({"name":"$repo", "auto_init":true $private}); # Issue in json | |||||||||||||||||||||||||||||||||||||||||
| 819 | 0 | my $tmpFile = writeFile(undef, $json); # Write repo definition | |||||||||||||||||||||||||||||||||||||||||
| 820 | 0 | my $d = q( -d @).$tmpFile; | |||||||||||||||||||||||||||||||||||||||||
| 821 | 0 | my $u = filePath($url, qw(user repos)); # Request url | |||||||||||||||||||||||||||||||||||||||||
| 822 | 0 | my $s = "curl -si -X POST $pat $u $d"; # Create url | |||||||||||||||||||||||||||||||||||||||||
| 823 | 0 | my $r = GitHub::Crud::Response::new($gitHub, $s); | |||||||||||||||||||||||||||||||||||||||||
| 824 | 0 | my $success = $r->status == 201; # Check response code | |||||||||||||||||||||||||||||||||||||||||
| 825 | 0 | unlink $tmpFile; # Cleanup | |||||||||||||||||||||||||||||||||||||||||
| 826 | 0 | ▶ | $gitHub->failed = $success ? undef : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 827 | 0 | ▶ | !$success and $gitHub->confessOnFailure and confess dump($gitHub); # Confess to any failure if so requested | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $success and $gitHub->confessOnFailure
MC/DC0%0/2
not $success and $gitHub->confessOnFailure
not $success
$gitHub->confessOnFailure
Truth table0%0/3
not(A) and B
A= not $successB= $gitHub->confessOnFailure
| |||||||||||||||||||||||||||||||||||||||||||
| 828 | 0 | ▶ | $success ? 1 : undef # Return true on success | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 829 | } | ||||||||||||||||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||||||||||||||||
| 831 | sub createRepositoryFromSavedToken($$;$$) # Create a repository on L<GitHub> using an access token either as supplied or saved in a file using L<savePersonalAccessToken|/savePersonalAccessToken>.\mReturns true if the issue was created successfully else false. | ||||||||||||||||||||||||||||||||||||||||||
| 832 | 0 | ▶ | {my ($userid, $repository, $private, $accessFolderOrToken) = @_; # Userid on GitHub, the repository name, true if the repo is private, location of access token. | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
createRepositoryFromSavedToken: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 833 | 0 | my $g = GitHub::Crud::new; | |||||||||||||||||||||||||||||||||||||||||
| 834 | 0 | $g->userid = $userid; | |||||||||||||||||||||||||||||||||||||||||
| 835 | 0 | $g->repository = $repository; | |||||||||||||||||||||||||||||||||||||||||
| 836 | 0 | $g->private = $private; | |||||||||||||||||||||||||||||||||||||||||
| 837 | 0 | $g->personalAccessTokenFolder = $accessFolderOrToken; | |||||||||||||||||||||||||||||||||||||||||
| 838 | 0 | $g->loadPersonalAccessToken; | |||||||||||||||||||||||||||||||||||||||||
| 839 | 0 | $g->confessOnFailure = 0; | |||||||||||||||||||||||||||||||||||||||||
| 840 | 0 | $g->createRepository; | |||||||||||||||||||||||||||||||||||||||||
| 841 | } | ||||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||
| 843 | #D1 Issues # Create issues on L<GitHub>. | ||||||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||||||
| 845 | sub createIssue($) # Create an issue on L<GitHub>.\mRequired: L<userid|/userid>, L<repository|/repository>, L<body|/body>, L<title|/title>.\mIf the operation is successful, L<failed|/failed> is set to false otherwise it is set to true.\mReturns true if the issue was created successfully else false. | ||||||||||||||||||||||||||||||||||||||||||
| 846 | 0 | ▶ | {my ($gitHub) = @_; # GitHub object | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
createIssue: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 847 | 0 | my $pat = $gitHub->patKey(1); | |||||||||||||||||||||||||||||||||||||||||
| 848 | 0 | ▶ | my $user = qm $gitHub->userid; $user or confess "userid required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 849 | 0 | ▶ | my $repo = qm $gitHub->repository; $repo or confess "repository required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | ▶ | my $body = $gitHub->body; $body or confess "body required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | ▶ | my $title = $gitHub->title; $title or confess "title required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 852 | 0 | my $bran = qm $gitHub->refOrBranch(0); | |||||||||||||||||||||||||||||||||||||||||
| 853 | 0 | my $url = url; | |||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||
| 855 | 0 | my $json = encodeJson({body=>$body, title=>$title}); # Issue in json | |||||||||||||||||||||||||||||||||||||||||
| 856 | 0 | owf(my $tmpFile = temporaryFile(), $json); # Write issue definition | |||||||||||||||||||||||||||||||||||||||||
| 857 | 0 | my $d = q( -d @).$tmpFile; | |||||||||||||||||||||||||||||||||||||||||
| 858 | 0 | my $u = filePath($url, $user, $repo, qw(issues)); | |||||||||||||||||||||||||||||||||||||||||
| 859 | 0 | my $s = "curl -si -X POST $pat $u $d"; # Create url | |||||||||||||||||||||||||||||||||||||||||
| 860 | 0 | my $r = GitHub::Crud::Response::new($gitHub, $s); | |||||||||||||||||||||||||||||||||||||||||
| 861 | 0 | my $success = $r->status == 201; # Check response code | |||||||||||||||||||||||||||||||||||||||||
| 862 | 0 | unlink $tmpFile; # Cleanup | |||||||||||||||||||||||||||||||||||||||||
| 863 | 0 | ▶ | $gitHub->failed = $success ? undef : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 864 | 0 | ▶ | !$success and $gitHub->confessOnFailure and # Confess to any failure if so requested | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $success and $gitHub->confessOnFailure
MC/DC0%0/2
not $success and $gitHub->confessOnFailure
not $success
$gitHub->confessOnFailure
Truth table0%0/3
not(A) and B
A= not $successB= $gitHub->confessOnFailure
| |||||||||||||||||||||||||||||||||||||||||||
| 865 | confess join "\n", dump($gitHub), $json, $s; | ||||||||||||||||||||||||||||||||||||||||||
| 866 | 0 | ▶ | $success ? 1 : undef # Return true on success | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 867 | } | ||||||||||||||||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||||||||||||||||
| 869 | #D1 Using saved access tokens # Call methods directly using a saved access token rather than first creating a L<GitHub> description object and then calling methods using it. This is often more convenient if you just want to perform one or two actions using a L<perl> one liner. See: L<https://github.com/philiprbrenan/GitHubCrud/blob/main/.github/workflows/main.yml> for examples in action. | ||||||||||||||||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||||||||||||||||
| 871 | sub createIssueFromSavedToken($$$$;$) # Create an issue on L<GitHub> using an access token as supplied or saved in a file using L<savePersonalAccessToken|/savePersonalAccessToken>.\mReturns true if the issue was created successfully else false. | ||||||||||||||||||||||||||||||||||||||||||
| 872 | 0 | ▶ | {my ($userid, $repository, $title, $body, $accessFolderOrToken) = @_; # Userid on GitHub, repository name, issue title, issue body, location of access token. | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
createIssueFromSavedToken: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 873 | 0 | my $g = GitHub::Crud::new; | |||||||||||||||||||||||||||||||||||||||||
| 874 | 0 | $g->userid = $userid; | |||||||||||||||||||||||||||||||||||||||||
| 875 | 0 | $g->repository = $repository; | |||||||||||||||||||||||||||||||||||||||||
| 876 | 0 | $g->title = $title; | |||||||||||||||||||||||||||||||||||||||||
| 877 | 0 | $g->body = $body; | |||||||||||||||||||||||||||||||||||||||||
| 878 | 0 | $g->personalAccessTokenFolder = $accessFolderOrToken; | |||||||||||||||||||||||||||||||||||||||||
| 879 | 0 | $g->loadPersonalAccessToken; | |||||||||||||||||||||||||||||||||||||||||
| 880 | 0 | $g->confessOnFailure = 1; | |||||||||||||||||||||||||||||||||||||||||
| 881 | 0 | $g->createIssue; | |||||||||||||||||||||||||||||||||||||||||
| 882 | } | ||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||
| 884 | sub writeFileUsingSavedToken($$$$;$) # Write to a file on L<GitHub> using a personal access token as supplied or saved in a file. Return B<1> on success or confess to any failure. | ||||||||||||||||||||||||||||||||||||||||||
| 885 | 0 | ▶ | {my ($userid, $repository, $file, $content, $accessFolderOrToken) = @_; # Userid on GitHub, repository name, file name on github, file content, location of access token. | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
writeFileUsingSavedToken: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 886 | 0 | my $g = GitHub::Crud::new; | |||||||||||||||||||||||||||||||||||||||||
| 887 | 0 | ▶ | $g->userid = $userid; $userid or confess "Userid required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 888 | 0 | ▶ | $g->repository = $repository; $repository or confess "Repository required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 889 | 0 | ▶ | $g->gitFile = $file; $file or confess "File required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 890 | 0 | $g->personalAccessTokenFolder = $accessFolderOrToken; | |||||||||||||||||||||||||||||||||||||||||
| 891 | 0 | $g->loadPersonalAccessToken; | |||||||||||||||||||||||||||||||||||||||||
| 892 | 0 | $g->write($content); | |||||||||||||||||||||||||||||||||||||||||
| 893 | } | ||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||
| 895 | sub writeFileFromFileUsingSavedToken($$$$;$) # Copy a file to L<GitHub> using a personal access token as supplied or saved in a file. Return B<1> on success or confess to any failure. | ||||||||||||||||||||||||||||||||||||||||||
| 896 | 0 | ▶ | {my ($userid, $repository, $file, $localFile, $accessFolderOrToken) = @_; # Userid on GitHub, repository name, file name on github, file content, location of access token. | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
writeFileFromFileUsingSavedToken: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 897 | 0 | writeFileUsingSavedToken($userid, $repository, $file, | |||||||||||||||||||||||||||||||||||||||||
| 898 | readBinaryFile($localFile), $accessFolderOrToken); | ||||||||||||||||||||||||||||||||||||||||||
| 899 | } | ||||||||||||||||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||||||||||||||||
| 901 | sub readFileUsingSavedToken($$$;$) # Read from a file on L<GitHub> using a personal access token as supplied or saved in a file. Return the content of the file on success or confess to any failure. | ||||||||||||||||||||||||||||||||||||||||||
| 902 | 0 | ▶ | {my ($userid, $repository, $file, $accessFolderOrToken) = @_; # Userid on GitHub, repository name, file name on GitHub, location of access token. | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readFileUsingSavedToken: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 903 | 0 | my $g = GitHub::Crud::new; | |||||||||||||||||||||||||||||||||||||||||
| 904 | 0 | $g->userid = $userid; | |||||||||||||||||||||||||||||||||||||||||
| 905 | 0 | $g->repository = $repository; | |||||||||||||||||||||||||||||||||||||||||
| 906 | 0 | $g->gitFile = $file; | |||||||||||||||||||||||||||||||||||||||||
| 907 | 0 | $g->personalAccessTokenFolder = $accessFolderOrToken; | |||||||||||||||||||||||||||||||||||||||||
| 908 | 0 | $g->loadPersonalAccessToken; | |||||||||||||||||||||||||||||||||||||||||
| 909 | 0 | $g->read; | |||||||||||||||||||||||||||||||||||||||||
| 910 | } | ||||||||||||||||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||||||||||||||||
| 912 | sub writeFolderUsingSavedToken($$$$;$) # Write all the files in a local folder to a target folder on a named L<GitHub> repository using a personal access token as supplied or saved in a file. | ||||||||||||||||||||||||||||||||||||||||||
| 913 | 0 | ▶ | {my ($userid,$repository,$targetFolder,$localFolder,$accessFolderOrToken) = @_;# Userid on GitHub, repository name, target folder on GitHub, local folder name, location of access token. | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
writeFolderUsingSavedToken: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 914 | 0 | my $g = GitHub::Crud::new; | |||||||||||||||||||||||||||||||||||||||||
| 915 | 0 | $g->userid = $userid; | |||||||||||||||||||||||||||||||||||||||||
| 916 | 0 | $g->repository = $repository; | |||||||||||||||||||||||||||||||||||||||||
| 917 | 0 | $g->personalAccessTokenFolder = $accessFolderOrToken; | |||||||||||||||||||||||||||||||||||||||||
| 918 | 0 | $g->loadPersonalAccessToken; | |||||||||||||||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||||||||||||||||
| 920 | 0 | my @r; | |||||||||||||||||||||||||||||||||||||||||
| 921 | 0 | for my $file(searchDirectoryTreesForMatchingFiles($localFolder)) | |||||||||||||||||||||||||||||||||||||||||
| 922 | 0 | {$g->gitFile = swapFilePrefix($file, $localFolder, $targetFolder); | |||||||||||||||||||||||||||||||||||||||||
| 923 | 0 | push @r, [$g->write(readBinaryFile($file)), $file]; | |||||||||||||||||||||||||||||||||||||||||
| 924 | } | ||||||||||||||||||||||||||||||||||||||||||
| 925 | @r | ||||||||||||||||||||||||||||||||||||||||||
| 926 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||||||||||||||||
| 928 | sub writeCommitUsingSavedToken($$$;$) # Write all the files in a local folder to a named L<GitHub> repository using a personal access token as supplied or saved in a file. | ||||||||||||||||||||||||||||||||||||||||||
| 929 | 0 | ▶ | {my ($userid, $repository, $source, $accessFolderOrToken) = @_; # Userid on GitHub, repository name, local folder on GitHub, optionally: location of access token. | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
writeCommitUsingSavedToken: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 930 | 0 | my $g = GitHub::Crud::new; | |||||||||||||||||||||||||||||||||||||||||
| 931 | 0 | $g->userid = $userid; | |||||||||||||||||||||||||||||||||||||||||
| 932 | 0 | $g->repository = $repository; | |||||||||||||||||||||||||||||||||||||||||
| 933 | 0 | $g->personalAccessTokenFolder = $accessFolderOrToken; | |||||||||||||||||||||||||||||||||||||||||
| 934 | 0 | $g->loadPersonalAccessToken; | |||||||||||||||||||||||||||||||||||||||||
| 935 | 0 | $g->branch = 'master'; | |||||||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||||||||
| 937 | 0 | $g->writeCommit($source); | |||||||||||||||||||||||||||||||||||||||||
| 938 | } | ||||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||
| 940 | sub deleteFileUsingSavedToken($$$;$) # Delete a file on L<GitHub> using a saved token | ||||||||||||||||||||||||||||||||||||||||||
| 941 | 0 | ▶ | {my ($userid, $repository, $target, $accessFolderOrToken) = @_; # Userid on GitHub, repository name, file on GitHub, optional: the folder containing saved access tokens. | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deleteFileUsingSavedToken: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 942 | 0 | my $g = GitHub::Crud::new; | |||||||||||||||||||||||||||||||||||||||||
| 943 | 0 | $g->userid = $userid; | |||||||||||||||||||||||||||||||||||||||||
| 944 | 0 | $g->repository = $repository; | |||||||||||||||||||||||||||||||||||||||||
| 945 | 0 | $g->personalAccessTokenFolder = $accessFolderOrToken; | |||||||||||||||||||||||||||||||||||||||||
| 946 | 0 | $g->loadPersonalAccessToken; | |||||||||||||||||||||||||||||||||||||||||
| 947 | |||||||||||||||||||||||||||||||||||||||||||
| 948 | 0 | $g->gitFile = $target; | |||||||||||||||||||||||||||||||||||||||||
| 949 | 0 | $g->delete; | |||||||||||||||||||||||||||||||||||||||||
| 950 | } | ||||||||||||||||||||||||||||||||||||||||||
| 951 | |||||||||||||||||||||||||||||||||||||||||||
| 952 | sub getRepositoryUsingSavedToken($$;$) # Get repository details from L<GitHub> using a saved token | ||||||||||||||||||||||||||||||||||||||||||
| 953 | 0 | ▶ | {my ($userid, $repository, $accessFolderOrToken) = @_; # Userid on GitHub, repository name, optionally: location of access token. | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getRepositoryUsingSavedToken: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 954 | 0 | my $g = GitHub::Crud::new; | |||||||||||||||||||||||||||||||||||||||||
| 955 | 0 | ▶ | $g->userid = $userid; $userid or confess "Userid required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 956 | 0 | ▶ | $g->repository = $repository; $repository or confess "Repository required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 957 | 0 | $g->personalAccessTokenFolder = $accessFolderOrToken; | |||||||||||||||||||||||||||||||||||||||||
| 958 | 0 | $g->loadPersonalAccessToken; | |||||||||||||||||||||||||||||||||||||||||
| 959 | 0 | $g->getRepository; | |||||||||||||||||||||||||||||||||||||||||
| 960 | } | ||||||||||||||||||||||||||||||||||||||||||
| 961 | |||||||||||||||||||||||||||||||||||||||||||
| 962 | sub listRepositoryUsingSavedToken($$;$) # List the files in a repository using a saved token | ||||||||||||||||||||||||||||||||||||||||||
| 963 | 0 | ▶ | {my ($userid, $repository, $accessFolderOrToken) = @_; # Userid on GitHub, repository name, optionally: location of access token. | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
listRepositoryUsingSavedToken: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 964 | 0 | my $g = GitHub::Crud::new; | |||||||||||||||||||||||||||||||||||||||||
| 965 | 0 | ▶ | $g->userid = $userid; $userid or confess "Userid required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 966 | 0 | ▶ | $g->repository = $repository; $repository or confess "Repository required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 967 | 0 | $g->personalAccessTokenFolder = $accessFolderOrToken; | |||||||||||||||||||||||||||||||||||||||||
| 968 | 0 | $g->loadPersonalAccessToken; | |||||||||||||||||||||||||||||||||||||||||
| 969 | 0 | $g->list; | |||||||||||||||||||||||||||||||||||||||||
| 970 | } | ||||||||||||||||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||||||||||||||||
| 972 | sub getRepositoryUpdatedAtUsingSavedToken($$;$) # Get the last time a repository was updated via the 'updated_at' field using a saved token and return the time in number of seconds since the Unix epoch. | ||||||||||||||||||||||||||||||||||||||||||
| 973 | 0 | ▶ | {my ($userid, $repository, $accessFolderOrToken) = @_; # Userid on GitHub, repository name, optionally: location of access token. | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getRepositoryUpdatedAtUsingSavedToken: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 974 | 0 | my $r = &getRepositoryUsingSavedToken(@_); # Get repository details using a saved token | |||||||||||||||||||||||||||||||||||||||||
| 975 | 0 | my $u = $r->data->{updated_at}; | |||||||||||||||||||||||||||||||||||||||||
| 976 | 0 | return Date::Manip::UnixDate($u,'%s'); | |||||||||||||||||||||||||||||||||||||||||
| 977 | } | ||||||||||||||||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||||||||||||||||
| 979 | #D1 Actions # Perform an action against the current repository while running as a L<GitHub> action. If such an action requires a security token please supply the token as shown in at the end of: L<https://github.com/philiprbrenan/maze/blob/main/.github/workflows/main.yml>. | ||||||||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||||||||
| 981 | sub currentRepo() #P Create a L<GitHub> object for the current repo if we are on L<GitHub> actions | ||||||||||||||||||||||||||||||||||||||||||
| 982 | 0 | ▶ | {if (my $r = $ENV{GITHUB_REPOSITORY}) # We are on GitHub | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
currentRepo: not called CC=3 SCAR=24.8
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 983 | 0 | {my ($user, $repo) = split m(/), $r, 2; | |||||||||||||||||||||||||||||||||||||||||
| 984 | 0 | my $g = GitHub::Crud::new; | |||||||||||||||||||||||||||||||||||||||||
| 985 | 0 | $g->userid = $user; | |||||||||||||||||||||||||||||||||||||||||
| 986 | 0 | $g->repository = $repo; | |||||||||||||||||||||||||||||||||||||||||
| 987 | 0 | $g->personalAccessToken = $ENV{GITHUB_TOKEN}; | |||||||||||||||||||||||||||||||||||||||||
| 988 | 0 | $g->confessOnFailure = 1; | |||||||||||||||||||||||||||||||||||||||||
| 989 | |||||||||||||||||||||||||||||||||||||||||||
| 990 | 0 | ▶ | if (!$g->personalAccessToken) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 991 | 0 | {confess "Unable to load github token for repository $r from environment variable: GITHUB_TOKEN\nSee: https://github.com/philiprbrenan/postgres/blob/main/.github/workflows/main.yml"; | |||||||||||||||||||||||||||||||||||||||||
| 992 | } | ||||||||||||||||||||||||||||||||||||||||||
| 993 | |||||||||||||||||||||||||||||||||||||||||||
| 994 | 0 | return $g; | |||||||||||||||||||||||||||||||||||||||||
| 995 | } | ||||||||||||||||||||||||||||||||||||||||||
| 996 | undef | ||||||||||||||||||||||||||||||||||||||||||
| 997 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 998 | |||||||||||||||||||||||||||||||||||||||||||
| 999 | sub createIssueInCurrentRepo($$) # Create an issue in the current L<GitHub> repository if we are running on L<GitHub>. | ||||||||||||||||||||||||||||||||||||||||||
| 1000 | 0 | ▶ | {my ($title, $body) = @_; # Title of issue, body of issue | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
createIssueInCurrentRepo: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1001 | 0 | ▶ | if (my $g = currentRepo) # We are on GitHub | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1002 | 0 | {$g->title = $title; | |||||||||||||||||||||||||||||||||||||||||
| 1003 | 0 | $g->body = $body; | |||||||||||||||||||||||||||||||||||||||||
| 1004 | 0 | $g->createIssue; | |||||||||||||||||||||||||||||||||||||||||
| 1005 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1006 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1007 | |||||||||||||||||||||||||||||||||||||||||||
| 1008 | sub writeFileFromCurrentRun($$) # Write text into a file in the current L<GitHub> repository if we are running on L<GitHub>. | ||||||||||||||||||||||||||||||||||||||||||
| 1009 | 0 | ▶ | {my ($target, $text) = @_; # The target file name in the repo, the text to write into this file | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
writeFileFromCurrentRun: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1010 | 0 | ▶ | if (my $g = currentRepo) # We are on GitHub | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1011 | 0 | {$g->gitFile = $target; | |||||||||||||||||||||||||||||||||||||||||
| 1012 | 0 | $g->write($text); | |||||||||||||||||||||||||||||||||||||||||
| 1013 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1014 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1015 | |||||||||||||||||||||||||||||||||||||||||||
| 1016 | sub writeFileFromFileFromCurrentRun($) # Write to a file in the current L<GitHub> repository by copying a local file if we are running on L<GitHub>. | ||||||||||||||||||||||||||||||||||||||||||
| 1017 | 0 | ▶ | {my ($target) = @_; # File name both locally and in the repo | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
writeFileFromFileFromCurrentRun: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1018 | 0 | ▶ | -e $target or confess "File to upload does not exist:\n$target"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1019 | 0 | ▶ | if (my $g = currentRepo) # We are on GitHub | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1020 | 0 | {$g->gitFile = $target; | |||||||||||||||||||||||||||||||||||||||||
| 1021 | 0 | $g->write(scalar(readFile($target))); | |||||||||||||||||||||||||||||||||||||||||
| 1022 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1023 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1024 | |||||||||||||||||||||||||||||||||||||||||||
| 1025 | sub writeBinaryFileFromFileInCurrentRun($$) # Write to a file in the current L<GitHub> repository by copying a local binary file if we are running on L<GitHub>. | ||||||||||||||||||||||||||||||||||||||||||
| 1026 | 0 | ▶ | {my ($target, $source) = @_; # The target file name in the repo, the current file name in the run | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
writeBinaryFileFromFileInCurrentRun: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1027 | 0 | ▶ | if (my $g = currentRepo) # We are on GitHub | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1028 | 0 | {$g->gitFile = $target; | |||||||||||||||||||||||||||||||||||||||||
| 1029 | 0 | $g->write(readBinaryFile($source)); | |||||||||||||||||||||||||||||||||||||||||
| 1030 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1031 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1032 | |||||||||||||||||||||||||||||||||||||||||||
| 1033 | sub pushToGitHub($$$@) # Push some files to github | ||||||||||||||||||||||||||||||||||||||||||
| 1034 | 0 | ▶ | {my ($user, $repo, $home, @files) = @_; # User id on github, repo name, home folder name, list of files to upload if they have changed since the last time an upload was performed | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pushToGitHub: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1035 | |||||||||||||||||||||||||||||||||||||||||||
| 1036 | 0 | @files = changedFiles ".changedFiles", @files if 1; # Filter out files that have not changed | |||||||||||||||||||||||||||||||||||||||||
| 1037 | |||||||||||||||||||||||||||||||||||||||||||
| 1038 | 0 | for my $s(@files) # Upload each selected file | |||||||||||||||||||||||||||||||||||||||||
| 1039 | 0 | {my $c = readBinaryFile $s; # Load file | |||||||||||||||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||||||||||||||||
| 1041 | 0 | ▶ | $c = expandWellKnownWordsAsUrlsInMdFormat($c) if $s =~ m(README); # Expand read me file | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1042 | |||||||||||||||||||||||||||||||||||||||||||
| 1043 | 0 | my $t = swapFilePrefix $s, $home; # File on github | |||||||||||||||||||||||||||||||||||||||||
| 1044 | 0 | my $w = writeFileUsingSavedToken($user, $repo, $t, $c); # Write file into github | |||||||||||||||||||||||||||||||||||||||||
| 1045 | 0 | lll "$w $t"; | |||||||||||||||||||||||||||||||||||||||||
| 1046 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1047 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1048 | |||||||||||||||||||||||||||||||||||||||||||
| 1049 | #D1 Access tokens # Load and save access tokens. Some L<GitHub> requests must be signed with an L<OAuth> access token. These methods help you store and reuse such tokens. Access tokens can be created at: L<https://github.com/settings/tokens>. | ||||||||||||||||||||||||||||||||||||||||||
| 1050 | |||||||||||||||||||||||||||||||||||||||||||
| 1051 | sub savePersonalAccessToken($) # Save a L<GitHub> personal access token by userid in folder L<personalAccessTokenFolder|/personalAccessTokenFolder>. | ||||||||||||||||||||||||||||||||||||||||||
| 1052 | 0 | ▶ | {my ($gitHub) = @_; # GitHub object | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
savePersonalAccessToken: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1053 | 0 | ▶ | my $user = qm $gitHub->userid; $user or confess "userid required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1054 | 0 | ▶ | my $pat = $gitHub->personalAccessToken; $pat or confess "personal access token required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1055 | 0 | ▶ | my $dir = $gitHub->personalAccessTokenFolder // accessFolder; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$gitHub->personalAccessTokenFolder // accessFolder()
MC/DC0%0/2
$gitHub->personalAccessTokenFolder // accessFolder()
$gitHub->personalAccessTokenFolder
accessFolder()
Truth table0%0/3
A // B
A= $gitHub->personalAccessTokenFolderB= accessFolder()
| |||||||||||||||||||||||||||||||||||||||||||
| 1056 | 0 | my $file = filePathExt($dir, $user, q(data)); | |||||||||||||||||||||||||||||||||||||||||
| 1057 | 0 | makePath($file); | |||||||||||||||||||||||||||||||||||||||||
| 1058 | 0 | storeFile($file, {pat=>$pat}); # Store personal access token | |||||||||||||||||||||||||||||||||||||||||
| 1059 | 0 | ▶ | -e $file or confess "Unable to store personal access token in file:\n$file"; # Complain if store fails | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1060 | 0 | my $p = retrieveFile $file; # Retrieve access token to check that we wrote it successfully | |||||||||||||||||||||||||||||||||||||||||
| 1061 | $pat eq $p->{pat} or # Check file format | ||||||||||||||||||||||||||||||||||||||||||
| 1062 | 0 | ▶ | confess "File contains the wrong personal access token:\n$file"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1063 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1064 | |||||||||||||||||||||||||||||||||||||||||||
| 1065 | sub loadPersonalAccessToken($) # Load a personal access token by userid from folder L<personalAccessTokenFolder|/personalAccessTokenFolder>. | ||||||||||||||||||||||||||||||||||||||||||
| 1066 | 0 | ▶ | {my ($gitHub) = @_; # GitHub object | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
loadPersonalAccessToken: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1067 | 0 | ▶ | my $user = qm $gitHub->userid; $user or confess "userid required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1068 | |||||||||||||||||||||||||||||||||||||||||||
| 1069 | 0 | ▶ | if (length($gitHub->personalAccessTokenFolder//accessFolder) == 43) # Access token supplied directly | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$gitHub->personalAccessTokenFolder // accessFolder()
MC/DC0%0/2
$gitHub->personalAccessTokenFolder // accessFolder()
$gitHub->personalAccessTokenFolder
accessFolder()
Truth table0%0/3
A // B
A= $gitHub->personalAccessTokenFolderB= accessFolder()
| |||||||||||||||||||||||||||||||||||||||||||
| 1070 | 0 | {return $gitHub->personalAccessToken = $gitHub->personalAccessTokenFolder; | |||||||||||||||||||||||||||||||||||||||||
| 1071 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||||||||||||||||
| 1073 | 0 | ▶ | if ($ENV{GITHUB_TOKEN}) # Access token supplied through environment | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1074 | 0 | {return $gitHub->personalAccessToken = $ENV{GITHUB_TOKEN}; | |||||||||||||||||||||||||||||||||||||||||
| 1075 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||||||||||||||||
| 1077 | 0 | ▶ | my $dir = $gitHub->personalAccessTokenFolder // accessFolder; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$gitHub->personalAccessTokenFolder // accessFolder()
MC/DC0%0/2
$gitHub->personalAccessTokenFolder // accessFolder()
$gitHub->personalAccessTokenFolder
accessFolder()
Truth table0%0/3
A // B
A= $gitHub->personalAccessTokenFolderB= accessFolder()
| |||||||||||||||||||||||||||||||||||||||||||
| 1078 | 0 | my $file = filePathExt($dir, $user, q(data)); | |||||||||||||||||||||||||||||||||||||||||
| 1079 | 0 | my $p = retrieveFile $file; # Load personal access token | |||||||||||||||||||||||||||||||||||||||||
| 1080 | my $a = $p->{pat} or # Check file format | ||||||||||||||||||||||||||||||||||||||||||
| 1081 | 0 | ▶ | confess "File does not contain a personal access token:\n$file"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1082 | 0 | $gitHub->personalAccessToken = $a; # Retrieve token | |||||||||||||||||||||||||||||||||||||||||
| 1083 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1084 | |||||||||||||||||||||||||||||||||||||||||||
| 1085 | #D0 | ||||||||||||||||||||||||||||||||||||||||||
| 1086 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 1087 | # Export - eeee | ||||||||||||||||||||||||||||||||||||||||||
| 1088 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 1089 | |||||||||||||||||||||||||||||||||||||||||||
| 1090 | 1 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1091 | |||||||||||||||||||||||||||||||||||||||||||
| 1092 | 1 | ▶ | use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1093 | |||||||||||||||||||||||||||||||||||||||||||
| 1094 | # containingFolder | ||||||||||||||||||||||||||||||||||||||||||
| 1095 | |||||||||||||||||||||||||||||||||||||||||||
| 1096 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 1097 | 1 | @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||
| 1098 | createIssueFromSavedToken | ||||||||||||||||||||||||||||||||||||||||||
| 1099 | createIssueInCurrentRepo | ||||||||||||||||||||||||||||||||||||||||||
| 1100 | createRepositoryFromSavedToken | ||||||||||||||||||||||||||||||||||||||||||
| 1101 | deleteFileUsingSavedToken | ||||||||||||||||||||||||||||||||||||||||||
| 1102 | getRepository | ||||||||||||||||||||||||||||||||||||||||||
| 1103 | getRepositoryUsingSavedToken | ||||||||||||||||||||||||||||||||||||||||||
| 1104 | getRepositoryUpdatedAtUsingSavedToken | ||||||||||||||||||||||||||||||||||||||||||
| 1105 | listRepositoryUsingSavedToken | ||||||||||||||||||||||||||||||||||||||||||
| 1106 | pushToGitHub | ||||||||||||||||||||||||||||||||||||||||||
| 1107 | readFileUsingSavedToken | ||||||||||||||||||||||||||||||||||||||||||
| 1108 | writeBinaryFileFromFileInCurrentRun | ||||||||||||||||||||||||||||||||||||||||||
| 1109 | writeCommitUsingSavedToken | ||||||||||||||||||||||||||||||||||||||||||
| 1110 | writeFileFromCurrentRun | ||||||||||||||||||||||||||||||||||||||||||
| 1111 | writeFileFromFileUsingSavedToken | ||||||||||||||||||||||||||||||||||||||||||
| 1112 | writeFileUsingSavedToken | ||||||||||||||||||||||||||||||||||||||||||
| 1113 | writeFolderUsingSavedToken | ||||||||||||||||||||||||||||||||||||||||||
| 1114 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1115 | 1 | %EXPORT_TAGS = (all=>[@EXPORT_OK]); | |||||||||||||||||||||||||||||||||||||||||
| 1116 | |||||||||||||||||||||||||||||||||||||||||||
| 1117 | #podDocumentation | ||||||||||||||||||||||||||||||||||||||||||
| 1118 | |||||||||||||||||||||||||||||||||||||||||||
| 1119 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 1120 | |||||||||||||||||||||||||||||||||||||||||||
| 1121 | =encoding utf-8 | ||||||||||||||||||||||||||||||||||||||||||
| 1122 | |||||||||||||||||||||||||||||||||||||||||||
| 1123 | =for html <p><a href="https://github.com/philiprbrenan/GitHubCrud"><img src="https://github.com/philiprbrenan/GitHubCrud/workflows/Test/badge.svg"></a> | ||||||||||||||||||||||||||||||||||||||||||
| 1124 | |||||||||||||||||||||||||||||||||||||||||||
| 1125 | =head1 Name | ||||||||||||||||||||||||||||||||||||||||||
| 1126 | |||||||||||||||||||||||||||||||||||||||||||
| 1127 | GitHub::Crud - Create, Read, Update, Delete files, commits, issues, and web hooks on GitHub. | ||||||||||||||||||||||||||||||||||||||||||
| 1128 | |||||||||||||||||||||||||||||||||||||||||||
| 1129 | =head1 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 1130 | |||||||||||||||||||||||||||||||||||||||||||
| 1131 | Create, Read, Update, Delete files, commits, issues, and web hooks on GitHub as | ||||||||||||||||||||||||||||||||||||||||||
| 1132 | described at: | ||||||||||||||||||||||||||||||||||||||||||
| 1133 | |||||||||||||||||||||||||||||||||||||||||||
| 1134 | https://developer.github.com/v3/repos/contents/#update-a-file | ||||||||||||||||||||||||||||||||||||||||||
| 1135 | |||||||||||||||||||||||||||||||||||||||||||
| 1136 | =head2 Upload a file from an action | ||||||||||||||||||||||||||||||||||||||||||
| 1137 | |||||||||||||||||||||||||||||||||||||||||||
| 1138 | Upload a file created during a github action to the repository for that action: | ||||||||||||||||||||||||||||||||||||||||||
| 1139 | |||||||||||||||||||||||||||||||||||||||||||
| 1140 | GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} \ | ||||||||||||||||||||||||||||||||||||||||||
| 1141 | perl -M"GitHub::Crud" -e"GitHub::Crud::writeFileFromFileFromCurrentRun q(output.txt);" | ||||||||||||||||||||||||||||||||||||||||||
| 1142 | |||||||||||||||||||||||||||||||||||||||||||
| 1143 | =head2 Upload a folder | ||||||||||||||||||||||||||||||||||||||||||
| 1144 | |||||||||||||||||||||||||||||||||||||||||||
| 1145 | Commit a folder to GitHub then read and check some of the uploaded content: | ||||||||||||||||||||||||||||||||||||||||||
| 1146 | |||||||||||||||||||||||||||||||||||||||||||
| 1147 | use GitHub::Crud; | ||||||||||||||||||||||||||||||||||||||||||
| 1148 | use Data::Table::Text qw(:all); | ||||||||||||||||||||||||||||||||||||||||||
| 1149 | |||||||||||||||||||||||||||||||||||||||||||
| 1150 | my $f = temporaryFolder; # Folder in which we will create some files to upload in the commit | ||||||||||||||||||||||||||||||||||||||||||
| 1151 | my $c = dateTimeStamp; # Create some content | ||||||||||||||||||||||||||||||||||||||||||
| 1152 | my $if = q(/home/phil/.face); # Image file | ||||||||||||||||||||||||||||||||||||||||||
| 1153 | |||||||||||||||||||||||||||||||||||||||||||
| 1154 | writeFile(fpe($f, q(data), $_, qw(txt)), $c) for 1..3; # Place content in files in a sub folder | ||||||||||||||||||||||||||||||||||||||||||
| 1155 | copyBinaryFile $if, my $If = fpe $f, qw(face jpg); # Add an image | ||||||||||||||||||||||||||||||||||||||||||
| 1156 | |||||||||||||||||||||||||||||||||||||||||||
| 1157 | my $g = GitHub::Crud::new # Create GitHub | ||||||||||||||||||||||||||||||||||||||||||
| 1158 | (userid => q(philiprbrenan), | ||||||||||||||||||||||||||||||||||||||||||
| 1159 | repository => q(aaa), | ||||||||||||||||||||||||||||||||||||||||||
| 1160 | branch => q(test), | ||||||||||||||||||||||||||||||||||||||||||
| 1161 | confessOnFailure => 1); | ||||||||||||||||||||||||||||||||||||||||||
| 1162 | |||||||||||||||||||||||||||||||||||||||||||
| 1163 | $g->loadPersonalAccessToken; # Load a personal access token | ||||||||||||||||||||||||||||||||||||||||||
| 1164 | $g->writeCommit($f); # Upload commit - confess to any errors | ||||||||||||||||||||||||||||||||||||||||||
| 1165 | |||||||||||||||||||||||||||||||||||||||||||
| 1166 | my $C = $g->read(q(data/1.txt)); # Read data written in commit | ||||||||||||||||||||||||||||||||||||||||||
| 1167 | my $I = $g->read(q(face.jpg)); | ||||||||||||||||||||||||||||||||||||||||||
| 1168 | my $i = readBinaryFile $if; | ||||||||||||||||||||||||||||||||||||||||||
| 1169 | |||||||||||||||||||||||||||||||||||||||||||
| 1170 | confess "Date stamp failed" unless $C eq $c; # Check text | ||||||||||||||||||||||||||||||||||||||||||
| 1171 | confess "Image failed" unless $i eq $I; # Check image | ||||||||||||||||||||||||||||||||||||||||||
| 1172 | confess "Write commit succeeded"; | ||||||||||||||||||||||||||||||||||||||||||
| 1173 | |||||||||||||||||||||||||||||||||||||||||||
| 1174 | =head2 Prerequisites | ||||||||||||||||||||||||||||||||||||||||||
| 1175 | |||||||||||||||||||||||||||||||||||||||||||
| 1176 | Please install B<curl> if it is not already present on your computer. | ||||||||||||||||||||||||||||||||||||||||||
| 1177 | |||||||||||||||||||||||||||||||||||||||||||
| 1178 | sudo apt-get install curl | ||||||||||||||||||||||||||||||||||||||||||
| 1179 | |||||||||||||||||||||||||||||||||||||||||||
| 1180 | =head2 Personal Access Token | ||||||||||||||||||||||||||||||||||||||||||
| 1181 | |||||||||||||||||||||||||||||||||||||||||||
| 1182 | You will need to create a personal access token if you wish to gain write | ||||||||||||||||||||||||||||||||||||||||||
| 1183 | access to your respositories : L<https://github.com/settings/tokens>. | ||||||||||||||||||||||||||||||||||||||||||
| 1184 | Depending on your security requirements you can either install this token at | ||||||||||||||||||||||||||||||||||||||||||
| 1185 | the well known location: | ||||||||||||||||||||||||||||||||||||||||||
| 1186 | |||||||||||||||||||||||||||||||||||||||||||
| 1187 | /etc/GitHubCrudPersonalAccessToken/<github userid> | ||||||||||||||||||||||||||||||||||||||||||
| 1188 | |||||||||||||||||||||||||||||||||||||||||||
| 1189 | or at a location of your choice. If you use a well known location then the | ||||||||||||||||||||||||||||||||||||||||||
| 1190 | personal access token will be loaded automatically for you, else you will need | ||||||||||||||||||||||||||||||||||||||||||
| 1191 | to supply it to each call via the L</personalAccessToken> attribute. | ||||||||||||||||||||||||||||||||||||||||||
| 1192 | |||||||||||||||||||||||||||||||||||||||||||
| 1193 | The following code will install a personal access token for github userid | ||||||||||||||||||||||||||||||||||||||||||
| 1194 | B<uuuuuu> in the default location: | ||||||||||||||||||||||||||||||||||||||||||
| 1195 | |||||||||||||||||||||||||||||||||||||||||||
| 1196 | use GitHub::Crud qw(:all); | ||||||||||||||||||||||||||||||||||||||||||
| 1197 | |||||||||||||||||||||||||||||||||||||||||||
| 1198 | my $g = GitHub::Crud::gitHub | ||||||||||||||||||||||||||||||||||||||||||
| 1199 | (userid => q(uuuuuu), | ||||||||||||||||||||||||||||||||||||||||||
| 1200 | personalAccessToken => q(........................................), | ||||||||||||||||||||||||||||||||||||||||||
| 1201 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1202 | |||||||||||||||||||||||||||||||||||||||||||
| 1203 | $g->savePersonalAccessToken; | ||||||||||||||||||||||||||||||||||||||||||
| 1204 | |||||||||||||||||||||||||||||||||||||||||||
| 1205 | =head1 Description | ||||||||||||||||||||||||||||||||||||||||||
| 1206 | |||||||||||||||||||||||||||||||||||||||||||
| 1207 | Create, Read, Update, Delete files, commits, issues, and web hooks on GitHub. | ||||||||||||||||||||||||||||||||||||||||||
| 1208 | |||||||||||||||||||||||||||||||||||||||||||
| 1209 | |||||||||||||||||||||||||||||||||||||||||||
| 1210 | Version 20250520. | ||||||||||||||||||||||||||||||||||||||||||
| 1211 | |||||||||||||||||||||||||||||||||||||||||||
| 1212 | |||||||||||||||||||||||||||||||||||||||||||
| 1213 | The following sections describe the methods in each functional area of this | ||||||||||||||||||||||||||||||||||||||||||
| 1214 | module. For an alphabetic listing of all methods by name see L<Index|/Index>. | ||||||||||||||||||||||||||||||||||||||||||
| 1215 | |||||||||||||||||||||||||||||||||||||||||||
| 1216 | |||||||||||||||||||||||||||||||||||||||||||
| 1217 | |||||||||||||||||||||||||||||||||||||||||||
| 1218 | =head1 Constructor | ||||||||||||||||||||||||||||||||||||||||||
| 1219 | |||||||||||||||||||||||||||||||||||||||||||
| 1220 | Create a L<GitHub|https://github.com/philiprbrenan> object with the specified attributes describing the interface with L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 1221 | |||||||||||||||||||||||||||||||||||||||||||
| 1222 | =head2 new (%attributes) | ||||||||||||||||||||||||||||||||||||||||||
| 1223 | |||||||||||||||||||||||||||||||||||||||||||
| 1224 | Create a new L<GitHub|https://github.com/philiprbrenan> object with attributes as described at: L<GitHub::Crud Definition>. | ||||||||||||||||||||||||||||||||||||||||||
| 1225 | |||||||||||||||||||||||||||||||||||||||||||
| 1226 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1227 | 1 %attributes Attribute values | ||||||||||||||||||||||||||||||||||||||||||
| 1228 | |||||||||||||||||||||||||||||||||||||||||||
| 1229 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1230 | |||||||||||||||||||||||||||||||||||||||||||
| 1231 | |||||||||||||||||||||||||||||||||||||||||||
| 1232 | my $f = temporaryFolder; # Folder in which we will create some files to upload in the commit | ||||||||||||||||||||||||||||||||||||||||||
| 1233 | my $c = dateTimeStamp; # Create some content | ||||||||||||||||||||||||||||||||||||||||||
| 1234 | my $if = q(/home/phil/.face); # Image file | ||||||||||||||||||||||||||||||||||||||||||
| 1235 | |||||||||||||||||||||||||||||||||||||||||||
| 1236 | writeFile(fpe($f, q(data), $_, qw(txt)), $c) for 1..3; # Place content in files in a sub folder | ||||||||||||||||||||||||||||||||||||||||||
| 1237 | copyBinaryFile $if, my $If = fpe $f, qw(face jpg); # Add an image | ||||||||||||||||||||||||||||||||||||||||||
| 1238 | |||||||||||||||||||||||||||||||||||||||||||
| 1239 | |||||||||||||||||||||||||||||||||||||||||||
| 1240 | my $g = GitHub::Crud::new # Create GitHub # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1241 | |||||||||||||||||||||||||||||||||||||||||||
| 1242 | (userid => q(philiprbrenan), | ||||||||||||||||||||||||||||||||||||||||||
| 1243 | repository => q(aaa), | ||||||||||||||||||||||||||||||||||||||||||
| 1244 | branch => q(test), | ||||||||||||||||||||||||||||||||||||||||||
| 1245 | confessOnFailure => 1); | ||||||||||||||||||||||||||||||||||||||||||
| 1246 | |||||||||||||||||||||||||||||||||||||||||||
| 1247 | $g->loadPersonalAccessToken; # Load a personal access token | ||||||||||||||||||||||||||||||||||||||||||
| 1248 | $g->writeCommit($f); # Upload commit - confess to any errors | ||||||||||||||||||||||||||||||||||||||||||
| 1249 | |||||||||||||||||||||||||||||||||||||||||||
| 1250 | my $C = $g->read(q(data/1.txt)); # Read data written in commit | ||||||||||||||||||||||||||||||||||||||||||
| 1251 | my $I = $g->read(q(face.jpg)); | ||||||||||||||||||||||||||||||||||||||||||
| 1252 | my $i = readBinaryFile $if; | ||||||||||||||||||||||||||||||||||||||||||
| 1253 | |||||||||||||||||||||||||||||||||||||||||||
| 1254 | confess "Date stamp failed" unless $C eq $c; # Check text | ||||||||||||||||||||||||||||||||||||||||||
| 1255 | confess "Image failed" unless $i eq $I; # Check image | ||||||||||||||||||||||||||||||||||||||||||
| 1256 | success "Write commit succeeded"; | ||||||||||||||||||||||||||||||||||||||||||
| 1257 | |||||||||||||||||||||||||||||||||||||||||||
| 1258 | |||||||||||||||||||||||||||||||||||||||||||
| 1259 | =head1 Files | ||||||||||||||||||||||||||||||||||||||||||
| 1260 | |||||||||||||||||||||||||||||||||||||||||||
| 1261 | File actions on the contents of L<GitHub|https://github.com/philiprbrenan> repositories. | ||||||||||||||||||||||||||||||||||||||||||
| 1262 | |||||||||||||||||||||||||||||||||||||||||||
| 1263 | =head2 list($gitHub) | ||||||||||||||||||||||||||||||||||||||||||
| 1264 | |||||||||||||||||||||||||||||||||||||||||||
| 1265 | List all the files contained in a L<GitHub|https://github.com/philiprbrenan> repository or all the files below a specified folder in the repository. | ||||||||||||||||||||||||||||||||||||||||||
| 1266 | |||||||||||||||||||||||||||||||||||||||||||
| 1267 | Required attributes: L<userid|/userid>, L<repository|/repository>. | ||||||||||||||||||||||||||||||||||||||||||
| 1268 | |||||||||||||||||||||||||||||||||||||||||||
| 1269 | Optional attributes: L<gitFolder|/gitFolder>, L<refOrBranch|/refOrBranch>, L<nonRecursive|/nonRecursive>, L<patKey|/patKey>. | ||||||||||||||||||||||||||||||||||||||||||
| 1270 | |||||||||||||||||||||||||||||||||||||||||||
| 1271 | Use the L<gitFolder|/gitFolder> parameter to specify the folder to start the list from, by default, the listing will start at the root folder of your repository. | ||||||||||||||||||||||||||||||||||||||||||
| 1272 | |||||||||||||||||||||||||||||||||||||||||||
| 1273 | Use the L<nonRecursive|/nonRecursive> option if you require only the files in the start folder as otherwise all the folders in the start folder will be listed as well which might take some time. | ||||||||||||||||||||||||||||||||||||||||||
| 1274 | |||||||||||||||||||||||||||||||||||||||||||
| 1275 | If the list operation is successful, L<failed|/failed> is set to false and L<fileList|/fileList> is set to refer to an array of the file names found. | ||||||||||||||||||||||||||||||||||||||||||
| 1276 | |||||||||||||||||||||||||||||||||||||||||||
| 1277 | If the list operation fails then L<failed|/failed> is set to true and L<fileList|/fileList> is set to refer to an empty array. | ||||||||||||||||||||||||||||||||||||||||||
| 1278 | |||||||||||||||||||||||||||||||||||||||||||
| 1279 | Returns the list of file names found or empty list if no files were found. | ||||||||||||||||||||||||||||||||||||||||||
| 1280 | |||||||||||||||||||||||||||||||||||||||||||
| 1281 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1282 | 1 $gitHub GitHub | ||||||||||||||||||||||||||||||||||||||||||
| 1283 | |||||||||||||||||||||||||||||||||||||||||||
| 1284 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1285 | |||||||||||||||||||||||||||||||||||||||||||
| 1286 | |||||||||||||||||||||||||||||||||||||||||||
| 1287 | |||||||||||||||||||||||||||||||||||||||||||
| 1288 | success "list:", gitHub->list; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1289 | |||||||||||||||||||||||||||||||||||||||||||
| 1290 | |||||||||||||||||||||||||||||||||||||||||||
| 1291 | # list: alpha.data .github/workflows/test.yaml images/aaa.txt images/aaa/bbb.txt # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1292 | |||||||||||||||||||||||||||||||||||||||||||
| 1293 | |||||||||||||||||||||||||||||||||||||||||||
| 1294 | |||||||||||||||||||||||||||||||||||||||||||
| 1295 | =head2 read($gitHub, $File) | ||||||||||||||||||||||||||||||||||||||||||
| 1296 | |||||||||||||||||||||||||||||||||||||||||||
| 1297 | Read data from a file on L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 1298 | |||||||||||||||||||||||||||||||||||||||||||
| 1299 | Required attributes: L<userid|/userid>, L<repository|/repository>. | ||||||||||||||||||||||||||||||||||||||||||
| 1300 | |||||||||||||||||||||||||||||||||||||||||||
| 1301 | Optional attributes: L<gitFile|/gitFile> = the file to read, L<refOrBranch|/refOrBranch>, L<patKey|/patKey>. | ||||||||||||||||||||||||||||||||||||||||||
| 1302 | |||||||||||||||||||||||||||||||||||||||||||
| 1303 | If the read operation is successful, L<failed|/failed> is set to false and L<readData|/readData> is set to the data read from the file. | ||||||||||||||||||||||||||||||||||||||||||
| 1304 | |||||||||||||||||||||||||||||||||||||||||||
| 1305 | If the read operation fails then L<failed|/failed> is set to true and L<readData|/readData> is set to B<undef>. | ||||||||||||||||||||||||||||||||||||||||||
| 1306 | |||||||||||||||||||||||||||||||||||||||||||
| 1307 | Returns the data read or B<undef> if no file was found. | ||||||||||||||||||||||||||||||||||||||||||
| 1308 | |||||||||||||||||||||||||||||||||||||||||||
| 1309 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1310 | 1 $gitHub GitHub | ||||||||||||||||||||||||||||||||||||||||||
| 1311 | 2 $File File to read if not specified in gitFile | ||||||||||||||||||||||||||||||||||||||||||
| 1312 | |||||||||||||||||||||||||||||||||||||||||||
| 1313 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1314 | |||||||||||||||||||||||||||||||||||||||||||
| 1315 | |||||||||||||||||||||||||||||||||||||||||||
| 1316 | my $g = gitHub; | ||||||||||||||||||||||||||||||||||||||||||
| 1317 | $g->gitFile = my $f = q(z'2 'z"z.data); | ||||||||||||||||||||||||||||||||||||||||||
| 1318 | my $d = q(𝝰𝝱𝝲); | ||||||||||||||||||||||||||||||||||||||||||
| 1319 | $g->write($d); | ||||||||||||||||||||||||||||||||||||||||||
| 1320 | |||||||||||||||||||||||||||||||||||||||||||
| 1321 | confess "read FAILED" unless $g->read eq $d; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1322 | |||||||||||||||||||||||||||||||||||||||||||
| 1323 | success "Read passed"; | ||||||||||||||||||||||||||||||||||||||||||
| 1324 | |||||||||||||||||||||||||||||||||||||||||||
| 1325 | |||||||||||||||||||||||||||||||||||||||||||
| 1326 | =head2 write ($gitHub, $data, $File) | ||||||||||||||||||||||||||||||||||||||||||
| 1327 | |||||||||||||||||||||||||||||||||||||||||||
| 1328 | Write the specified data into a file on L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 1329 | |||||||||||||||||||||||||||||||||||||||||||
| 1330 | Required attributes: L<userid|/userid>, L<repository|/repository>, L<patKey|/patKey>. Either specify the target file on: L<GitHub|https://github.com/philiprbrenan> using the L<gitFile|/gitFile> attribute or supply it as the third parameter. Returns B<true> on success else L<undef|https://perldoc.perl.org/functions/undef.html>. | ||||||||||||||||||||||||||||||||||||||||||
| 1331 | |||||||||||||||||||||||||||||||||||||||||||
| 1332 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1333 | 1 $gitHub GitHub object | ||||||||||||||||||||||||||||||||||||||||||
| 1334 | 2 $data Data to be written | ||||||||||||||||||||||||||||||||||||||||||
| 1335 | 3 $File Optionally the name of the file on github | ||||||||||||||||||||||||||||||||||||||||||
| 1336 | |||||||||||||||||||||||||||||||||||||||||||
| 1337 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1338 | |||||||||||||||||||||||||||||||||||||||||||
| 1339 | |||||||||||||||||||||||||||||||||||||||||||
| 1340 | my $g = gitHub; | ||||||||||||||||||||||||||||||||||||||||||
| 1341 | $g->gitFile = "zzz.data"; | ||||||||||||||||||||||||||||||||||||||||||
| 1342 | |||||||||||||||||||||||||||||||||||||||||||
| 1343 | my $d = dateTimeStamp.q( 𝝰𝝱𝝲); | ||||||||||||||||||||||||||||||||||||||||||
| 1344 | |||||||||||||||||||||||||||||||||||||||||||
| 1345 | if (1) | ||||||||||||||||||||||||||||||||||||||||||
| 1346 | {my $t = time(); | ||||||||||||||||||||||||||||||||||||||||||
| 1347 | |||||||||||||||||||||||||||||||||||||||||||
| 1348 | $g->write($d); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1349 | |||||||||||||||||||||||||||||||||||||||||||
| 1350 | |||||||||||||||||||||||||||||||||||||||||||
| 1351 | lll "First write time: ", time() - $t; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1352 | |||||||||||||||||||||||||||||||||||||||||||
| 1353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1354 | |||||||||||||||||||||||||||||||||||||||||||
| 1355 | my $r = $g->read; | ||||||||||||||||||||||||||||||||||||||||||
| 1356 | lll "Write bbb: $r"; | ||||||||||||||||||||||||||||||||||||||||||
| 1357 | if (1) | ||||||||||||||||||||||||||||||||||||||||||
| 1358 | {my $t = time(); | ||||||||||||||||||||||||||||||||||||||||||
| 1359 | |||||||||||||||||||||||||||||||||||||||||||
| 1360 | $g->write($d); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1361 | |||||||||||||||||||||||||||||||||||||||||||
| 1362 | |||||||||||||||||||||||||||||||||||||||||||
| 1363 | lll "Second write time: ", time() - $t; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1364 | |||||||||||||||||||||||||||||||||||||||||||
| 1365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1366 | |||||||||||||||||||||||||||||||||||||||||||
| 1367 | confess "write FAILED" unless $g->exists; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1368 | |||||||||||||||||||||||||||||||||||||||||||
| 1369 | success "Write passed"; | ||||||||||||||||||||||||||||||||||||||||||
| 1370 | |||||||||||||||||||||||||||||||||||||||||||
| 1371 | |||||||||||||||||||||||||||||||||||||||||||
| 1372 | =head2 readBlob($gitHub, $sha) | ||||||||||||||||||||||||||||||||||||||||||
| 1373 | |||||||||||||||||||||||||||||||||||||||||||
| 1374 | Read a L<blob|https://en.wikipedia.org/wiki/Binary_large_object> from L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 1375 | |||||||||||||||||||||||||||||||||||||||||||
| 1376 | Required attributes: L<userid|/userid>, L<repository|/repository>, L<patKey|/patKey>. Returns the content of the L<blob|https://en.wikipedia.org/wiki/Binary_large_object> identified by the specified L<SHA|https://en.wikipedia.org/wiki/SHA-1>. | ||||||||||||||||||||||||||||||||||||||||||
| 1377 | |||||||||||||||||||||||||||||||||||||||||||
| 1378 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1379 | 1 $gitHub GitHub object | ||||||||||||||||||||||||||||||||||||||||||
| 1380 | 2 $sha Data to be written | ||||||||||||||||||||||||||||||||||||||||||
| 1381 | |||||||||||||||||||||||||||||||||||||||||||
| 1382 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1383 | |||||||||||||||||||||||||||||||||||||||||||
| 1384 | |||||||||||||||||||||||||||||||||||||||||||
| 1385 | my $g = gitHub; | ||||||||||||||||||||||||||||||||||||||||||
| 1386 | $g->gitFile = "face.jpg"; | ||||||||||||||||||||||||||||||||||||||||||
| 1387 | my $d = readBinaryFile(q(/home/phil/.face)); | ||||||||||||||||||||||||||||||||||||||||||
| 1388 | my $s = $g->writeBlob($d); | ||||||||||||||||||||||||||||||||||||||||||
| 1389 | my $S = q(4a2df549febb701ba651aae46e041923e9550cb8); | ||||||||||||||||||||||||||||||||||||||||||
| 1390 | confess q(Write blob FAILED) unless $s eq $S; | ||||||||||||||||||||||||||||||||||||||||||
| 1391 | |||||||||||||||||||||||||||||||||||||||||||
| 1392 | |||||||||||||||||||||||||||||||||||||||||||
| 1393 | my $D = $g->readBlob($s); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1394 | |||||||||||||||||||||||||||||||||||||||||||
| 1395 | confess q(Write/Read blob FAILED) unless $d eq $D; | ||||||||||||||||||||||||||||||||||||||||||
| 1396 | success q(Write/Read blob passed); | ||||||||||||||||||||||||||||||||||||||||||
| 1397 | |||||||||||||||||||||||||||||||||||||||||||
| 1398 | |||||||||||||||||||||||||||||||||||||||||||
| 1399 | =head2 writeBlob ($gitHub, $data) | ||||||||||||||||||||||||||||||||||||||||||
| 1400 | |||||||||||||||||||||||||||||||||||||||||||
| 1401 | Write data into a L<GitHub|https://github.com/philiprbrenan> as a L<blob|https://en.wikipedia.org/wiki/Binary_large_object> that can be referenced by future commits. | ||||||||||||||||||||||||||||||||||||||||||
| 1402 | |||||||||||||||||||||||||||||||||||||||||||
| 1403 | Required attributes: L<userid|/userid>, L<repository|/repository>, L<patKey|/patKey>. Returns the L<SHA|https://en.wikipedia.org/wiki/SHA-1> of the created L<blob|https://en.wikipedia.org/wiki/Binary_large_object> or L<undef|https://perldoc.perl.org/functions/undef.html> in a failure occurred. | ||||||||||||||||||||||||||||||||||||||||||
| 1404 | |||||||||||||||||||||||||||||||||||||||||||
| 1405 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1406 | 1 $gitHub GitHub object | ||||||||||||||||||||||||||||||||||||||||||
| 1407 | 2 $data Data to be written | ||||||||||||||||||||||||||||||||||||||||||
| 1408 | |||||||||||||||||||||||||||||||||||||||||||
| 1409 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1410 | |||||||||||||||||||||||||||||||||||||||||||
| 1411 | |||||||||||||||||||||||||||||||||||||||||||
| 1412 | my $g = gitHub; | ||||||||||||||||||||||||||||||||||||||||||
| 1413 | $g->gitFile = "face.jpg"; | ||||||||||||||||||||||||||||||||||||||||||
| 1414 | my $d = readBinaryFile(q(/home/phil/.face)); | ||||||||||||||||||||||||||||||||||||||||||
| 1415 | |||||||||||||||||||||||||||||||||||||||||||
| 1416 | my $s = $g->writeBlob($d); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1417 | |||||||||||||||||||||||||||||||||||||||||||
| 1418 | my $S = q(4a2df549febb701ba651aae46e041923e9550cb8); | ||||||||||||||||||||||||||||||||||||||||||
| 1419 | confess q(Write blob FAILED) unless $s eq $S; | ||||||||||||||||||||||||||||||||||||||||||
| 1420 | |||||||||||||||||||||||||||||||||||||||||||
| 1421 | my $D = $g->readBlob($s); | ||||||||||||||||||||||||||||||||||||||||||
| 1422 | confess q(Write/Read blob FAILED) unless $d eq $D; | ||||||||||||||||||||||||||||||||||||||||||
| 1423 | success q(Write/Read blob passed); | ||||||||||||||||||||||||||||||||||||||||||
| 1424 | |||||||||||||||||||||||||||||||||||||||||||
| 1425 | |||||||||||||||||||||||||||||||||||||||||||
| 1426 | =head2 copy($gitHub, $target) | ||||||||||||||||||||||||||||||||||||||||||
| 1427 | |||||||||||||||||||||||||||||||||||||||||||
| 1428 | Copy a source file from one location to another target location in your L<GitHub|https://github.com/philiprbrenan> repository, overwriting the target file if it already exists. | ||||||||||||||||||||||||||||||||||||||||||
| 1429 | |||||||||||||||||||||||||||||||||||||||||||
| 1430 | Required attributes: L<userid|/userid>, L<repository|/repository>, L<patKey|/patKey>, L<gitFile|/gitFile> = the file to be copied. | ||||||||||||||||||||||||||||||||||||||||||
| 1431 | |||||||||||||||||||||||||||||||||||||||||||
| 1432 | Optional attributes: L<refOrBranch|/refOrBranch>. | ||||||||||||||||||||||||||||||||||||||||||
| 1433 | |||||||||||||||||||||||||||||||||||||||||||
| 1434 | If the write operation is successful, L<failed|/failed> is set to false otherwise it is set to true. | ||||||||||||||||||||||||||||||||||||||||||
| 1435 | |||||||||||||||||||||||||||||||||||||||||||
| 1436 | Returns B<updated> if the write updated the file, B<created> if the write created the file else B<undef> if the write failed. | ||||||||||||||||||||||||||||||||||||||||||
| 1437 | |||||||||||||||||||||||||||||||||||||||||||
| 1438 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1439 | 1 $gitHub GitHub object | ||||||||||||||||||||||||||||||||||||||||||
| 1440 | 2 $target The name of the file to be created | ||||||||||||||||||||||||||||||||||||||||||
| 1441 | |||||||||||||||||||||||||||||||||||||||||||
| 1442 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1443 | |||||||||||||||||||||||||||||||||||||||||||
| 1444 | |||||||||||||||||||||||||||||||||||||||||||
| 1445 | my ($f1, $f2) = ("zzz.data", "zzz2.data"); | ||||||||||||||||||||||||||||||||||||||||||
| 1446 | my $g = gitHub; | ||||||||||||||||||||||||||||||||||||||||||
| 1447 | $g->gitFile = $f2; $g->delete; | ||||||||||||||||||||||||||||||||||||||||||
| 1448 | $g->gitFile = $f1; | ||||||||||||||||||||||||||||||||||||||||||
| 1449 | my $d = dateTimeStamp; | ||||||||||||||||||||||||||||||||||||||||||
| 1450 | my $w = $g->write($d); | ||||||||||||||||||||||||||||||||||||||||||
| 1451 | |||||||||||||||||||||||||||||||||||||||||||
| 1452 | my $r = $g->copy($f2); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1453 | |||||||||||||||||||||||||||||||||||||||||||
| 1454 | lll "Copy created: $r"; | ||||||||||||||||||||||||||||||||||||||||||
| 1455 | $g->gitFile = $f2; | ||||||||||||||||||||||||||||||||||||||||||
| 1456 | my $D = $g->read; | ||||||||||||||||||||||||||||||||||||||||||
| 1457 | lll "Read ccc: $D"; | ||||||||||||||||||||||||||||||||||||||||||
| 1458 | |||||||||||||||||||||||||||||||||||||||||||
| 1459 | confess "copy FAILED" unless $d eq $D; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1460 | |||||||||||||||||||||||||||||||||||||||||||
| 1461 | success "Copy passed" | ||||||||||||||||||||||||||||||||||||||||||
| 1462 | |||||||||||||||||||||||||||||||||||||||||||
| 1463 | |||||||||||||||||||||||||||||||||||||||||||
| 1464 | =head2 exists ($gitHub) | ||||||||||||||||||||||||||||||||||||||||||
| 1465 | |||||||||||||||||||||||||||||||||||||||||||
| 1466 | Test whether a file exists on L<GitHub|https://github.com/philiprbrenan> or not and returns an object including the B<sha> and B<size> fields if it does else L<undef|https://perldoc.perl.org/functions/undef.html>. | ||||||||||||||||||||||||||||||||||||||||||
| 1467 | |||||||||||||||||||||||||||||||||||||||||||
| 1468 | Required attributes: L<userid|/userid>, L<repository|/repository>, L<gitFile|/gitFile> file to test. | ||||||||||||||||||||||||||||||||||||||||||
| 1469 | |||||||||||||||||||||||||||||||||||||||||||
| 1470 | Optional attributes: L<refOrBranch|/refOrBranch>, L<patKey|/patKey>. | ||||||||||||||||||||||||||||||||||||||||||
| 1471 | |||||||||||||||||||||||||||||||||||||||||||
| 1472 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1473 | 1 $gitHub GitHub object | ||||||||||||||||||||||||||||||||||||||||||
| 1474 | |||||||||||||||||||||||||||||||||||||||||||
| 1475 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1476 | |||||||||||||||||||||||||||||||||||||||||||
| 1477 | |||||||||||||||||||||||||||||||||||||||||||
| 1478 | my $g = gitHub; | ||||||||||||||||||||||||||||||||||||||||||
| 1479 | $g->gitFile = "test4.html"; | ||||||||||||||||||||||||||||||||||||||||||
| 1480 | my $d = dateTimeStamp; | ||||||||||||||||||||||||||||||||||||||||||
| 1481 | $g->write($d); | ||||||||||||||||||||||||||||||||||||||||||
| 1482 | |||||||||||||||||||||||||||||||||||||||||||
| 1483 | confess "exists FAILED" unless $g->read eq $d; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1484 | |||||||||||||||||||||||||||||||||||||||||||
| 1485 | $g->delete; | ||||||||||||||||||||||||||||||||||||||||||
| 1486 | |||||||||||||||||||||||||||||||||||||||||||
| 1487 | confess "exists FAILED" if $g->read eq $d; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1488 | |||||||||||||||||||||||||||||||||||||||||||
| 1489 | success "Exists passed"; | ||||||||||||||||||||||||||||||||||||||||||
| 1490 | |||||||||||||||||||||||||||||||||||||||||||
| 1491 | |||||||||||||||||||||||||||||||||||||||||||
| 1492 | =head2 rename ($gitHub, $target) | ||||||||||||||||||||||||||||||||||||||||||
| 1493 | |||||||||||||||||||||||||||||||||||||||||||
| 1494 | Rename a source file on L<GitHub|https://github.com/philiprbrenan> if the target file name is not already in use. | ||||||||||||||||||||||||||||||||||||||||||
| 1495 | |||||||||||||||||||||||||||||||||||||||||||
| 1496 | Required attributes: L<userid|/userid>, L<repository|/repository>, L<patKey|/patKey>, L<gitFile|/gitFile> = the file to be renamed. | ||||||||||||||||||||||||||||||||||||||||||
| 1497 | |||||||||||||||||||||||||||||||||||||||||||
| 1498 | Optional attributes: L<refOrBranch|/refOrBranch>. | ||||||||||||||||||||||||||||||||||||||||||
| 1499 | |||||||||||||||||||||||||||||||||||||||||||
| 1500 | Returns the new name of the file B<renamed> if the rename was successful else B<undef> if the rename failed. | ||||||||||||||||||||||||||||||||||||||||||
| 1501 | |||||||||||||||||||||||||||||||||||||||||||
| 1502 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1503 | 1 $gitHub GitHub object | ||||||||||||||||||||||||||||||||||||||||||
| 1504 | 2 $target The new name of the file | ||||||||||||||||||||||||||||||||||||||||||
| 1505 | |||||||||||||||||||||||||||||||||||||||||||
| 1506 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1507 | |||||||||||||||||||||||||||||||||||||||||||
| 1508 | |||||||||||||||||||||||||||||||||||||||||||
| 1509 | my ($f1, $f2) = qw(zzz.data zzz2.data); | ||||||||||||||||||||||||||||||||||||||||||
| 1510 | my $g = gitHub; | ||||||||||||||||||||||||||||||||||||||||||
| 1511 | $g->gitFile = $f2; $g->delete; | ||||||||||||||||||||||||||||||||||||||||||
| 1512 | |||||||||||||||||||||||||||||||||||||||||||
| 1513 | my $d = dateTimeStamp; | ||||||||||||||||||||||||||||||||||||||||||
| 1514 | $g->gitFile = $f1; | ||||||||||||||||||||||||||||||||||||||||||
| 1515 | $g->write($d); | ||||||||||||||||||||||||||||||||||||||||||
| 1516 | |||||||||||||||||||||||||||||||||||||||||||
| 1517 | confess "rename FAILED" unless $g->read eq $d; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1518 | |||||||||||||||||||||||||||||||||||||||||||
| 1519 | |||||||||||||||||||||||||||||||||||||||||||
| 1520 | |||||||||||||||||||||||||||||||||||||||||||
| 1521 | $g->rename($f2); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1522 | |||||||||||||||||||||||||||||||||||||||||||
| 1523 | |||||||||||||||||||||||||||||||||||||||||||
| 1524 | confess "rename FAILED" if $g->exists; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1525 | |||||||||||||||||||||||||||||||||||||||||||
| 1526 | |||||||||||||||||||||||||||||||||||||||||||
| 1527 | $g->gitFile = $f2; | ||||||||||||||||||||||||||||||||||||||||||
| 1528 | |||||||||||||||||||||||||||||||||||||||||||
| 1529 | confess "rename FAILED" if $g->read eq $d; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1530 | |||||||||||||||||||||||||||||||||||||||||||
| 1531 | success "Rename passed"; | ||||||||||||||||||||||||||||||||||||||||||
| 1532 | |||||||||||||||||||||||||||||||||||||||||||
| 1533 | |||||||||||||||||||||||||||||||||||||||||||
| 1534 | =head2 delete ($gitHub) | ||||||||||||||||||||||||||||||||||||||||||
| 1535 | |||||||||||||||||||||||||||||||||||||||||||
| 1536 | Delete a file from L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 1537 | |||||||||||||||||||||||||||||||||||||||||||
| 1538 | Required attributes: L<userid|/userid>, L<repository|/repository>, L<patKey|/patKey>, L<gitFile|/gitFile> = the file to be deleted. | ||||||||||||||||||||||||||||||||||||||||||
| 1539 | |||||||||||||||||||||||||||||||||||||||||||
| 1540 | Optional attributes: L<refOrBranch|/refOrBranch>. | ||||||||||||||||||||||||||||||||||||||||||
| 1541 | |||||||||||||||||||||||||||||||||||||||||||
| 1542 | If the delete operation is successful, L<failed|/failed> is set to false otherwise it is set to true. | ||||||||||||||||||||||||||||||||||||||||||
| 1543 | |||||||||||||||||||||||||||||||||||||||||||
| 1544 | Returns true if the delete was successful else false. | ||||||||||||||||||||||||||||||||||||||||||
| 1545 | |||||||||||||||||||||||||||||||||||||||||||
| 1546 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1547 | 1 $gitHub GitHub object | ||||||||||||||||||||||||||||||||||||||||||
| 1548 | |||||||||||||||||||||||||||||||||||||||||||
| 1549 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1550 | |||||||||||||||||||||||||||||||||||||||||||
| 1551 | |||||||||||||||||||||||||||||||||||||||||||
| 1552 | my $g = gitHub; | ||||||||||||||||||||||||||||||||||||||||||
| 1553 | my $d = dateTimeStamp; | ||||||||||||||||||||||||||||||||||||||||||
| 1554 | $g->gitFile = "zzz.data"; | ||||||||||||||||||||||||||||||||||||||||||
| 1555 | $g->write($d); | ||||||||||||||||||||||||||||||||||||||||||
| 1556 | |||||||||||||||||||||||||||||||||||||||||||
| 1557 | |||||||||||||||||||||||||||||||||||||||||||
| 1558 | confess "delete FAILED" unless $g->read eq $d; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1559 | |||||||||||||||||||||||||||||||||||||||||||
| 1560 | |||||||||||||||||||||||||||||||||||||||||||
| 1561 | if (1) | ||||||||||||||||||||||||||||||||||||||||||
| 1562 | {my $t = time(); | ||||||||||||||||||||||||||||||||||||||||||
| 1563 | |||||||||||||||||||||||||||||||||||||||||||
| 1564 | my $d = $g->delete; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1565 | |||||||||||||||||||||||||||||||||||||||||||
| 1566 | lll "Delete 1: ", $d; | ||||||||||||||||||||||||||||||||||||||||||
| 1567 | |||||||||||||||||||||||||||||||||||||||||||
| 1568 | lll "First delete: ", time() - $t; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1569 | |||||||||||||||||||||||||||||||||||||||||||
| 1570 | |||||||||||||||||||||||||||||||||||||||||||
| 1571 | confess "delete FAILED" if $g->exists; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1572 | |||||||||||||||||||||||||||||||||||||||||||
| 1573 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1574 | |||||||||||||||||||||||||||||||||||||||||||
| 1575 | if (1) | ||||||||||||||||||||||||||||||||||||||||||
| 1576 | {my $t = time(); | ||||||||||||||||||||||||||||||||||||||||||
| 1577 | |||||||||||||||||||||||||||||||||||||||||||
| 1578 | my $d = $g->delete; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1579 | |||||||||||||||||||||||||||||||||||||||||||
| 1580 | lll "Delete 1: ", $d; | ||||||||||||||||||||||||||||||||||||||||||
| 1581 | |||||||||||||||||||||||||||||||||||||||||||
| 1582 | lll "Second delete: ", time() - $t; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1583 | |||||||||||||||||||||||||||||||||||||||||||
| 1584 | |||||||||||||||||||||||||||||||||||||||||||
| 1585 | confess "delete FAILED" if $g->exists; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1586 | |||||||||||||||||||||||||||||||||||||||||||
| 1587 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1588 | success "Delete passed"; | ||||||||||||||||||||||||||||||||||||||||||
| 1589 | |||||||||||||||||||||||||||||||||||||||||||
| 1590 | |||||||||||||||||||||||||||||||||||||||||||
| 1591 | =head1 Repositories | ||||||||||||||||||||||||||||||||||||||||||
| 1592 | |||||||||||||||||||||||||||||||||||||||||||
| 1593 | Perform actions on L<GitHub|https://github.com/philiprbrenan> repositories. | ||||||||||||||||||||||||||||||||||||||||||
| 1594 | |||||||||||||||||||||||||||||||||||||||||||
| 1595 | =head2 getRepository ($gitHub) | ||||||||||||||||||||||||||||||||||||||||||
| 1596 | |||||||||||||||||||||||||||||||||||||||||||
| 1597 | Get the overall details of a repository | ||||||||||||||||||||||||||||||||||||||||||
| 1598 | |||||||||||||||||||||||||||||||||||||||||||
| 1599 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1600 | 1 $gitHub GitHub object | ||||||||||||||||||||||||||||||||||||||||||
| 1601 | |||||||||||||||||||||||||||||||||||||||||||
| 1602 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1603 | |||||||||||||||||||||||||||||||||||||||||||
| 1604 | |||||||||||||||||||||||||||||||||||||||||||
| 1605 | |||||||||||||||||||||||||||||||||||||||||||
| 1606 | my $r = gitHub(repository => q(C))->getRepository; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1607 | |||||||||||||||||||||||||||||||||||||||||||
| 1608 | success "Get repository succeeded"; | ||||||||||||||||||||||||||||||||||||||||||
| 1609 | |||||||||||||||||||||||||||||||||||||||||||
| 1610 | |||||||||||||||||||||||||||||||||||||||||||
| 1611 | =head2 listCommits ($gitHub) | ||||||||||||||||||||||||||||||||||||||||||
| 1612 | |||||||||||||||||||||||||||||||||||||||||||
| 1613 | List all the commits in a L<GitHub|https://github.com/philiprbrenan> repository. | ||||||||||||||||||||||||||||||||||||||||||
| 1614 | |||||||||||||||||||||||||||||||||||||||||||
| 1615 | Required attributes: L<userid|/userid>, L<repository|/repository>. | ||||||||||||||||||||||||||||||||||||||||||
| 1616 | |||||||||||||||||||||||||||||||||||||||||||
| 1617 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1618 | 1 $gitHub GitHub object | ||||||||||||||||||||||||||||||||||||||||||
| 1619 | |||||||||||||||||||||||||||||||||||||||||||
| 1620 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1621 | |||||||||||||||||||||||||||||||||||||||||||
| 1622 | |||||||||||||||||||||||||||||||||||||||||||
| 1623 | |||||||||||||||||||||||||||||||||||||||||||
| 1624 | my $c = gitHub->listCommits; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1625 | |||||||||||||||||||||||||||||||||||||||||||
| 1626 | my %s = listCommitShas $c; | ||||||||||||||||||||||||||||||||||||||||||
| 1627 | lll "Commits | ||||||||||||||||||||||||||||||||||||||||||
| 1628 | ", dump $c; | ||||||||||||||||||||||||||||||||||||||||||
| 1629 | lll "Commit shas | ||||||||||||||||||||||||||||||||||||||||||
| 1630 | ", dump \%s; | ||||||||||||||||||||||||||||||||||||||||||
| 1631 | success "ListCommits passed"; | ||||||||||||||||||||||||||||||||||||||||||
| 1632 | |||||||||||||||||||||||||||||||||||||||||||
| 1633 | |||||||||||||||||||||||||||||||||||||||||||
| 1634 | =head2 listCommitShas ($commits) | ||||||||||||||||||||||||||||||||||||||||||
| 1635 | |||||||||||||||||||||||||||||||||||||||||||
| 1636 | Create {commit name => sha} from the results of L</listCommits>. | ||||||||||||||||||||||||||||||||||||||||||
| 1637 | |||||||||||||||||||||||||||||||||||||||||||
| 1638 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1639 | 1 $commits Commits from L</listCommits> | ||||||||||||||||||||||||||||||||||||||||||
| 1640 | |||||||||||||||||||||||||||||||||||||||||||
| 1641 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1642 | |||||||||||||||||||||||||||||||||||||||||||
| 1643 | |||||||||||||||||||||||||||||||||||||||||||
| 1644 | my $c = gitHub->listCommits; | ||||||||||||||||||||||||||||||||||||||||||
| 1645 | |||||||||||||||||||||||||||||||||||||||||||
| 1646 | my %s = listCommitShas $c; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1647 | |||||||||||||||||||||||||||||||||||||||||||
| 1648 | lll "Commits | ||||||||||||||||||||||||||||||||||||||||||
| 1649 | ", dump $c; | ||||||||||||||||||||||||||||||||||||||||||
| 1650 | lll "Commit shas | ||||||||||||||||||||||||||||||||||||||||||
| 1651 | ", dump \%s; | ||||||||||||||||||||||||||||||||||||||||||
| 1652 | success "ListCommits passed"; | ||||||||||||||||||||||||||||||||||||||||||
| 1653 | |||||||||||||||||||||||||||||||||||||||||||
| 1654 | |||||||||||||||||||||||||||||||||||||||||||
| 1655 | =head2 writeCommit ($gitHub, $folder, @files) | ||||||||||||||||||||||||||||||||||||||||||
| 1656 | |||||||||||||||||||||||||||||||||||||||||||
| 1657 | Write all the files in a B<$folder> (or just the the named files) into a L<GitHub|https://github.com/philiprbrenan> repository in parallel as a commit on the specified branch. | ||||||||||||||||||||||||||||||||||||||||||
| 1658 | |||||||||||||||||||||||||||||||||||||||||||
| 1659 | Required attributes: L<userid|/userid>, L<repository|/repository>, L<refOrBranch|/refOrBranch>. | ||||||||||||||||||||||||||||||||||||||||||
| 1660 | |||||||||||||||||||||||||||||||||||||||||||
| 1661 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1662 | 1 $gitHub GitHub object | ||||||||||||||||||||||||||||||||||||||||||
| 1663 | 2 $folder File prefix to remove | ||||||||||||||||||||||||||||||||||||||||||
| 1664 | 3 @files Files to write | ||||||||||||||||||||||||||||||||||||||||||
| 1665 | |||||||||||||||||||||||||||||||||||||||||||
| 1666 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1667 | |||||||||||||||||||||||||||||||||||||||||||
| 1668 | |||||||||||||||||||||||||||||||||||||||||||
| 1669 | my $f = temporaryFolder; # Folder in which we will create some files to upload in the commit | ||||||||||||||||||||||||||||||||||||||||||
| 1670 | my $c = dateTimeStamp; # Create some content | ||||||||||||||||||||||||||||||||||||||||||
| 1671 | my $if = q(/home/phil/.face); # Image file | ||||||||||||||||||||||||||||||||||||||||||
| 1672 | |||||||||||||||||||||||||||||||||||||||||||
| 1673 | writeFile(fpe($f, q(data), $_, qw(txt)), $c) for 1..3; # Place content in files in a sub folder | ||||||||||||||||||||||||||||||||||||||||||
| 1674 | copyBinaryFile $if, my $If = fpe $f, qw(face jpg); # Add an image | ||||||||||||||||||||||||||||||||||||||||||
| 1675 | |||||||||||||||||||||||||||||||||||||||||||
| 1676 | my $g = GitHub::Crud::new # Create GitHub | ||||||||||||||||||||||||||||||||||||||||||
| 1677 | (userid => q(philiprbrenan), | ||||||||||||||||||||||||||||||||||||||||||
| 1678 | repository => q(aaa), | ||||||||||||||||||||||||||||||||||||||||||
| 1679 | branch => q(test), | ||||||||||||||||||||||||||||||||||||||||||
| 1680 | confessOnFailure => 1); | ||||||||||||||||||||||||||||||||||||||||||
| 1681 | |||||||||||||||||||||||||||||||||||||||||||
| 1682 | $g->loadPersonalAccessToken; # Load a personal access token | ||||||||||||||||||||||||||||||||||||||||||
| 1683 | |||||||||||||||||||||||||||||||||||||||||||
| 1684 | $g->writeCommit($f); # Upload commit - confess to any errors # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1685 | |||||||||||||||||||||||||||||||||||||||||||
| 1686 | |||||||||||||||||||||||||||||||||||||||||||
| 1687 | my $C = $g->read(q(data/1.txt)); # Read data written in commit | ||||||||||||||||||||||||||||||||||||||||||
| 1688 | my $I = $g->read(q(face.jpg)); | ||||||||||||||||||||||||||||||||||||||||||
| 1689 | my $i = readBinaryFile $if; | ||||||||||||||||||||||||||||||||||||||||||
| 1690 | |||||||||||||||||||||||||||||||||||||||||||
| 1691 | confess "Date stamp failed" unless $C eq $c; # Check text | ||||||||||||||||||||||||||||||||||||||||||
| 1692 | confess "Image failed" unless $i eq $I; # Check image | ||||||||||||||||||||||||||||||||||||||||||
| 1693 | success "Write commit succeeded"; | ||||||||||||||||||||||||||||||||||||||||||
| 1694 | |||||||||||||||||||||||||||||||||||||||||||
| 1695 | |||||||||||||||||||||||||||||||||||||||||||
| 1696 | =head2 listWebHooks($gitHub) | ||||||||||||||||||||||||||||||||||||||||||
| 1697 | |||||||||||||||||||||||||||||||||||||||||||
| 1698 | List web hooks associated with your L<GitHub|https://github.com/philiprbrenan> repository. | ||||||||||||||||||||||||||||||||||||||||||
| 1699 | |||||||||||||||||||||||||||||||||||||||||||
| 1700 | Required: L<userid|/userid>, L<repository|/repository>, L<patKey|/patKey>. | ||||||||||||||||||||||||||||||||||||||||||
| 1701 | |||||||||||||||||||||||||||||||||||||||||||
| 1702 | If the list operation is successful, L<failed|/failed> is set to false otherwise it is set to true. | ||||||||||||||||||||||||||||||||||||||||||
| 1703 | |||||||||||||||||||||||||||||||||||||||||||
| 1704 | Returns true if the list operation was successful else false. | ||||||||||||||||||||||||||||||||||||||||||
| 1705 | |||||||||||||||||||||||||||||||||||||||||||
| 1706 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1707 | 1 $gitHub GitHub object | ||||||||||||||||||||||||||||||||||||||||||
| 1708 | |||||||||||||||||||||||||||||||||||||||||||
| 1709 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1710 | |||||||||||||||||||||||||||||||||||||||||||
| 1711 | |||||||||||||||||||||||||||||||||||||||||||
| 1712 | |||||||||||||||||||||||||||||||||||||||||||
| 1713 | success join ' ', q(Webhooks:), dump(gitHub->listWebHooks); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1714 | |||||||||||||||||||||||||||||||||||||||||||
| 1715 | |||||||||||||||||||||||||||||||||||||||||||
| 1716 | |||||||||||||||||||||||||||||||||||||||||||
| 1717 | =head2 createPushWebHook ($gitHub) | ||||||||||||||||||||||||||||||||||||||||||
| 1718 | |||||||||||||||||||||||||||||||||||||||||||
| 1719 | Create a web hook for your L<GitHub|https://github.com/philiprbrenan> userid. | ||||||||||||||||||||||||||||||||||||||||||
| 1720 | |||||||||||||||||||||||||||||||||||||||||||
| 1721 | Required: L<userid|/userid>, L<repository|/repository>, L<url|/url>, L<patKey|/patKey>. | ||||||||||||||||||||||||||||||||||||||||||
| 1722 | |||||||||||||||||||||||||||||||||||||||||||
| 1723 | Optional: L<secret|/secret>. | ||||||||||||||||||||||||||||||||||||||||||
| 1724 | |||||||||||||||||||||||||||||||||||||||||||
| 1725 | If the create operation is successful, L<failed|/failed> is set to false otherwise it is set to true. | ||||||||||||||||||||||||||||||||||||||||||
| 1726 | |||||||||||||||||||||||||||||||||||||||||||
| 1727 | Returns true if the web hook was created successfully else false. | ||||||||||||||||||||||||||||||||||||||||||
| 1728 | |||||||||||||||||||||||||||||||||||||||||||
| 1729 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1730 | 1 $gitHub GitHub object | ||||||||||||||||||||||||||||||||||||||||||
| 1731 | |||||||||||||||||||||||||||||||||||||||||||
| 1732 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1733 | |||||||||||||||||||||||||||||||||||||||||||
| 1734 | |||||||||||||||||||||||||||||||||||||||||||
| 1735 | my $g = gitHub; | ||||||||||||||||||||||||||||||||||||||||||
| 1736 | |||||||||||||||||||||||||||||||||||||||||||
| 1737 | my $d = $g->createPushWebHook; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1738 | |||||||||||||||||||||||||||||||||||||||||||
| 1739 | success join ' ', "Create web hook:", dump($d); | ||||||||||||||||||||||||||||||||||||||||||
| 1740 | |||||||||||||||||||||||||||||||||||||||||||
| 1741 | |||||||||||||||||||||||||||||||||||||||||||
| 1742 | =head2 listRepositories($gitHub) | ||||||||||||||||||||||||||||||||||||||||||
| 1743 | |||||||||||||||||||||||||||||||||||||||||||
| 1744 | List the repositories accessible to a user on L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 1745 | |||||||||||||||||||||||||||||||||||||||||||
| 1746 | Required: L<userid|/userid>. | ||||||||||||||||||||||||||||||||||||||||||
| 1747 | |||||||||||||||||||||||||||||||||||||||||||
| 1748 | Returns details of the repositories. | ||||||||||||||||||||||||||||||||||||||||||
| 1749 | |||||||||||||||||||||||||||||||||||||||||||
| 1750 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1751 | 1 $gitHub GitHub object | ||||||||||||||||||||||||||||||||||||||||||
| 1752 | |||||||||||||||||||||||||||||||||||||||||||
| 1753 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1754 | |||||||||||||||||||||||||||||||||||||||||||
| 1755 | |||||||||||||||||||||||||||||||||||||||||||
| 1756 | |||||||||||||||||||||||||||||||||||||||||||
| 1757 | success "List repositories: ", dump(gitHub()->listRepositories); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1758 | |||||||||||||||||||||||||||||||||||||||||||
| 1759 | |||||||||||||||||||||||||||||||||||||||||||
| 1760 | |||||||||||||||||||||||||||||||||||||||||||
| 1761 | =head2 createRepository($gitHub) | ||||||||||||||||||||||||||||||||||||||||||
| 1762 | |||||||||||||||||||||||||||||||||||||||||||
| 1763 | Create a repository on L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 1764 | |||||||||||||||||||||||||||||||||||||||||||
| 1765 | Required: L<userid|/userid>, L<repository|/repository>. | ||||||||||||||||||||||||||||||||||||||||||
| 1766 | |||||||||||||||||||||||||||||||||||||||||||
| 1767 | Returns true if the issue was created successfully else false. | ||||||||||||||||||||||||||||||||||||||||||
| 1768 | |||||||||||||||||||||||||||||||||||||||||||
| 1769 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1770 | 1 $gitHub GitHub object | ||||||||||||||||||||||||||||||||||||||||||
| 1771 | |||||||||||||||||||||||||||||||||||||||||||
| 1772 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1773 | |||||||||||||||||||||||||||||||||||||||||||
| 1774 | |||||||||||||||||||||||||||||||||||||||||||
| 1775 | |||||||||||||||||||||||||||||||||||||||||||
| 1776 | gitHub(repository => q(ccc))->createRepository; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1777 | |||||||||||||||||||||||||||||||||||||||||||
| 1778 | success "Create repository succeeded"; | ||||||||||||||||||||||||||||||||||||||||||
| 1779 | |||||||||||||||||||||||||||||||||||||||||||
| 1780 | |||||||||||||||||||||||||||||||||||||||||||
| 1781 | =head2 createRepositoryFromSavedToken ($userid, $repository, $private, $accessFolderOrToken) | ||||||||||||||||||||||||||||||||||||||||||
| 1782 | |||||||||||||||||||||||||||||||||||||||||||
| 1783 | Create a repository on L<GitHub|https://github.com/philiprbrenan> using an access token either as supplied or saved in a file using L<savePersonalAccessToken|/savePersonalAccessToken>. | ||||||||||||||||||||||||||||||||||||||||||
| 1784 | |||||||||||||||||||||||||||||||||||||||||||
| 1785 | Returns true if the issue was created successfully else false. | ||||||||||||||||||||||||||||||||||||||||||
| 1786 | |||||||||||||||||||||||||||||||||||||||||||
| 1787 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1788 | 1 $userid Userid on GitHub | ||||||||||||||||||||||||||||||||||||||||||
| 1789 | 2 $repository The repository name | ||||||||||||||||||||||||||||||||||||||||||
| 1790 | 3 $private True if the repo is private | ||||||||||||||||||||||||||||||||||||||||||
| 1791 | 4 $accessFolderOrToken Location of access token. | ||||||||||||||||||||||||||||||||||||||||||
| 1792 | |||||||||||||||||||||||||||||||||||||||||||
| 1793 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1794 | |||||||||||||||||||||||||||||||||||||||||||
| 1795 | |||||||||||||||||||||||||||||||||||||||||||
| 1796 | |||||||||||||||||||||||||||||||||||||||||||
| 1797 | createRepositoryFromSavedToken(q(philiprbrenan), q(ddd)); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1798 | |||||||||||||||||||||||||||||||||||||||||||
| 1799 | success "Create repository succeeded"; | ||||||||||||||||||||||||||||||||||||||||||
| 1800 | |||||||||||||||||||||||||||||||||||||||||||
| 1801 | |||||||||||||||||||||||||||||||||||||||||||
| 1802 | =head1 Issues | ||||||||||||||||||||||||||||||||||||||||||
| 1803 | |||||||||||||||||||||||||||||||||||||||||||
| 1804 | Create issues on L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 1805 | |||||||||||||||||||||||||||||||||||||||||||
| 1806 | =head2 createIssue ($gitHub) | ||||||||||||||||||||||||||||||||||||||||||
| 1807 | |||||||||||||||||||||||||||||||||||||||||||
| 1808 | Create an issue on L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 1809 | |||||||||||||||||||||||||||||||||||||||||||
| 1810 | Required: L<userid|/userid>, L<repository|/repository>, L<body|/body>, L<title|/title>. | ||||||||||||||||||||||||||||||||||||||||||
| 1811 | |||||||||||||||||||||||||||||||||||||||||||
| 1812 | If the operation is successful, L<failed|/failed> is set to false otherwise it is set to true. | ||||||||||||||||||||||||||||||||||||||||||
| 1813 | |||||||||||||||||||||||||||||||||||||||||||
| 1814 | Returns true if the issue was created successfully else false. | ||||||||||||||||||||||||||||||||||||||||||
| 1815 | |||||||||||||||||||||||||||||||||||||||||||
| 1816 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1817 | 1 $gitHub GitHub object | ||||||||||||||||||||||||||||||||||||||||||
| 1818 | |||||||||||||||||||||||||||||||||||||||||||
| 1819 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1820 | |||||||||||||||||||||||||||||||||||||||||||
| 1821 | |||||||||||||||||||||||||||||||||||||||||||
| 1822 | |||||||||||||||||||||||||||||||||||||||||||
| 1823 | gitHub(title=>q(Hello), body=>q(World))->createIssue; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1824 | |||||||||||||||||||||||||||||||||||||||||||
| 1825 | success "Create issue succeeded"; | ||||||||||||||||||||||||||||||||||||||||||
| 1826 | |||||||||||||||||||||||||||||||||||||||||||
| 1827 | |||||||||||||||||||||||||||||||||||||||||||
| 1828 | =head1 Using saved access tokens | ||||||||||||||||||||||||||||||||||||||||||
| 1829 | |||||||||||||||||||||||||||||||||||||||||||
| 1830 | Call methods directly using a saved access token rather than first creating a L<GitHub|https://github.com/philiprbrenan> description object and then calling methods using it. This is often more convenient if you just want to perform one or two actions using a L<Perl|http://www.perl.org/> one liner. See: L<https://github.com/philiprbrenan/GitHubCrud/blob/main/.github/workflows/main.yml> for examples in action. | ||||||||||||||||||||||||||||||||||||||||||
| 1831 | |||||||||||||||||||||||||||||||||||||||||||
| 1832 | =head2 createIssueFromSavedToken ($userid, $repository, $title, $body, $accessFolderOrToken) | ||||||||||||||||||||||||||||||||||||||||||
| 1833 | |||||||||||||||||||||||||||||||||||||||||||
| 1834 | Create an issue on L<GitHub|https://github.com/philiprbrenan> using an access token as supplied or saved in a file using L<savePersonalAccessToken|/savePersonalAccessToken>. | ||||||||||||||||||||||||||||||||||||||||||
| 1835 | |||||||||||||||||||||||||||||||||||||||||||
| 1836 | Returns true if the issue was created successfully else false. | ||||||||||||||||||||||||||||||||||||||||||
| 1837 | |||||||||||||||||||||||||||||||||||||||||||
| 1838 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1839 | 1 $userid Userid on GitHub | ||||||||||||||||||||||||||||||||||||||||||
| 1840 | 2 $repository Repository name | ||||||||||||||||||||||||||||||||||||||||||
| 1841 | 3 $title Issue title | ||||||||||||||||||||||||||||||||||||||||||
| 1842 | 4 $body Issue body | ||||||||||||||||||||||||||||||||||||||||||
| 1843 | 5 $accessFolderOrToken Location of access token. | ||||||||||||||||||||||||||||||||||||||||||
| 1844 | |||||||||||||||||||||||||||||||||||||||||||
| 1845 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1846 | |||||||||||||||||||||||||||||||||||||||||||
| 1847 | |||||||||||||||||||||||||||||||||||||||||||
| 1848 | |||||||||||||||||||||||||||||||||||||||||||
| 1849 | &createIssueFromSavedToken(qw(philiprbrenan ddd hello World)); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1850 | |||||||||||||||||||||||||||||||||||||||||||
| 1851 | success "Create issue succeeded"; | ||||||||||||||||||||||||||||||||||||||||||
| 1852 | |||||||||||||||||||||||||||||||||||||||||||
| 1853 | |||||||||||||||||||||||||||||||||||||||||||
| 1854 | =head2 writeFileUsingSavedToken($userid, $repository, $file, $content, $accessFolderOrToken) | ||||||||||||||||||||||||||||||||||||||||||
| 1855 | |||||||||||||||||||||||||||||||||||||||||||
| 1856 | Write to a file on L<GitHub|https://github.com/philiprbrenan> using a personal access token as supplied or saved in a file. Return B<1> on success or confess to any failure. | ||||||||||||||||||||||||||||||||||||||||||
| 1857 | |||||||||||||||||||||||||||||||||||||||||||
| 1858 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1859 | 1 $userid Userid on GitHub | ||||||||||||||||||||||||||||||||||||||||||
| 1860 | 2 $repository Repository name | ||||||||||||||||||||||||||||||||||||||||||
| 1861 | 3 $file File name on github | ||||||||||||||||||||||||||||||||||||||||||
| 1862 | 4 $content File content | ||||||||||||||||||||||||||||||||||||||||||
| 1863 | 5 $accessFolderOrToken Location of access token. | ||||||||||||||||||||||||||||||||||||||||||
| 1864 | |||||||||||||||||||||||||||||||||||||||||||
| 1865 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1866 | |||||||||||||||||||||||||||||||||||||||||||
| 1867 | |||||||||||||||||||||||||||||||||||||||||||
| 1868 | my $s = q(HelloWorld); | ||||||||||||||||||||||||||||||||||||||||||
| 1869 | |||||||||||||||||||||||||||||||||||||||||||
| 1870 | &writeFileUsingSavedToken(qw(philiprbrenan ddd hello.txt), $s); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1871 | |||||||||||||||||||||||||||||||||||||||||||
| 1872 | my $S = gitHub(repository=>q(ddd), gitFile=>q(hello.txt))->read; | ||||||||||||||||||||||||||||||||||||||||||
| 1873 | |||||||||||||||||||||||||||||||||||||||||||
| 1874 | confess "Write file using saved token FAILED" unless $s eq $S; | ||||||||||||||||||||||||||||||||||||||||||
| 1875 | success "Write file using saved token succeeded"; | ||||||||||||||||||||||||||||||||||||||||||
| 1876 | |||||||||||||||||||||||||||||||||||||||||||
| 1877 | |||||||||||||||||||||||||||||||||||||||||||
| 1878 | =head2 writeFileFromFileUsingSavedToken($userid, $repository, $file, $localFile, $accessFolderOrToken) | ||||||||||||||||||||||||||||||||||||||||||
| 1879 | |||||||||||||||||||||||||||||||||||||||||||
| 1880 | Copy a file to L<GitHub|https://github.com/philiprbrenan> using a personal access token as supplied or saved in a file. Return B<1> on success or confess to any failure. | ||||||||||||||||||||||||||||||||||||||||||
| 1881 | |||||||||||||||||||||||||||||||||||||||||||
| 1882 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1883 | 1 $userid Userid on GitHub | ||||||||||||||||||||||||||||||||||||||||||
| 1884 | 2 $repository Repository name | ||||||||||||||||||||||||||||||||||||||||||
| 1885 | 3 $file File name on github | ||||||||||||||||||||||||||||||||||||||||||
| 1886 | 4 $localFile File content | ||||||||||||||||||||||||||||||||||||||||||
| 1887 | 5 $accessFolderOrToken Location of access token. | ||||||||||||||||||||||||||||||||||||||||||
| 1888 | |||||||||||||||||||||||||||||||||||||||||||
| 1889 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1890 | |||||||||||||||||||||||||||||||||||||||||||
| 1891 | |||||||||||||||||||||||||||||||||||||||||||
| 1892 | my $f = writeFile(undef, my $s = "World | ||||||||||||||||||||||||||||||||||||||||||
| 1893 | "); | ||||||||||||||||||||||||||||||||||||||||||
| 1894 | |||||||||||||||||||||||||||||||||||||||||||
| 1895 | &writeFileFromFileUsingSavedToken(qw(philiprbrenan ddd hello.txt), $f); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1896 | |||||||||||||||||||||||||||||||||||||||||||
| 1897 | my $S = gitHub(repository=>q(ddd), gitFile=>q(hello.txt))->read; | ||||||||||||||||||||||||||||||||||||||||||
| 1898 | confess "Write file from file using saved token FAILED" unless $s eq $S; | ||||||||||||||||||||||||||||||||||||||||||
| 1899 | success "Write file from file using saved token succeeded" | ||||||||||||||||||||||||||||||||||||||||||
| 1900 | |||||||||||||||||||||||||||||||||||||||||||
| 1901 | |||||||||||||||||||||||||||||||||||||||||||
| 1902 | =head2 readFileUsingSavedToken ($userid, $repository, $file, $accessFolderOrToken) | ||||||||||||||||||||||||||||||||||||||||||
| 1903 | |||||||||||||||||||||||||||||||||||||||||||
| 1904 | Read from a file on L<GitHub|https://github.com/philiprbrenan> using a personal access token as supplied or saved in a file. Return the content of the file on success or confess to any failure. | ||||||||||||||||||||||||||||||||||||||||||
| 1905 | |||||||||||||||||||||||||||||||||||||||||||
| 1906 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1907 | 1 $userid Userid on GitHub | ||||||||||||||||||||||||||||||||||||||||||
| 1908 | 2 $repository Repository name | ||||||||||||||||||||||||||||||||||||||||||
| 1909 | 3 $file File name on GitHub | ||||||||||||||||||||||||||||||||||||||||||
| 1910 | 4 $accessFolderOrToken Location of access token. | ||||||||||||||||||||||||||||||||||||||||||
| 1911 | |||||||||||||||||||||||||||||||||||||||||||
| 1912 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1913 | |||||||||||||||||||||||||||||||||||||||||||
| 1914 | |||||||||||||||||||||||||||||||||||||||||||
| 1915 | my $s = q(Hello to the World); | ||||||||||||||||||||||||||||||||||||||||||
| 1916 | &writeFileUsingSavedToken(qw(philiprbrenan ddd hello.txt), $s); | ||||||||||||||||||||||||||||||||||||||||||
| 1917 | |||||||||||||||||||||||||||||||||||||||||||
| 1918 | my $S = &readFileUsingSavedToken (qw(philiprbrenan ddd hello.txt)); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1919 | |||||||||||||||||||||||||||||||||||||||||||
| 1920 | |||||||||||||||||||||||||||||||||||||||||||
| 1921 | confess "Read file using saved token FAILED" unless $s eq $S; | ||||||||||||||||||||||||||||||||||||||||||
| 1922 | success "Read file using saved token succeeded" | ||||||||||||||||||||||||||||||||||||||||||
| 1923 | |||||||||||||||||||||||||||||||||||||||||||
| 1924 | |||||||||||||||||||||||||||||||||||||||||||
| 1925 | =head2 writeFolderUsingSavedToken ($userid, $repository, $targetFolder, $localFolder, $accessFolderOrToken) | ||||||||||||||||||||||||||||||||||||||||||
| 1926 | |||||||||||||||||||||||||||||||||||||||||||
| 1927 | Write all the files in a local folder to a target folder on a named L<GitHub|https://github.com/philiprbrenan> repository using a personal access token as supplied or saved in a file. | ||||||||||||||||||||||||||||||||||||||||||
| 1928 | |||||||||||||||||||||||||||||||||||||||||||
| 1929 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1930 | 1 $userid Userid on GitHub | ||||||||||||||||||||||||||||||||||||||||||
| 1931 | 2 $repository Repository name | ||||||||||||||||||||||||||||||||||||||||||
| 1932 | 3 $targetFolder Target folder on GitHub | ||||||||||||||||||||||||||||||||||||||||||
| 1933 | 4 $localFolder Local folder name | ||||||||||||||||||||||||||||||||||||||||||
| 1934 | 5 $accessFolderOrToken Location of access token. | ||||||||||||||||||||||||||||||||||||||||||
| 1935 | |||||||||||||||||||||||||||||||||||||||||||
| 1936 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1937 | |||||||||||||||||||||||||||||||||||||||||||
| 1938 | |||||||||||||||||||||||||||||||||||||||||||
| 1939 | writeCommitUsingSavedToken("philiprbrenan", "test", "/home/phil/files/"); | ||||||||||||||||||||||||||||||||||||||||||
| 1940 | |||||||||||||||||||||||||||||||||||||||||||
| 1941 | writeFolderUsingSavedToken("philiprbrenan", "test", "files", "/home/phil/files/"); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1942 | |||||||||||||||||||||||||||||||||||||||||||
| 1943 | |||||||||||||||||||||||||||||||||||||||||||
| 1944 | |||||||||||||||||||||||||||||||||||||||||||
| 1945 | =head2 writeCommitUsingSavedToken ($userid, $repository, $source, $accessFolderOrToken) | ||||||||||||||||||||||||||||||||||||||||||
| 1946 | |||||||||||||||||||||||||||||||||||||||||||
| 1947 | Write all the files in a local folder to a named L<GitHub|https://github.com/philiprbrenan> repository using a personal access token as supplied or saved in a file. | ||||||||||||||||||||||||||||||||||||||||||
| 1948 | |||||||||||||||||||||||||||||||||||||||||||
| 1949 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1950 | 1 $userid Userid on GitHub | ||||||||||||||||||||||||||||||||||||||||||
| 1951 | 2 $repository Repository name | ||||||||||||||||||||||||||||||||||||||||||
| 1952 | 3 $source Local folder on GitHub | ||||||||||||||||||||||||||||||||||||||||||
| 1953 | 4 $accessFolderOrToken Optionally: location of access token. | ||||||||||||||||||||||||||||||||||||||||||
| 1954 | |||||||||||||||||||||||||||||||||||||||||||
| 1955 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1956 | |||||||||||||||||||||||||||||||||||||||||||
| 1957 | |||||||||||||||||||||||||||||||||||||||||||
| 1958 | |||||||||||||||||||||||||||||||||||||||||||
| 1959 | writeCommitUsingSavedToken("philiprbrenan", "test", "/home/phil/files/"); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1960 | |||||||||||||||||||||||||||||||||||||||||||
| 1961 | writeFolderUsingSavedToken("philiprbrenan", "test", "files", "/home/phil/files/"); | ||||||||||||||||||||||||||||||||||||||||||
| 1962 | |||||||||||||||||||||||||||||||||||||||||||
| 1963 | |||||||||||||||||||||||||||||||||||||||||||
| 1964 | =head2 deleteFileUsingSavedToken ($userid, $repository, $target, $accessFolderOrToken) | ||||||||||||||||||||||||||||||||||||||||||
| 1965 | |||||||||||||||||||||||||||||||||||||||||||
| 1966 | Delete a file on L<GitHub|https://github.com/philiprbrenan> using a saved token | ||||||||||||||||||||||||||||||||||||||||||
| 1967 | |||||||||||||||||||||||||||||||||||||||||||
| 1968 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1969 | 1 $userid Userid on GitHub | ||||||||||||||||||||||||||||||||||||||||||
| 1970 | 2 $repository Repository name | ||||||||||||||||||||||||||||||||||||||||||
| 1971 | 3 $target File on GitHub | ||||||||||||||||||||||||||||||||||||||||||
| 1972 | 4 $accessFolderOrToken Optional: the folder containing saved access tokens. | ||||||||||||||||||||||||||||||||||||||||||
| 1973 | |||||||||||||||||||||||||||||||||||||||||||
| 1974 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1975 | |||||||||||||||||||||||||||||||||||||||||||
| 1976 | |||||||||||||||||||||||||||||||||||||||||||
| 1977 | |||||||||||||||||||||||||||||||||||||||||||
| 1978 | deleteFileUsingSavedToken("philiprbrenan", "test", "aaa.data"); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1979 | |||||||||||||||||||||||||||||||||||||||||||
| 1980 | |||||||||||||||||||||||||||||||||||||||||||
| 1981 | |||||||||||||||||||||||||||||||||||||||||||
| 1982 | =head2 getRepositoryUsingSavedToken($userid, $repository, $accessFolderOrToken) | ||||||||||||||||||||||||||||||||||||||||||
| 1983 | |||||||||||||||||||||||||||||||||||||||||||
| 1984 | Get repository details from L<GitHub|https://github.com/philiprbrenan> using a saved token | ||||||||||||||||||||||||||||||||||||||||||
| 1985 | |||||||||||||||||||||||||||||||||||||||||||
| 1986 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 1987 | 1 $userid Userid on GitHub | ||||||||||||||||||||||||||||||||||||||||||
| 1988 | 2 $repository Repository name | ||||||||||||||||||||||||||||||||||||||||||
| 1989 | 3 $accessFolderOrToken Optionally: location of access token. | ||||||||||||||||||||||||||||||||||||||||||
| 1990 | |||||||||||||||||||||||||||||||||||||||||||
| 1991 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 1992 | |||||||||||||||||||||||||||||||||||||||||||
| 1993 | |||||||||||||||||||||||||||||||||||||||||||
| 1994 | |||||||||||||||||||||||||||||||||||||||||||
| 1995 | my $r = getRepositoryUsingSavedToken(q(philiprbrenan), q(aaa)); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 1996 | |||||||||||||||||||||||||||||||||||||||||||
| 1997 | success "Get repository using saved access token succeeded"; | ||||||||||||||||||||||||||||||||||||||||||
| 1998 | |||||||||||||||||||||||||||||||||||||||||||
| 1999 | |||||||||||||||||||||||||||||||||||||||||||
| 2000 | =head2 listRepositoryUsingSavedToken ($userid, $repository, $accessFolderOrToken) | ||||||||||||||||||||||||||||||||||||||||||
| 2001 | |||||||||||||||||||||||||||||||||||||||||||
| 2002 | List the files in a repository using a saved token | ||||||||||||||||||||||||||||||||||||||||||
| 2003 | |||||||||||||||||||||||||||||||||||||||||||
| 2004 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 2005 | 1 $userid Userid on GitHub | ||||||||||||||||||||||||||||||||||||||||||
| 2006 | 2 $repository Repository name | ||||||||||||||||||||||||||||||||||||||||||
| 2007 | 3 $accessFolderOrToken Optionally: location of access token. | ||||||||||||||||||||||||||||||||||||||||||
| 2008 | |||||||||||||||||||||||||||||||||||||||||||
| 2009 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 2010 | |||||||||||||||||||||||||||||||||||||||||||
| 2011 | |||||||||||||||||||||||||||||||||||||||||||
| 2012 | |||||||||||||||||||||||||||||||||||||||||||
| 2013 | listRepositoryUsingSavedToken("philiprbrenan", "test", "/home/phil/files/"); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 2014 | |||||||||||||||||||||||||||||||||||||||||||
| 2015 | |||||||||||||||||||||||||||||||||||||||||||
| 2016 | |||||||||||||||||||||||||||||||||||||||||||
| 2017 | =head2 getRepositoryUpdatedAtUsingSavedToken ($userid, $repository, $accessFolderOrToken) | ||||||||||||||||||||||||||||||||||||||||||
| 2018 | |||||||||||||||||||||||||||||||||||||||||||
| 2019 | Get the last time a repository was updated via the 'updated_at' field using a saved token and return the time in number of seconds since the Unix epoch. | ||||||||||||||||||||||||||||||||||||||||||
| 2020 | |||||||||||||||||||||||||||||||||||||||||||
| 2021 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 2022 | 1 $userid Userid on GitHub | ||||||||||||||||||||||||||||||||||||||||||
| 2023 | 2 $repository Repository name | ||||||||||||||||||||||||||||||||||||||||||
| 2024 | 3 $accessFolderOrToken Optionally: location of access token. | ||||||||||||||||||||||||||||||||||||||||||
| 2025 | |||||||||||||||||||||||||||||||||||||||||||
| 2026 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 2027 | |||||||||||||||||||||||||||||||||||||||||||
| 2028 | |||||||||||||||||||||||||||||||||||||||||||
| 2029 | |||||||||||||||||||||||||||||||||||||||||||
| 2030 | my $u = getRepositoryUpdatedAtUsingSavedToken(q(philiprbrenan), q(aaa)); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 2031 | |||||||||||||||||||||||||||||||||||||||||||
| 2032 | success "Get repository updated_at field succeeded"; | ||||||||||||||||||||||||||||||||||||||||||
| 2033 | |||||||||||||||||||||||||||||||||||||||||||
| 2034 | |||||||||||||||||||||||||||||||||||||||||||
| 2035 | =head1 Actions | ||||||||||||||||||||||||||||||||||||||||||
| 2036 | |||||||||||||||||||||||||||||||||||||||||||
| 2037 | Perform an action against the current repository while running as a L<GitHub|https://github.com/philiprbrenan> action. If such an action requires a security token please supply the token as shown in at the end of: L<https://github.com/philiprbrenan/maze/blob/main/.github/workflows/main.yml>. | ||||||||||||||||||||||||||||||||||||||||||
| 2038 | |||||||||||||||||||||||||||||||||||||||||||
| 2039 | =head2 createIssueInCurrentRepo($title, $body) | ||||||||||||||||||||||||||||||||||||||||||
| 2040 | |||||||||||||||||||||||||||||||||||||||||||
| 2041 | Create an issue in the current L<GitHub|https://github.com/philiprbrenan> repository if we are running on L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 2042 | |||||||||||||||||||||||||||||||||||||||||||
| 2043 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 2044 | 1 $title Title of issue | ||||||||||||||||||||||||||||||||||||||||||
| 2045 | 2 $body Body of issue | ||||||||||||||||||||||||||||||||||||||||||
| 2046 | |||||||||||||||||||||||||||||||||||||||||||
| 2047 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 2048 | |||||||||||||||||||||||||||||||||||||||||||
| 2049 | |||||||||||||||||||||||||||||||||||||||||||
| 2050 | |||||||||||||||||||||||||||||||||||||||||||
| 2051 | createIssueInCurrentRepo("Hello World", "Need to run Hello World"); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 2052 | |||||||||||||||||||||||||||||||||||||||||||
| 2053 | |||||||||||||||||||||||||||||||||||||||||||
| 2054 | writeFileFromCurrentRun("output.text", "Hello World"); | ||||||||||||||||||||||||||||||||||||||||||
| 2055 | writeFileFromFileFromCurrentRun("output.txt"); | ||||||||||||||||||||||||||||||||||||||||||
| 2056 | writeBinaryFileFromFileInCurrentRun("image.jpg", "out/image.jpg"); | ||||||||||||||||||||||||||||||||||||||||||
| 2057 | |||||||||||||||||||||||||||||||||||||||||||
| 2058 | |||||||||||||||||||||||||||||||||||||||||||
| 2059 | =head2 writeFileFromCurrentRun ($target, $text) | ||||||||||||||||||||||||||||||||||||||||||
| 2060 | |||||||||||||||||||||||||||||||||||||||||||
| 2061 | Write text into a file in the current L<GitHub|https://github.com/philiprbrenan> repository if we are running on L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 2062 | |||||||||||||||||||||||||||||||||||||||||||
| 2063 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 2064 | 1 $target The target file name in the repo | ||||||||||||||||||||||||||||||||||||||||||
| 2065 | 2 $text The text to write into this file | ||||||||||||||||||||||||||||||||||||||||||
| 2066 | |||||||||||||||||||||||||||||||||||||||||||
| 2067 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 2068 | |||||||||||||||||||||||||||||||||||||||||||
| 2069 | |||||||||||||||||||||||||||||||||||||||||||
| 2070 | createIssueInCurrentRepo("Hello World", "Need to run Hello World"); | ||||||||||||||||||||||||||||||||||||||||||
| 2071 | |||||||||||||||||||||||||||||||||||||||||||
| 2072 | |||||||||||||||||||||||||||||||||||||||||||
| 2073 | writeFileFromCurrentRun("output.text", "Hello World"); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 2074 | |||||||||||||||||||||||||||||||||||||||||||
| 2075 | writeFileFromFileFromCurrentRun("output.txt"); | ||||||||||||||||||||||||||||||||||||||||||
| 2076 | writeBinaryFileFromFileInCurrentRun("image.jpg", "out/image.jpg"); | ||||||||||||||||||||||||||||||||||||||||||
| 2077 | |||||||||||||||||||||||||||||||||||||||||||
| 2078 | |||||||||||||||||||||||||||||||||||||||||||
| 2079 | =head2 writeFileFromFileFromCurrentRun ($target) | ||||||||||||||||||||||||||||||||||||||||||
| 2080 | |||||||||||||||||||||||||||||||||||||||||||
| 2081 | Write to a file in the current L<GitHub|https://github.com/philiprbrenan> repository by copying a local file if we are running on L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 2082 | |||||||||||||||||||||||||||||||||||||||||||
| 2083 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 2084 | 1 $target File name both locally and in the repo | ||||||||||||||||||||||||||||||||||||||||||
| 2085 | |||||||||||||||||||||||||||||||||||||||||||
| 2086 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 2087 | |||||||||||||||||||||||||||||||||||||||||||
| 2088 | |||||||||||||||||||||||||||||||||||||||||||
| 2089 | createIssueInCurrentRepo("Hello World", "Need to run Hello World"); | ||||||||||||||||||||||||||||||||||||||||||
| 2090 | |||||||||||||||||||||||||||||||||||||||||||
| 2091 | writeFileFromCurrentRun("output.text", "Hello World"); | ||||||||||||||||||||||||||||||||||||||||||
| 2092 | |||||||||||||||||||||||||||||||||||||||||||
| 2093 | writeFileFromFileFromCurrentRun("output.txt"); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 2094 | |||||||||||||||||||||||||||||||||||||||||||
| 2095 | writeBinaryFileFromFileInCurrentRun("image.jpg", "out/image.jpg"); | ||||||||||||||||||||||||||||||||||||||||||
| 2096 | |||||||||||||||||||||||||||||||||||||||||||
| 2097 | |||||||||||||||||||||||||||||||||||||||||||
| 2098 | =head2 writeBinaryFileFromFileInCurrentRun ($target, $source) | ||||||||||||||||||||||||||||||||||||||||||
| 2099 | |||||||||||||||||||||||||||||||||||||||||||
| 2100 | Write to a file in the current L<GitHub|https://github.com/philiprbrenan> repository by copying a local binary file if we are running on L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 2101 | |||||||||||||||||||||||||||||||||||||||||||
| 2102 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 2103 | 1 $target The target file name in the repo | ||||||||||||||||||||||||||||||||||||||||||
| 2104 | 2 $source The current file name in the run | ||||||||||||||||||||||||||||||||||||||||||
| 2105 | |||||||||||||||||||||||||||||||||||||||||||
| 2106 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 2107 | |||||||||||||||||||||||||||||||||||||||||||
| 2108 | |||||||||||||||||||||||||||||||||||||||||||
| 2109 | createIssueInCurrentRepo("Hello World", "Need to run Hello World"); | ||||||||||||||||||||||||||||||||||||||||||
| 2110 | |||||||||||||||||||||||||||||||||||||||||||
| 2111 | writeFileFromCurrentRun("output.text", "Hello World"); | ||||||||||||||||||||||||||||||||||||||||||
| 2112 | writeFileFromFileFromCurrentRun("output.txt"); | ||||||||||||||||||||||||||||||||||||||||||
| 2113 | |||||||||||||||||||||||||||||||||||||||||||
| 2114 | writeBinaryFileFromFileInCurrentRun("image.jpg", "out/image.jpg"); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 2115 | |||||||||||||||||||||||||||||||||||||||||||
| 2116 | |||||||||||||||||||||||||||||||||||||||||||
| 2117 | |||||||||||||||||||||||||||||||||||||||||||
| 2118 | =head2 pushToGitHub($user, $repo, $home, @files) | ||||||||||||||||||||||||||||||||||||||||||
| 2119 | |||||||||||||||||||||||||||||||||||||||||||
| 2120 | Push some files to github | ||||||||||||||||||||||||||||||||||||||||||
| 2121 | |||||||||||||||||||||||||||||||||||||||||||
| 2122 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 2123 | 1 $user User id on github | ||||||||||||||||||||||||||||||||||||||||||
| 2124 | 2 $repo Repo name | ||||||||||||||||||||||||||||||||||||||||||
| 2125 | 3 $home Home folder name | ||||||||||||||||||||||||||||||||||||||||||
| 2126 | 4 @files List of files to upload if they have changed since the last time an upload was performed | ||||||||||||||||||||||||||||||||||||||||||
| 2127 | |||||||||||||||||||||||||||||||||||||||||||
| 2128 | =head1 Access tokens | ||||||||||||||||||||||||||||||||||||||||||
| 2129 | |||||||||||||||||||||||||||||||||||||||||||
| 2130 | Load and save access tokens. Some L<GitHub|https://github.com/philiprbrenan> requests must be signed with an L<Oauth|https://en.wikipedia.org/wiki/OAuth> access token. These methods help you store and reuse such tokens. Access tokens can be created at: L<https://github.com/settings/tokens>. | ||||||||||||||||||||||||||||||||||||||||||
| 2131 | |||||||||||||||||||||||||||||||||||||||||||
| 2132 | =head2 savePersonalAccessToken ($gitHub) | ||||||||||||||||||||||||||||||||||||||||||
| 2133 | |||||||||||||||||||||||||||||||||||||||||||
| 2134 | Save a L<GitHub|https://github.com/philiprbrenan> personal access token by userid in folder L<personalAccessTokenFolder|/personalAccessTokenFolder>. | ||||||||||||||||||||||||||||||||||||||||||
| 2135 | |||||||||||||||||||||||||||||||||||||||||||
| 2136 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 2137 | 1 $gitHub GitHub object | ||||||||||||||||||||||||||||||||||||||||||
| 2138 | |||||||||||||||||||||||||||||||||||||||||||
| 2139 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 2140 | |||||||||||||||||||||||||||||||||||||||||||
| 2141 | |||||||||||||||||||||||||||||||||||||||||||
| 2142 | my $d = temporaryFolder; | ||||||||||||||||||||||||||||||||||||||||||
| 2143 | my $t = join '', 1..20; | ||||||||||||||||||||||||||||||||||||||||||
| 2144 | |||||||||||||||||||||||||||||||||||||||||||
| 2145 | my $g = gitHub | ||||||||||||||||||||||||||||||||||||||||||
| 2146 | (userid => q(philiprbrenan), | ||||||||||||||||||||||||||||||||||||||||||
| 2147 | personalAccessToken => $t, | ||||||||||||||||||||||||||||||||||||||||||
| 2148 | personalAccessTokenFolder => $d, | ||||||||||||||||||||||||||||||||||||||||||
| 2149 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 2150 | |||||||||||||||||||||||||||||||||||||||||||
| 2151 | |||||||||||||||||||||||||||||||||||||||||||
| 2152 | $g->savePersonalAccessToken; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 2153 | |||||||||||||||||||||||||||||||||||||||||||
| 2154 | my $T = $g->loadPersonalAccessToken; | ||||||||||||||||||||||||||||||||||||||||||
| 2155 | |||||||||||||||||||||||||||||||||||||||||||
| 2156 | confess "Load/Save token FAILED" unless $t eq $T; | ||||||||||||||||||||||||||||||||||||||||||
| 2157 | success "Load/Save token succeeded" | ||||||||||||||||||||||||||||||||||||||||||
| 2158 | |||||||||||||||||||||||||||||||||||||||||||
| 2159 | |||||||||||||||||||||||||||||||||||||||||||
| 2160 | =head2 loadPersonalAccessToken ($gitHub) | ||||||||||||||||||||||||||||||||||||||||||
| 2161 | |||||||||||||||||||||||||||||||||||||||||||
| 2162 | Load a personal access token by userid from folder L<personalAccessTokenFolder|/personalAccessTokenFolder>. | ||||||||||||||||||||||||||||||||||||||||||
| 2163 | |||||||||||||||||||||||||||||||||||||||||||
| 2164 | Parameter Description | ||||||||||||||||||||||||||||||||||||||||||
| 2165 | 1 $gitHub GitHub object | ||||||||||||||||||||||||||||||||||||||||||
| 2166 | |||||||||||||||||||||||||||||||||||||||||||
| 2167 | B<Example:> | ||||||||||||||||||||||||||||||||||||||||||
| 2168 | |||||||||||||||||||||||||||||||||||||||||||
| 2169 | |||||||||||||||||||||||||||||||||||||||||||
| 2170 | my $d = temporaryFolder; | ||||||||||||||||||||||||||||||||||||||||||
| 2171 | my $t = join '', 1..20; | ||||||||||||||||||||||||||||||||||||||||||
| 2172 | |||||||||||||||||||||||||||||||||||||||||||
| 2173 | my $g = gitHub | ||||||||||||||||||||||||||||||||||||||||||
| 2174 | (userid => q(philiprbrenan), | ||||||||||||||||||||||||||||||||||||||||||
| 2175 | personalAccessToken => $t, | ||||||||||||||||||||||||||||||||||||||||||
| 2176 | personalAccessTokenFolder => $d, | ||||||||||||||||||||||||||||||||||||||||||
| 2177 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 2178 | |||||||||||||||||||||||||||||||||||||||||||
| 2179 | $g->savePersonalAccessToken; | ||||||||||||||||||||||||||||||||||||||||||
| 2180 | |||||||||||||||||||||||||||||||||||||||||||
| 2181 | my $T = $g->loadPersonalAccessToken; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 | ||||||||||||||||||||||||||||||||||||||||||
| 2182 | |||||||||||||||||||||||||||||||||||||||||||
| 2183 | |||||||||||||||||||||||||||||||||||||||||||
| 2184 | confess "Load/Save token FAILED" unless $t eq $T; | ||||||||||||||||||||||||||||||||||||||||||
| 2185 | success "Load/Save token succeeded" | ||||||||||||||||||||||||||||||||||||||||||
| 2186 | |||||||||||||||||||||||||||||||||||||||||||
| 2187 | |||||||||||||||||||||||||||||||||||||||||||
| 2188 | |||||||||||||||||||||||||||||||||||||||||||
| 2189 | =head1 Hash Definitions | ||||||||||||||||||||||||||||||||||||||||||
| 2190 | |||||||||||||||||||||||||||||||||||||||||||
| 2191 | |||||||||||||||||||||||||||||||||||||||||||
| 2192 | |||||||||||||||||||||||||||||||||||||||||||
| 2193 | |||||||||||||||||||||||||||||||||||||||||||
| 2194 | =head2 GitHub::Crud Definition | ||||||||||||||||||||||||||||||||||||||||||
| 2195 | |||||||||||||||||||||||||||||||||||||||||||
| 2196 | |||||||||||||||||||||||||||||||||||||||||||
| 2197 | Attributes describing the interface with L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 2198 | |||||||||||||||||||||||||||||||||||||||||||
| 2199 | |||||||||||||||||||||||||||||||||||||||||||
| 2200 | |||||||||||||||||||||||||||||||||||||||||||
| 2201 | |||||||||||||||||||||||||||||||||||||||||||
| 2202 | =head3 Input fields | ||||||||||||||||||||||||||||||||||||||||||
| 2203 | |||||||||||||||||||||||||||||||||||||||||||
| 2204 | |||||||||||||||||||||||||||||||||||||||||||
| 2205 | =head4 body | ||||||||||||||||||||||||||||||||||||||||||
| 2206 | |||||||||||||||||||||||||||||||||||||||||||
| 2207 | The body of an issue. | ||||||||||||||||||||||||||||||||||||||||||
| 2208 | |||||||||||||||||||||||||||||||||||||||||||
| 2209 | =head4 branch | ||||||||||||||||||||||||||||||||||||||||||
| 2210 | |||||||||||||||||||||||||||||||||||||||||||
| 2211 | Branch name (you should create this branch first) or omit it for the default branch which is usually 'master'. | ||||||||||||||||||||||||||||||||||||||||||
| 2212 | |||||||||||||||||||||||||||||||||||||||||||
| 2213 | =head4 confessOnFailure | ||||||||||||||||||||||||||||||||||||||||||
| 2214 | |||||||||||||||||||||||||||||||||||||||||||
| 2215 | Confess to any failures | ||||||||||||||||||||||||||||||||||||||||||
| 2216 | |||||||||||||||||||||||||||||||||||||||||||
| 2217 | =head4 gitFile | ||||||||||||||||||||||||||||||||||||||||||
| 2218 | |||||||||||||||||||||||||||||||||||||||||||
| 2219 | File name on L<GitHub|https://github.com/philiprbrenan> - this name can contain '/'. This is the file to be read from, written to, copied from, checked for existence or deleted. | ||||||||||||||||||||||||||||||||||||||||||
| 2220 | |||||||||||||||||||||||||||||||||||||||||||
| 2221 | =head4 gitFolder | ||||||||||||||||||||||||||||||||||||||||||
| 2222 | |||||||||||||||||||||||||||||||||||||||||||
| 2223 | Folder name on L<GitHub|https://github.com/philiprbrenan> - this name can contain '/'. | ||||||||||||||||||||||||||||||||||||||||||
| 2224 | |||||||||||||||||||||||||||||||||||||||||||
| 2225 | =head4 message | ||||||||||||||||||||||||||||||||||||||||||
| 2226 | |||||||||||||||||||||||||||||||||||||||||||
| 2227 | Optional commit message | ||||||||||||||||||||||||||||||||||||||||||
| 2228 | |||||||||||||||||||||||||||||||||||||||||||
| 2229 | =head4 nonRecursive | ||||||||||||||||||||||||||||||||||||||||||
| 2230 | |||||||||||||||||||||||||||||||||||||||||||
| 2231 | Fetch only one level of files with L<list|https://en.wikipedia.org/wiki/Linked_list>. | ||||||||||||||||||||||||||||||||||||||||||
| 2232 | |||||||||||||||||||||||||||||||||||||||||||
| 2233 | =head4 personalAccessToken | ||||||||||||||||||||||||||||||||||||||||||
| 2234 | |||||||||||||||||||||||||||||||||||||||||||
| 2235 | A personal access token with scope "public_repo" as generated on page: https://github.com/settings/tokens. | ||||||||||||||||||||||||||||||||||||||||||
| 2236 | |||||||||||||||||||||||||||||||||||||||||||
| 2237 | =head4 personalAccessTokenFolder | ||||||||||||||||||||||||||||||||||||||||||
| 2238 | |||||||||||||||||||||||||||||||||||||||||||
| 2239 | The folder into which to save personal access tokens. Set to B</etc/GitHubCrudPersonalAccessToken> by default. | ||||||||||||||||||||||||||||||||||||||||||
| 2240 | |||||||||||||||||||||||||||||||||||||||||||
| 2241 | =head4 private | ||||||||||||||||||||||||||||||||||||||||||
| 2242 | |||||||||||||||||||||||||||||||||||||||||||
| 2243 | Whether the repository being created should be private or not. | ||||||||||||||||||||||||||||||||||||||||||
| 2244 | |||||||||||||||||||||||||||||||||||||||||||
| 2245 | =head4 repository | ||||||||||||||||||||||||||||||||||||||||||
| 2246 | |||||||||||||||||||||||||||||||||||||||||||
| 2247 | The name of the repository to be worked on minus the userid - you should create this repository first manually. | ||||||||||||||||||||||||||||||||||||||||||
| 2248 | |||||||||||||||||||||||||||||||||||||||||||
| 2249 | =head4 secret | ||||||||||||||||||||||||||||||||||||||||||
| 2250 | |||||||||||||||||||||||||||||||||||||||||||
| 2251 | The secret for a web hook - this is created by the creator of the web hook and remembered by L<GitHub|https://github.com/philiprbrenan>, | ||||||||||||||||||||||||||||||||||||||||||
| 2252 | |||||||||||||||||||||||||||||||||||||||||||
| 2253 | =head4 title | ||||||||||||||||||||||||||||||||||||||||||
| 2254 | |||||||||||||||||||||||||||||||||||||||||||
| 2255 | The title of an issue. | ||||||||||||||||||||||||||||||||||||||||||
| 2256 | |||||||||||||||||||||||||||||||||||||||||||
| 2257 | =head4 userid | ||||||||||||||||||||||||||||||||||||||||||
| 2258 | |||||||||||||||||||||||||||||||||||||||||||
| 2259 | Userid on L<GitHub|https://github.com/philiprbrenan> of the repository to be worked on. | ||||||||||||||||||||||||||||||||||||||||||
| 2260 | |||||||||||||||||||||||||||||||||||||||||||
| 2261 | =head4 webHookUrl | ||||||||||||||||||||||||||||||||||||||||||
| 2262 | |||||||||||||||||||||||||||||||||||||||||||
| 2263 | The url for a web hook. | ||||||||||||||||||||||||||||||||||||||||||
| 2264 | |||||||||||||||||||||||||||||||||||||||||||
| 2265 | |||||||||||||||||||||||||||||||||||||||||||
| 2266 | |||||||||||||||||||||||||||||||||||||||||||
| 2267 | =head3 Output fields | ||||||||||||||||||||||||||||||||||||||||||
| 2268 | |||||||||||||||||||||||||||||||||||||||||||
| 2269 | |||||||||||||||||||||||||||||||||||||||||||
| 2270 | =head4 failed | ||||||||||||||||||||||||||||||||||||||||||
| 2271 | |||||||||||||||||||||||||||||||||||||||||||
| 2272 | Defined if the last request to L<GitHub|https://github.com/philiprbrenan> failed else B<undef>. | ||||||||||||||||||||||||||||||||||||||||||
| 2273 | |||||||||||||||||||||||||||||||||||||||||||
| 2274 | =head4 fileList | ||||||||||||||||||||||||||||||||||||||||||
| 2275 | |||||||||||||||||||||||||||||||||||||||||||
| 2276 | Reference to an array of files produced by L<list|/list>. | ||||||||||||||||||||||||||||||||||||||||||
| 2277 | |||||||||||||||||||||||||||||||||||||||||||
| 2278 | =head4 readData | ||||||||||||||||||||||||||||||||||||||||||
| 2279 | |||||||||||||||||||||||||||||||||||||||||||
| 2280 | Data produced by L<read|/read>. | ||||||||||||||||||||||||||||||||||||||||||
| 2281 | |||||||||||||||||||||||||||||||||||||||||||
| 2282 | =head4 response | ||||||||||||||||||||||||||||||||||||||||||
| 2283 | |||||||||||||||||||||||||||||||||||||||||||
| 2284 | A reference to L<GitHub|https://github.com/philiprbrenan>'s response to the latest request. | ||||||||||||||||||||||||||||||||||||||||||
| 2285 | |||||||||||||||||||||||||||||||||||||||||||
| 2286 | |||||||||||||||||||||||||||||||||||||||||||
| 2287 | |||||||||||||||||||||||||||||||||||||||||||
| 2288 | =head2 GitHub::Crud::Response Definition | ||||||||||||||||||||||||||||||||||||||||||
| 2289 | |||||||||||||||||||||||||||||||||||||||||||
| 2290 | |||||||||||||||||||||||||||||||||||||||||||
| 2291 | Attributes describing a response from L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 2292 | |||||||||||||||||||||||||||||||||||||||||||
| 2293 | |||||||||||||||||||||||||||||||||||||||||||
| 2294 | |||||||||||||||||||||||||||||||||||||||||||
| 2295 | |||||||||||||||||||||||||||||||||||||||||||
| 2296 | =head3 Output fields | ||||||||||||||||||||||||||||||||||||||||||
| 2297 | |||||||||||||||||||||||||||||||||||||||||||
| 2298 | |||||||||||||||||||||||||||||||||||||||||||
| 2299 | =head4 content | ||||||||||||||||||||||||||||||||||||||||||
| 2300 | |||||||||||||||||||||||||||||||||||||||||||
| 2301 | The actual content of the file from L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 2302 | |||||||||||||||||||||||||||||||||||||||||||
| 2303 | =head4 data | ||||||||||||||||||||||||||||||||||||||||||
| 2304 | |||||||||||||||||||||||||||||||||||||||||||
| 2305 | The data received from L<GitHub|https://github.com/philiprbrenan>, normally in L<Json|https://en.wikipedia.org/wiki/JSON> format. | ||||||||||||||||||||||||||||||||||||||||||
| 2306 | |||||||||||||||||||||||||||||||||||||||||||
| 2307 | =head4 status | ||||||||||||||||||||||||||||||||||||||||||
| 2308 | |||||||||||||||||||||||||||||||||||||||||||
| 2309 | Our version of Status. | ||||||||||||||||||||||||||||||||||||||||||
| 2310 | |||||||||||||||||||||||||||||||||||||||||||
| 2311 | |||||||||||||||||||||||||||||||||||||||||||
| 2312 | |||||||||||||||||||||||||||||||||||||||||||
| 2313 | =head1 Private Methods | ||||||||||||||||||||||||||||||||||||||||||
| 2314 | |||||||||||||||||||||||||||||||||||||||||||
| 2315 | =head2 currentRepo () | ||||||||||||||||||||||||||||||||||||||||||
| 2316 | |||||||||||||||||||||||||||||||||||||||||||
| 2317 | Create a L<GitHub|https://github.com/philiprbrenan> object for the current repo if we are on L<GitHub|https://github.com/philiprbrenan> actions | ||||||||||||||||||||||||||||||||||||||||||
| 2318 | |||||||||||||||||||||||||||||||||||||||||||
| 2319 | |||||||||||||||||||||||||||||||||||||||||||
| 2320 | |||||||||||||||||||||||||||||||||||||||||||
| 2321 | =head1 Index | ||||||||||||||||||||||||||||||||||||||||||
| 2322 | |||||||||||||||||||||||||||||||||||||||||||
| 2323 | |||||||||||||||||||||||||||||||||||||||||||
| 2324 | 1 L<copy|/copy> - Copy a source file from one location to another target location in your L<GitHub|https://github.com/philiprbrenan> repository, overwriting the target file if it already exists. | ||||||||||||||||||||||||||||||||||||||||||
| 2325 | |||||||||||||||||||||||||||||||||||||||||||
| 2326 | 2 L<createIssue|/createIssue> - Create an issue on L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 2327 | |||||||||||||||||||||||||||||||||||||||||||
| 2328 | 3 L<createIssueFromSavedToken|/createIssueFromSavedToken> - Create an issue on L<GitHub|https://github.com/philiprbrenan> using an access token as supplied or saved in a file using L<savePersonalAccessToken|/savePersonalAccessToken>. | ||||||||||||||||||||||||||||||||||||||||||
| 2329 | |||||||||||||||||||||||||||||||||||||||||||
| 2330 | 4 L<createIssueInCurrentRepo|/createIssueInCurrentRepo> - Create an issue in the current L<GitHub|https://github.com/philiprbrenan> repository if we are running on L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 2331 | |||||||||||||||||||||||||||||||||||||||||||
| 2332 | 5 L<createPushWebHook|/createPushWebHook> - Create a web hook for your L<GitHub|https://github.com/philiprbrenan> userid. | ||||||||||||||||||||||||||||||||||||||||||
| 2333 | |||||||||||||||||||||||||||||||||||||||||||
| 2334 | 6 L<createRepository|/createRepository> - Create a repository on L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 2335 | |||||||||||||||||||||||||||||||||||||||||||
| 2336 | 7 L<createRepositoryFromSavedToken|/createRepositoryFromSavedToken> - Create a repository on L<GitHub|https://github.com/philiprbrenan> using an access token either as supplied or saved in a file using L<savePersonalAccessToken|/savePersonalAccessToken>. | ||||||||||||||||||||||||||||||||||||||||||
| 2337 | |||||||||||||||||||||||||||||||||||||||||||
| 2338 | 8 L<currentRepo|/currentRepo> - Create a L<GitHub|https://github.com/philiprbrenan> object for the current repo if we are on L<GitHub|https://github.com/philiprbrenan> actions | ||||||||||||||||||||||||||||||||||||||||||
| 2339 | |||||||||||||||||||||||||||||||||||||||||||
| 2340 | 9 L<delete|/delete> - Delete a file from L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 2341 | |||||||||||||||||||||||||||||||||||||||||||
| 2342 | 10 L<deleteFileUsingSavedToken|/deleteFileUsingSavedToken> - Delete a file on L<GitHub|https://github.com/philiprbrenan> using a saved token | ||||||||||||||||||||||||||||||||||||||||||
| 2343 | |||||||||||||||||||||||||||||||||||||||||||
| 2344 | 11 L<exists|/exists> - Test whether a file exists on L<GitHub|https://github.com/philiprbrenan> or not and returns an object including the B<sha> and B<size> fields if it does else L<undef|https://perldoc.perl.org/functions/undef.html>. | ||||||||||||||||||||||||||||||||||||||||||
| 2345 | |||||||||||||||||||||||||||||||||||||||||||
| 2346 | 12 L<getRepository|/getRepository> - Get the overall details of a repository | ||||||||||||||||||||||||||||||||||||||||||
| 2347 | |||||||||||||||||||||||||||||||||||||||||||
| 2348 | 13 L<getRepositoryUpdatedAtUsingSavedToken|/getRepositoryUpdatedAtUsingSavedToken> - Get the last time a repository was updated via the 'updated_at' field using a saved token and return the time in number of seconds since the Unix epoch. | ||||||||||||||||||||||||||||||||||||||||||
| 2349 | |||||||||||||||||||||||||||||||||||||||||||
| 2350 | 14 L<getRepositoryUsingSavedToken|/getRepositoryUsingSavedToken> - Get repository details from L<GitHub|https://github.com/philiprbrenan> using a saved token | ||||||||||||||||||||||||||||||||||||||||||
| 2351 | |||||||||||||||||||||||||||||||||||||||||||
| 2352 | 15 L<list|/list> - List all the files contained in a L<GitHub|https://github.com/philiprbrenan> repository or all the files below a specified folder in the repository. | ||||||||||||||||||||||||||||||||||||||||||
| 2353 | |||||||||||||||||||||||||||||||||||||||||||
| 2354 | 16 L<listCommits|/listCommits> - List all the commits in a L<GitHub|https://github.com/philiprbrenan> repository. | ||||||||||||||||||||||||||||||||||||||||||
| 2355 | |||||||||||||||||||||||||||||||||||||||||||
| 2356 | 17 L<listCommitShas|/listCommitShas> - Create {commit name => sha} from the results of L</listCommits>. | ||||||||||||||||||||||||||||||||||||||||||
| 2357 | |||||||||||||||||||||||||||||||||||||||||||
| 2358 | 18 L<listRepositories|/listRepositories> - List the repositories accessible to a user on L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 2359 | |||||||||||||||||||||||||||||||||||||||||||
| 2360 | 19 L<listRepositoryUsingSavedToken|/listRepositoryUsingSavedToken> - List the files in a repository using a saved token | ||||||||||||||||||||||||||||||||||||||||||
| 2361 | |||||||||||||||||||||||||||||||||||||||||||
| 2362 | 20 L<listWebHooks|/listWebHooks> - List web hooks associated with your L<GitHub|https://github.com/philiprbrenan> repository. | ||||||||||||||||||||||||||||||||||||||||||
| 2363 | |||||||||||||||||||||||||||||||||||||||||||
| 2364 | 21 L<loadPersonalAccessToken|/loadPersonalAccessToken> - Load a personal access token by userid from folder L<personalAccessTokenFolder|/personalAccessTokenFolder>. | ||||||||||||||||||||||||||||||||||||||||||
| 2365 | |||||||||||||||||||||||||||||||||||||||||||
| 2366 | 22 L<new|/new> - Create a new L<GitHub|https://github.com/philiprbrenan> object with attributes as described at: L<GitHub::Crud Definition>. | ||||||||||||||||||||||||||||||||||||||||||
| 2367 | |||||||||||||||||||||||||||||||||||||||||||
| 2368 | 23 L<pushToGitHub|/pushToGitHub> - Push some files to github | ||||||||||||||||||||||||||||||||||||||||||
| 2369 | |||||||||||||||||||||||||||||||||||||||||||
| 2370 | 24 L<read|/read> - Read data from a file on L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 2371 | |||||||||||||||||||||||||||||||||||||||||||
| 2372 | 25 L<readBlob|/readBlob> - Read a L<blob|https://en.wikipedia.org/wiki/Binary_large_object> from L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 2373 | |||||||||||||||||||||||||||||||||||||||||||
| 2374 | 26 L<readFileUsingSavedToken|/readFileUsingSavedToken> - Read from a file on L<GitHub|https://github.com/philiprbrenan> using a personal access token as supplied or saved in a file. | ||||||||||||||||||||||||||||||||||||||||||
| 2375 | |||||||||||||||||||||||||||||||||||||||||||
| 2376 | 27 L<rename|/rename> - Rename a source file on L<GitHub|https://github.com/philiprbrenan> if the target file name is not already in use. | ||||||||||||||||||||||||||||||||||||||||||
| 2377 | |||||||||||||||||||||||||||||||||||||||||||
| 2378 | 28 L<savePersonalAccessToken|/savePersonalAccessToken> - Save a L<GitHub|https://github.com/philiprbrenan> personal access token by userid in folder L<personalAccessTokenFolder|/personalAccessTokenFolder>. | ||||||||||||||||||||||||||||||||||||||||||
| 2379 | |||||||||||||||||||||||||||||||||||||||||||
| 2380 | 29 L<write|/write> - Write the specified data into a file on L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 2381 | |||||||||||||||||||||||||||||||||||||||||||
| 2382 | 30 L<writeBinaryFileFromFileInCurrentRun|/writeBinaryFileFromFileInCurrentRun> - Write to a file in the current L<GitHub|https://github.com/philiprbrenan> repository by copying a local binary file if we are running on L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 2383 | |||||||||||||||||||||||||||||||||||||||||||
| 2384 | 31 L<writeBlob|/writeBlob> - Write data into a L<GitHub|https://github.com/philiprbrenan> as a L<blob|https://en.wikipedia.org/wiki/Binary_large_object> that can be referenced by future commits. | ||||||||||||||||||||||||||||||||||||||||||
| 2385 | |||||||||||||||||||||||||||||||||||||||||||
| 2386 | 32 L<writeCommit|/writeCommit> - Write all the files in a B<$folder> (or just the the named files) into a L<GitHub|https://github.com/philiprbrenan> repository in parallel as a commit on the specified branch. | ||||||||||||||||||||||||||||||||||||||||||
| 2387 | |||||||||||||||||||||||||||||||||||||||||||
| 2388 | 33 L<writeCommitUsingSavedToken|/writeCommitUsingSavedToken> - Write all the files in a local folder to a named L<GitHub|https://github.com/philiprbrenan> repository using a personal access token as supplied or saved in a file. | ||||||||||||||||||||||||||||||||||||||||||
| 2389 | |||||||||||||||||||||||||||||||||||||||||||
| 2390 | 34 L<writeFileFromCurrentRun|/writeFileFromCurrentRun> - Write text into a file in the current L<GitHub|https://github.com/philiprbrenan> repository if we are running on L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 2391 | |||||||||||||||||||||||||||||||||||||||||||
| 2392 | 35 L<writeFileFromFileFromCurrentRun|/writeFileFromFileFromCurrentRun> - Write to a file in the current L<GitHub|https://github.com/philiprbrenan> repository by copying a local file if we are running on L<GitHub|https://github.com/philiprbrenan>. | ||||||||||||||||||||||||||||||||||||||||||
| 2393 | |||||||||||||||||||||||||||||||||||||||||||
| 2394 | 36 L<writeFileFromFileUsingSavedToken|/writeFileFromFileUsingSavedToken> - Copy a file to L<GitHub|https://github.com/philiprbrenan> using a personal access token as supplied or saved in a file. | ||||||||||||||||||||||||||||||||||||||||||
| 2395 | |||||||||||||||||||||||||||||||||||||||||||
| 2396 | 37 L<writeFileUsingSavedToken|/writeFileUsingSavedToken> - Write to a file on L<GitHub|https://github.com/philiprbrenan> using a personal access token as supplied or saved in a file. | ||||||||||||||||||||||||||||||||||||||||||
| 2397 | |||||||||||||||||||||||||||||||||||||||||||
| 2398 | 38 L<writeFolderUsingSavedToken|/writeFolderUsingSavedToken> - Write all the files in a local folder to a target folder on a named L<GitHub|https://github.com/philiprbrenan> repository using a personal access token as supplied or saved in a file. | ||||||||||||||||||||||||||||||||||||||||||
| 2399 | |||||||||||||||||||||||||||||||||||||||||||
| 2400 | =head1 Installation | ||||||||||||||||||||||||||||||||||||||||||
| 2401 | |||||||||||||||||||||||||||||||||||||||||||
| 2402 | This module is written in 100% Pure Perl and, thus, it is easy to read, | ||||||||||||||||||||||||||||||||||||||||||
| 2403 | comprehend, use, modify and install via B<cpan>: | ||||||||||||||||||||||||||||||||||||||||||
| 2404 | |||||||||||||||||||||||||||||||||||||||||||
| 2405 | sudo cpan install GitHub::Crud | ||||||||||||||||||||||||||||||||||||||||||
| 2406 | |||||||||||||||||||||||||||||||||||||||||||
| 2407 | =head1 Author | ||||||||||||||||||||||||||||||||||||||||||
| 2408 | |||||||||||||||||||||||||||||||||||||||||||
| 2409 | L<philiprbrenan@gmail.com|mailto:philiprbrenan@gmail.com> | ||||||||||||||||||||||||||||||||||||||||||
| 2410 | |||||||||||||||||||||||||||||||||||||||||||
| 2411 | L<http://prb.appaapps.com|http://prb.appaapps.com> | ||||||||||||||||||||||||||||||||||||||||||
| 2412 | |||||||||||||||||||||||||||||||||||||||||||
| 2413 | =head1 Copyright | ||||||||||||||||||||||||||||||||||||||||||
| 2414 | |||||||||||||||||||||||||||||||||||||||||||
| 2415 | Copyright (c) 2016-2023 Philip R Brenan. | ||||||||||||||||||||||||||||||||||||||||||
| 2416 | |||||||||||||||||||||||||||||||||||||||||||
| 2417 | This module is free software. It may be used, redistributed and/or modified | ||||||||||||||||||||||||||||||||||||||||||
| 2418 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 2419 | |||||||||||||||||||||||||||||||||||||||||||
| 2420 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 2421 | |||||||||||||||||||||||||||||||||||||||||||
| 2422 | |||||||||||||||||||||||||||||||||||||||||||
| 2423 | |||||||||||||||||||||||||||||||||||||||||||
| 2424 | # Tests and documentation | ||||||||||||||||||||||||||||||||||||||||||
| 2425 | |||||||||||||||||||||||||||||||||||||||||||
| 2426 | sub test | ||||||||||||||||||||||||||||||||||||||||||
| 2427 | 1 | ▶ | {my $p = __PACKAGE__; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
test: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 2428 | 1 | binmode($_, ":utf8") for *STDOUT, *STDERR; | |||||||||||||||||||||||||||||||||||||||||
| 2429 | 1 | ▶ | return if eval "eof(${p}::DATA)"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2430 | 1 | my $s = eval "join('', <${p}::DATA>)"; | |||||||||||||||||||||||||||||||||||||||||
| 2431 | 1 | ▶ | $@ and die $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2432 | 0 | ▶ | eval $s; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
success: not called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 2433 | 1 | ▶ | $@ and die $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2434 | 1 | 1 | |||||||||||||||||||||||||||||||||||||||||
| 2435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 2436 | |||||||||||||||||||||||||||||||||||||||||||
| 2437 | 1 | ▶ | test unless caller; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 2438 | |||||||||||||||||||||||||||||||||||||||||||
| 2439 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 2440 | #podDocumentation | ||||||||||||||||||||||||||||||||||||||||||
| 2441 | __DATA__ | ||||||||||||||||||||||||||||||||||||||||||