| 1 | package App::SD::Replica::redmine; | ||
| 2 | use Any::Moose; | ||
| 3 | |||
| 4 | extends 'App::SD::ForeignReplica'; | ||
| 5 | |||
| 6 | use constant scheme => 'redmine'; | ||
| 7 | use constant pull_encoder => 'App::SD::Replica::redmine::PullEncoder'; | ||
| 8 | use constant push_encoder => 'App::SD::Replica::redmine::PushEncoder'; | ||
| 9 | use Prophet::ChangeSet; | ||
| 10 | |||
| 11 | has remote_url => ( isa => 'Str', is => 'rw'); | ||
| 12 | has query => ( isa => 'Str', is => 'rw'); | ||
| 13 | |||
| 14 | has redmine => (isa => 'Net::Redmine', is => 'rw'); | ||
| 15 | |||
| 16 | use URI; | ||
| 17 | |||
| 18 | sub BUILD { | ||
| 19 | my $self = shift; | ||
| 20 | |||
| 21 | eval { | ||
| 22 | require Net::Redmine; | ||
| 23 | }; | ||
| 24 | if ($@) { | ||
| 25 | die "SD requires Net::Redmine to sync with a Redmine server.\n". | ||
| 26 | "'cpan Net::Redmine' may sort this out for you"; | ||
| 27 | } | ||
| 28 | |||
| 29 | |||
| 30 | |||
| 31 | my ( $server, $type, $query ) = $self->{url} =~ m/^redmine:(.*?)$/ | ||
| 32 | or die "Can't parse Redmine server spec. Expected something like redmine:http://example.com/projects/project_name\n"; | ||
| 33 | |||
| 34 | my $uri = URI->new($server); | ||
| 35 | my ( $username, $password ); | ||
| 36 | if ( my $auth = $uri->userinfo ) { | ||
| 37 | ( $username, $password ) = split /:/, $auth, 2; | ||
| 38 | $uri->userinfo(undef); | ||
| 39 | } | ||
| 40 | |||
| 41 | $self->remote_url( $uri->as_string ); | ||
| 42 | |||
| 43 | ($username, $password) | ||
| 44 | = $self->prompt_for_login( | ||
| 45 | uri => $uri, | ||
| 46 | username => $username, | ||
| 47 | ) unless $password; | ||
| 48 | |||
| 49 | $self->redmine( | ||
| 50 | Net::Redmine->new( | ||
| 51 | url => $self->remote_url, | ||
| 52 | user => $username, | ||
| 53 | password => $password | ||
| 54 | )); | ||
| 55 | |||
| 56 | } | ||
| 57 | |||
| 58 | sub record_pushed_transactions {} | ||
| 59 | |||
| 60 | sub _uuid_url { | ||
| 61 | my $self = shift; | ||
| 62 | Carp::cluck "- can't make a uuid for this" unless ($self->remote_url); | ||
| 63 | return $self->remote_url; | ||
| 64 | } | ||
| 65 | |||
| 66 | sub remote_uri_path_for_id { | ||
| 67 | my $self = shift; | ||
| 68 | my $id = shift; | ||
| 69 | return "/issues/show/".$id; | ||
| 70 | } | ||
| 71 | |||
| 72 | 1; |