From f7f894dfd3b469e53c82ca3466408c58c897dd61 Mon Sep 17 00:00:00 2001 From: Ken-ichi Mito Date: Wed, 21 Aug 2013 12:56:22 +0900 Subject: [PATCH] change messages, add sample script --- Dev/github/GitHubBackup.pm | 23 ++++++++++++++++------- Dev/github/github-backup.pl | 15 +++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 Dev/github/github-backup.pl diff --git a/Dev/github/GitHubBackup.pm b/Dev/github/GitHubBackup.pm index 35a1836..6542ef3 100644 --- a/Dev/github/GitHubBackup.pm +++ b/Dev/github/GitHubBackup.pm @@ -193,6 +193,15 @@ sub directory { return $path; } +sub message { + my $self = shift; + my $message = shift; + + print $self->full_name, " $message\n"; + + return $self; +} + sub sync { my $self = shift; my $url = shift; @@ -200,12 +209,12 @@ sub sync { if (-d "$dir") { local $CWD = $dir; - print "fetch $dir\n"; + $self->message("++> $dir"); Git::Repository->run(fetch => '--all'); return $self; } - print "clone $dir\n"; + $self->message("==> $dir"); mkpath $dir; Git::Repository->run(clone => '--mirror' => $url => $dir); @@ -242,16 +251,16 @@ sub set_forks { my @fetch; foreach my $fork (@{$self->forks}) { if ($remotes =~ /$fork->{full_name}/) { - print "skip ", $fork->{full_name}, "\n"; + $self->message("--- ". $fork->{full_name}); next; } - print "add ", $fork->{full_name}, "\n"; + $self->message("+++ ". $fork->{full_name}); Git::Repository->run(remote => add => $fork->{full_name} => $fork->{clone_url}); push @fetch, $fork->{full_name}; } foreach my $fork (@fetch) { - print "fetch $fork\n"; + $self->message("--> $fork"); Git::Repository->run(fetch => $fork); } @@ -269,7 +278,7 @@ sub clone_wiki { 'https://github.com/' . $self->full_name . '/wiki' ); if ($res->code != 200) { - print "$dir does not exist\n"; + $self->message("wiki does not exist"); return $self; } @@ -302,7 +311,7 @@ sub save_issues { local $CWD = $dir; foreach my $issue (@{$self->issues}) { my $number = $issue->{number}; - print "save issue/$number\n"; + $self->message("+++ issue/$number"); open my $fh, ">$number.json"; print $fh $json->encode($issue); diff --git a/Dev/github/github-backup.pl b/Dev/github/github-backup.pl new file mode 100644 index 0000000..da6736a --- /dev/null +++ b/Dev/github/github-backup.pl @@ -0,0 +1,15 @@ +#! /usr/bin/perl -w + +use strict; +use warnings; +use utf8; + +use GitHubBackup; + +my $gh = GitHubBackup->new( + account => 'mittyorz', + repository => 'munin-plugins', + directory => 'repos', +); + +$gh->backup; -- 1.7.9.5