Showing 3 changed files with 66 additions and 43 deletions
+8
lib/Gitprep.pm
... ...
@@ -207,6 +207,14 @@ sub startup {
207 207
       join => [
208 208
         'left join user on pull_request.open_user = user.row_id'
209 209
       ]
210
+    },
211
+    {
212
+      table => 'pull_request_message',
213
+      primary_key => 'row_id',
214
+      join => [
215
+        'left join user on pull_request_message.user = user.row_id',
216
+        'left join pull_request on pull_request_message.pull_request = pull_request.row_id'
217
+      ]
210 218
     }
211 219
   ];
212 220
   $dbi->create_model($_) for @$models;
+2 -1
setup_database
... ...
@@ -202,13 +202,14 @@ EOS
202 202
     "message not null default ''",
203 203
     "create_time integer default 0",
204 204
     "update_time integer default 0",
205
+    "user integer not null default 0"
205 206
   );
206 207
   for my $column (@pull_request_message_columns) {
207 208
     eval { $dbi->execute("alter table pull_request_message add column $column") };
208 209
   }
209 210
 
210 211
   # Check pull_request_message table
211
-  eval { $dbi->select([qw/row_id pull_request number message create_time update_time/], table => 'pull_request_message') };
212
+  eval { $dbi->select([qw/row_id pull_request number message create_time update_time user/], table => 'pull_request_message') };
212 213
   if ($@) {
213 214
     my $error = "Can't create pull_request_message table properly: $@";
214 215
     die $error;
+56 -42
templates/compare.html.ep
... ...
@@ -3,15 +3,15 @@
3 3
   my $api = gitprep_api;
4 4
 
5 5
   # Parameters
6
-  my $user = param('user');
7
-  my $project = param('project');
6
+  my $user_id = param('user');
7
+  my $project_id = param('project');
8 8
   my $from_rev = param('rev1');
9 9
   my $rev = param('rev2');
10 10
   my $page = param('page') || 0;
11 11
   my $expand = param('expand');
12 12
   
13 13
   unless ($from_rev) {
14
-    $from_rev = app->manager->default_branch($user, $project);
14
+    $from_rev = app->manager->default_branch($user_id, $project_id);
15 15
   }
16 16
   
17 17
   # Git
... ...
@@ -25,8 +25,8 @@
25 25
       my $message = param('message');
26 26
       
27 27
       my $project_row_id = app->dbi->model('project')->select(
28
-        'row_id',
29
-        where => {user_id => $user, name => $project}
28
+        'project.row_id',
29
+        where => {'user.id' => $user_id, 'project.id' => $project_id}
30 30
       )->value;
31 31
       
32 32
       my $pull_request = app->dbi->model('pull_request')->select(
... ...
@@ -34,7 +34,7 @@
34 34
       )->one;
35 35
       
36 36
       if ($pull_request) {
37
-        $self->redirect_to("/$user/$project/pulls/$pull_request->{row_id}");
37
+        $self->redirect_to("/$user_id/$project_id/pulls/$pull_request->{row_id}");
38 38
         return;
39 39
       }
40 40
       else {
... ...
@@ -42,32 +42,46 @@
42 42
         my $now_epoch = $now_tm->epoch;
43 43
         my $user_row_id = app->dbi->model('user')->select(
44 44
           'row_id',
45
-          where => {id => $user}
45
+          where => {id => $user_id}
46 46
         )->value;
47 47
         
48
-        my $new_pull_request_params = {
49
-          project => $project_row_id,
50
-          branch1 => $from_rev,
51
-          branch2 => $rev,
52
-          title => $title,
53
-          message => $message,
54
-          open => 1,
55
-          open_time => $now_epoch,
56
-          open_user => $user_row_id
57
-        };
58
-        
59
-        app->dbi->model('pull_request')->insert($new_pull_request_params);
60
-        
61
-        my $new_pull_request_row_id = app->dbi->model('pull_request')->select(
62
-          'row_id',
63
-          where => {
48
+        my $new_pull_request_row_id;
49
+        app->dbi->connector->txn(sub {
50
+          # New pull request
51
+          my $new_pull_request_params = {
64 52
             project => $project_row_id,
65 53
             branch1 => $from_rev,
66
-            branch2 => $rev
67
-          }
68
-        )->value;
54
+            branch2 => $rev,
55
+            title => $title,
56
+            open => 1,
57
+            open_time => $now_epoch,
58
+            open_user => $user_row_id
59
+          };
60
+          
61
+          app->dbi->model('pull_request')->insert($new_pull_request_params);
62
+          
63
+          $new_pull_request_row_id = app->dbi->model('pull_request')->select(
64
+            'row_id',
65
+            where => {
66
+              project => $project_row_id,
67
+              branch1 => $from_rev,
68
+              branch2 => $rev
69
+            }
70
+          )->value;
71
+          
72
+          # New pull request message
73
+          my $new_pull_request_message_params = {
74
+            pull_request => $new_pull_request_row_id,
75
+            message => $message,
76
+            create_time => $now_epoch,
77
+            update_time => $now_epoch,
78
+            user => $user_row_id
79
+          };
80
+          
81
+          app->dbi->model('pull_request_message')->insert($new_pull_request_message_params);
82
+        });
69 83
         
70
-        $self->redirect_to("/$user/$project/pulls/$new_pull_request_row_id");
84
+        $self->redirect_to("/$user_id/$project_id/pull/$new_pull_request_row_id");
71 85
         return;
72 86
       }
73 87
       
... ...
@@ -75,7 +89,7 @@
75 89
   }
76 90
   
77 91
   # Commits
78
-  my $commits = $git->forward_commits(app->rep_info($user, $project), $from_rev, $rev);
92
+  my $commits = $git->forward_commits(app->rep_info($user_id, $project_id), $from_rev, $rev);
79 93
   my $commits_count = @$commits;
80 94
   my $commits_date = {};
81 95
   my $authors = {};
... ...
@@ -88,10 +102,10 @@
88 102
   my $authors_count = keys %$authors;
89 103
 
90 104
   # Start commit
91
-  my $start_commit = $git->separated_commit(app->rep_info($user, $project), $from_rev, $rev);
105
+  my $start_commit = $git->separated_commit(app->rep_info($user_id, $project_id), $from_rev, $rev);
92 106
 
93 107
   # End commit
94
-  my $end_commit = $git->get_commit(app->rep_info($user, $project), $rev);
108
+  my $end_commit = $git->get_commit(app->rep_info($user_id, $project_id), $rev);
95 109
   
96 110
   if (!$start_commit || !$end_commit) {
97 111
     $self->reply->not_found;
... ...
@@ -99,7 +113,7 @@
99 113
   }
100 114
   
101 115
   # Branches
102
-  my $branches = $git->branches(app->rep_info($user, $project));
116
+  my $branches = $git->branches(app->rep_info($user_id, $project_id));
103 117
   @$branches = sort { $a->{commit}{age} <=> $b->{commit}{age} } @$branches;
104 118
   
105 119
   # Variables
... ...
@@ -119,10 +133,10 @@
119 133
   if ($can_open_pull_request) {
120 134
     
121 135
     # Create working repository if it don't exist
122
-    $self->app->manager->create_work_rep($user, $project);
136
+    $self->app->manager->create_work_rep($user_id, $project_id);
123 137
     
124 138
     # Fetch repository
125
-    my $work_rep_info = app->work_rep_info($user, $project);
139
+    my $work_rep_info = app->work_rep_info($user_id, $project_id);
126 140
     my @git_fetch_cmd = $self->app->git->cmd($work_rep_info, 'fetch');
127 141
     Gitprep::Util::run_command(@git_fetch_cmd)
128 142
       or Carp::croak "Can't execute git fetch: @git_fetch_cmd";
... ...
@@ -152,13 +166,13 @@
152 166
     
153 167
     # Check merge automatically
154 168
     $merge_automatical = $self->app->manager->check_merge_automatical(
155
-      app->work_rep_info($user, $project),
169
+      app->work_rep_info($user_id, $project_id),
156 170
       $gitprep_tmp_branch_name,
157 171
       "origin/$rev"
158 172
     );
159 173
   }
160 174
   
161
-  layout 'common', title => "Comparing $from_rev...$rev \x{30fb} $user/$project";
175
+  layout 'common', title => "Comparing $from_rev...$rev \x{30fb} $user_id/$project_id";
162 176
 %>
163 177
 
164 178
 
... ...
@@ -179,7 +193,7 @@
179 193
     $('[name=base-branch]').on('keypress', function (e) {
180 194
       // Enter
181 195
       if (e.which == 13) {
182
-        var href = '<%= url_for("/$user/$project/compare/") %>' + $(this).val() + '...<%= $rev %>';
196
+        var href = '<%= url_for("/$user_id/$project_id/compare/") %>' + $(this).val() + '...<%= $rev %>';
183 197
         if (<%= $expand ? 1 : 0 %>) {
184 198
           href = href + '?expand=1';
185 199
         }
... ...
@@ -201,7 +215,7 @@
201 215
     $('[name=compare-branch]').on('keypress', function (e) {
202 216
       // Enter
203 217
       if (e.which == 13) {
204
-        var href = '<%= url_for("/$user/$project/compare/") %>' + '<%= $from_rev %>...' + $(this).val();
218
+        var href = '<%= url_for("/$user_id/$project_id/compare/") %>' + '<%= $from_rev %>...' + $(this).val();
205 219
         if (<%= $expand ? 1 : 0 %>) {
206 220
           href = href + '?expand=1';
207 221
         }
... ...
@@ -266,7 +280,7 @@
266 280
             % my $branch = $branches->[$i];
267 281
               <li>
268 282
                 <a style="border-top-left-radius:0px;border-top-right-radius:0px;"
269
-                  href="<%= url_with("/$user/$project/compare/$branch->{name}...$rev") %>">
283
+                  href="<%= url_with("/$user_id/$project_id/compare/$branch->{name}...$rev") %>">
270 284
                   <%= $branch->{name} %>
271 285
                 </a>
272 286
               </li>
... ...
@@ -295,7 +309,7 @@
295 309
           % my $branch = $branches->[$i];
296 310
             <li>
297 311
               <a style="border-top-left-radius:0px;border-top-right-radius:0px;"
298
-                href="<%= url_with("/$user/$project/compare/$from_rev...$branch->{name}") %>">
312
+                href="<%= url_with("/$user_id/$project_id/compare/$from_rev...$branch->{name}") %>">
299 313
                 <%= $branch->{name} %>
300 314
               </a>
301 315
             </li>
... ...
@@ -366,12 +380,12 @@
366 380
                 </span>
367 381
               </div>
368 382
               <div class="compare-commits-commit-title">
369
-                <a style="color:#333" href="<%= url_for("/$user/$project/commit/$commit->{id}") %>">
383
+                <a style="color:#333" href="<%= url_for("/$user_id/$project_id/commit/$commit->{id}") %>">
370 384
                   <%= $commit->{title_short} %>
371 385
                 </a>
372 386
               </div>
373 387
               <div class="compare-commits-commit-id">
374
-                <a href="<%= url_for("/$user/$project/commit/$commit->{id}") %>">
388
+                <a href="<%= url_for("/$user_id/$project_id/commit/$commit->{id}") %>">
375 389
                   <%= substr($commit->{id}, 0, 7) %>
376 390
                 </a>
377 391
               </div>
... ...
@@ -391,7 +405,7 @@
391 405
         <b>
392 406
           <%= $from_rev %></b> is up to date with all commits from
393 407
           <b><%= $rev %></b>.
394
-          Try <a href="<%= url_for("/$user/$project/compare/$rev...$from_rev") %>">switching the base</a> for your comparison.
408
+          Try <a href="<%= url_for("/$user_id/$project_id/compare/$rev...$from_rev") %>">switching the base</a> for your comparison.
395 409
       </div>
396 410
     </div>
397 411
   % }