Skip to content

Instantly share code, notes, and snippets.

@briandfoy
Created April 6, 2012 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briandfoy/2317089 to your computer and use it in GitHub Desktop.
Save briandfoy/2317089 to your computer and use it in GitHub Desktop.
Filter my big SourceForge SVN into separate Github projects
# I created this to translate a bunch of projects I had in one big git
# repo into separate repos. The big git repo was converted from the SVN
# repo of my old SourceForge project.
use v5.14;
use strict;
use warnings;
use File::Spec::Functions;
use File::Path qw(remove_tree);
my $src = '/Users/brian/Dev/brian-d-foy.git';
while( <DATA> ) {
chomp;
s|\A./||;
s|/Makefile.PL||;
say "\n", '-' x 70;
my $dir = catfile( '/Users/brian/Desktop', s|/|-|gr );
my $module = s|/|::|gr;
# checkout thing from git
my_system( 'git', 'clone', $src, $dir );
# change to directory
chdir $dir or die "Could not change to $dir: $!";
# git filter branch
my_system( 'git', 'filter-branch', '--subdirectory-filter', $_ );
# create repo
my $remote = create_repo( $module, $module =~ s/::/-/gr );
my_system( 'git', 'remote', 'add', 'github', $remote );
my_system( 'git', 'push', 'github', 'master' );
chdir '..';
remove_tree( $dir );
}
sub my_system {
my @args = @_;
say "Running [@args]\n";
system { $args[0] } @args;
}
sub create_repo {
my( $module, $dist ) = @_;
use Mojo::UserAgent;
use MIME::Base64 qw(encode_base64);
my $ua = Mojo::UserAgent->new;
my $user = $ENV{GITHUB_USER};
my $pass = $ENV{GITHUB_PASS};
my $base64 = encode_base64( "$user:$pass" );
$ua->on(
start => sub {
my ($ua, $tx) = @_;
$tx->req->headers->header( 'Authorization' => "Basic $base64" );
}
);
# Request that will most likely get redirected
my $res = $ua->post_form(
'http://github.com/api/v2/json/repos/create',
{
name => $dist,
description => "The Perl module $module",
homepage => "https://www.metacpan.org/module/$module",
public => 100,
}
)->res;
"git\@github.com:$user/$dist.git"
}
__END__
./weblint++/Makefile.PL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment