[BACK]Return to github_sync.pl CVS log [TXT][DIR] Up to [local] / misc / github_sync

Annotation of misc/github_sync/github_sync.pl, Revision 1.1

1.1     ! afresh1     1: #!/usr/bin/perl
        !             2: # $AFresh1$
        !             3: use utf8;
        !             4: use v5.16;
        !             5: use warnings;
        !             6: use warnings FATAL => 'utf8';
        !             7: use open qw< :std :encoding(UTF-8) >;
        !             8:
        !             9: my $github_account = shift;
        !            10: die "Usage: $0 github_account\n" unless $github_account;
        !            11: my $repos_url = "https://api.github.com/users/$github_account/repos";
        !            12:
        !            13: # Copyright (c) 2020 Andrew Hewus Fresh <andrew@afresh1.com>
        !            14: #
        !            15: # Permission to use, copy, modify, and distribute this software for any
        !            16: # purpose with or without fee is hereby granted, provided that the above
        !            17: # copyright notice and this permission notice appear in all copies.
        !            18: #
        !            19: # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
        !            20: # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
        !            21: # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
        !            22: # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
        !            23: # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
        !            24: # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
        !            25: # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
        !            26:
        !            27: my $response = HTTP::Tiny::JSON->new->get($repos_url);
        !            28: die "GET $repos_url: $response->{status}: $response->{reason}\n"
        !            29:     unless $response->{success};
        !            30:
        !            31: foreach my $repo (@{ $response->{content} }) {
        !            32:        my $clone_url = $repo->{clone_url};
        !            33:        my $name = $clone_url =~ s{.*?\Q$github_account/}{}ir;
        !            34:
        !            35:        git( clone => '--bare', $clone_url )
        !            36:            unless -e $name;
        !            37:
        !            38:        local $ENV{GIT_DIR} = $name;
        !            39:        git(qw< fetch --prune-tags --tags >);
        !            40:
        !            41:        # TODO: Authentication and push of changes
        !            42:        #git(qw< push  --all >);
        !            43: }
        !            44:
        !            45: sub git {
        !            46:        my (@args) = @_;
        !            47:        system('git', @args) == 0 or die "git @args failed: $?";
        !            48: }
        !            49:
        !            50:
        !            51: package HTTP::Tiny::JSON;
        !            52: use parent 'HTTP::Tiny';
        !            53:
        !            54: BEGIN { our $VERSION = v0.0.1 }
        !            55:
        !            56: use JSON::PP;
        !            57:
        !            58: sub request {
        !            59:        my ($self, @args) = @_;
        !            60:
        !            61:        my $response = $self->SUPER::request(@args);
        !            62:
        !            63:        return $response unless $response;
        !            64:
        !            65:        if ( $response->{headers}->{'content-type'}
        !            66:            =~ /^application\/json\b/i )
        !            67:        {
        !            68:                $response->{raw_content} = $response->{content};
        !            69:                $response->{content} = JSON::PP->new->utf8->decode(
        !            70:                    $response->{content} );
        !            71:        }
        !            72:
        !            73:        return $response;
        !            74: }
        !            75:
        !            76: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>