Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 62 lines (52 sloc) 1.761 kb
#!/usr/bin/perl
use strict;
use warnings;
use vars qw(%creds);
use File::Basename;
BEGIN {
-e "github-upload.localdefs" and do "github-upload.localdefs"; # you can put your "use lib"s there
}
use Net::GitHub::Upload;
BEGIN {
unless (Net::GitHub::Upload->can("delete")) {
die "Your installation of Net::GitHub::Upload does not support deletion\n".
"of files. Please grab, for now, a supported version from\n".
" https://github.com/yath/net-github-upload-perl\n".
"and check out the 'deletefile' branch.\n";
}
}
# enough for compilation phase
use constant CREDS => "github-upload.creds";
unless (my $ret = do +CREDS) {
die "Unable to parse @{[CREDS]}: $@" if $@;
die "Unable to import @{[CREDS]}: $!" unless defined $ret;
die "Unable to run @{[CREDS]}" unless $ret;
}
my ($filename, $repo) = @ARGV;
die "Usage: $0 <filename> <repository>" unless $filename && $repo;
# The MIME content type may be specified in brackets after the
# file name. If the file name *really* contains square brackets
# one can just append [].
my $mimetype = do {
$filename =~ s/(.*)\[(.*)\]$/$1/ ? $2 : undef
};
# set it up
my $github = Net::GitHub::Upload->new(
login => $creds{login},
token => $creds{token},
);
# delete leftover stuff
if (my $files = $github->list_files($repo)) {
foreach my $file (@$files) {
my $fbname = basename($filename);
next unless $file->{name} eq $fbname;
$github->delete(repos => $repo, fileinfo => $file) or die;
}
}
# and upload
warn "Uploading \"$filename\" (content type: @{[$mimetype||'unknown']}) to $repo\n";
$github->upload(
repos => $repo,
file => $filename,
content_type => $mimetype,
) or die;
Jump to Line
Something went wrong with that request. Please try again.