Skip to content

Commit

Permalink
get target branch logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-kimoto committed Apr 27, 2016
1 parent 69caebd commit a40aea2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
21 changes: 20 additions & 1 deletion lib/Gitprep/Manager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,6 @@ sub original_project {
croak "Original project don't eixsts." unless defined $original_project_row_id;

# Original project
$DB::single = 1 if $main::x;
my $original_project = $dbi->model('project')->select(
[
{__MY__ => '*'},
Expand All @@ -517,6 +516,26 @@ sub original_project {
return $original_project;
}

sub child_project {
my ($self, $user_id, $project_id, $child_user_id) = @_;

my $project_row_id = $self->app->dbi->model('project')->select(
'project.row_id', where => {'user.id' => $user_id, 'project.id' => $project_id}
)->value;

my $child_project = $self->app->dbi->model('project')->select(
[
{__MY__ => '*'},
],
where => {
'project.original_project' => $project_row_id,
'user.id' => $child_user_id
}
)->one;

return $child_project;
}

sub projects {
my ($self, $user_id) = @_;

Expand Down
11 changes: 10 additions & 1 deletion templates/compare.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
my $page = param('page') || 0;
my $expand = param('expand');

# Get target user, project, branch
my $target_user_id;
my $target_branch;
my $target_project;
if ($rev =~ /^([^:]+):(.+)/) {
$target_user_id = $1;
$target_branch = $2;
$target_project = $self->app->manager->child_project($user_id, $project_id, $target_user_id);
}

unless ($from_rev) {
$from_rev = app->manager->default_branch($user_id, $project_id);
}
Expand Down Expand Up @@ -96,7 +106,6 @@
$self->redirect_to("/$user_id/$project_id/pull/$new_pull_request_row_id");
return;
}

}
}

Expand Down

0 comments on commit a40aea2

Please sign in to comment.