gitprep / templates / compare.html.ep /
Newer Older
390 lines | 12.678kb
added feature that get branc...
Yuki Kimoto authored on 2013-02-04
1
<%
2
  # API
added compare branch popup t...
Yuki Kimoto authored on 2013-05-10
3
  my $api = gitprep_api;
added feature that get branc...
Yuki Kimoto authored on 2013-02-04
4

            
5
  # Parameters
6
  my $user = param('user');
7
  my $project = param('project');
cleanup
Yuki Kimoto authored on 2013-05-31
8
  my $from_rev = param('rev1');
9
  my $rev = param('rev2');
added feature that get branc...
Yuki Kimoto authored on 2013-02-04
10
  my $page = param('page') || 0;
add pull request form
Yuki Kimoto authored on 2016-04-12
11
  my $expand = param('expand');
added feature that get branc...
Yuki Kimoto authored on 2013-02-04
12
  
cleanup branch
Yuki Kimoto authored on 2016-04-12
13
  unless ($from_rev) {
14
    $from_rev = app->manager->default_branch($user, $project);
15
  }
16
  
added feature that get branc...
Yuki Kimoto authored on 2013-02-04
17
  # Git
revert encoding support
Yuki Kimoto authored on 2013-11-22
18
  my $git = $self->app->git;
added feature that get branc...
Yuki Kimoto authored on 2013-02-04
19
  
add create pull request logi...
Yuki Kimoto authored on 2016-04-19
20
  if (lc $self->req->method eq 'post') {
21
    my $op = param('op');
22
    
23
    if ($op eq 'create-pull-request') {
24
      my $title = param('title');
25
      my $message = param('message');
26
      
27
      my $project_row_id = app->dbi->model('project')->select(
28
        'row_id',
29
        where => {user_id => $user, name => $project}
30
      )->value;
31
      
32
      my $pull_request = app->dbi->model('pull_request')->select(
33
        where => {project => $project_row_id, branch1 => $from_rev, branch2 => $rev}
34
      )->one;
35
      
36
      if ($pull_request) {
37
        $self->redirect_to("/$user/$project/pulls/$pull_request->{row_id}");
38
        return;
39
      }
40
      else {
41
        my $new_pull_request_params = {
42
          project => $project_row_id,
43
          branch1 => $from_rev,
44
          branch2 => $rev,
45
          title => $title,
create pull request list
Yuki Kimoto authored on 2016-04-20
46
          message => $message,
47
          open => 1
add create pull request logi...
Yuki Kimoto authored on 2016-04-19
48
        };
49
        
50
        app->dbi->model('pull_request')->insert($new_pull_request_params);
51
        
52
        my $new_pull_request_row_id = app->dbi->model('pull_request')->select(
53
          'row_id',
54
          where => {
55
            project => $project_row_id,
56
            branch1 => $from_rev,
57
            branch2 => $rev
58
          }
59
        )->value;
60
        
61
        $self->redirect_to("/$user/$project/pulls/$new_pull_request_row_id");
62
        return;
63
      }
64
      
65
    }
66
  }
67
  
added feature that get branc...
Yuki Kimoto authored on 2013-02-04
68
  # Commits
cleanup method
Yuki Kimoto authored on 2016-04-16
69
  my $commits = $git->forward_commits(app->rep_info($user, $project), $from_rev, $rev);
added feature that get branc...
Yuki Kimoto authored on 2013-02-04
70
  my $commits_count = @$commits;
71
  my $commits_date = {};
improved compare page commit...
Yuki Kimoto authored on 2013-02-06
72
  my $authors = {};
added feature that get branc...
Yuki Kimoto authored on 2013-02-04
73
  for my $commit (@$commits) {
support time zone
Yuki Kimoto authored on 2014-03-08
74
    my $date = $commit->{age_string_date_local};
added feature that get branc...
Yuki Kimoto authored on 2013-02-04
75
    $commits_date->{$date} ||= [];
improved compare page commit...
Yuki Kimoto authored on 2013-02-06
76
    $authors->{$commit->{author}} = 1;
added feature that get branc...
Yuki Kimoto authored on 2013-02-04
77
    push @{$commits_date->{$date}}, $commit;
78
  }
improved compare page commit...
Yuki Kimoto authored on 2013-02-06
79
  my $authors_count = keys %$authors;
added compare page file chan...
Yuki Kimoto authored on 2013-02-07
80

            
81
  # Start commit
cleanup methods
Yuki Kimoto authored on 2016-04-16
82
  my $start_commit = $git->separated_commit(app->rep_info($user, $project), $from_rev, $rev);
added compare page file chan...
Yuki Kimoto authored on 2013-02-07
83

            
84
  # End commit
cleanup methods
Yuki Kimoto authored on 2016-04-16
85
  my $end_commit = $git->get_commit(app->rep_info($user, $project), $rev);
cleanup
Yuki Kimoto authored on 2013-05-13
86
  
87
  if (!$start_commit || !$end_commit) {
do success xt tests
Yuki Kimoto authored on 2016-03-25
88
    $self->reply->not_found;
cleanup
Yuki Kimoto authored on 2013-05-13
89
    return;
90
  }
added compare page file chan...
Yuki Kimoto authored on 2013-02-07
91
  
added base branch selection ...
Yuki Kimoto authored on 2013-05-10
92
  # Branches
cleanup rep_info
Yuki Kimoto authored on 2016-04-16
93
  my $branches = $git->branches(app->rep_info($user, $project));
added base branch selection ...
Yuki Kimoto authored on 2013-05-10
94
  @$branches = sort { $a->{commit}{age} <=> $b->{commit}{age} } @$branches;
95
  
improve compare page design
Yuki Kimoto authored on 2016-02-04
96
  # Variables
97
  stash id => $end_commit->{id};
98
  stash from_id => $start_commit->{id};
99
  stash rev => $end_commit->{id};
100
  stash from_rev => $start_commit->{id};
add pull request form
Yuki Kimoto authored on 2016-04-12
101
  
102
  # Can open pull request
103
  my $can_open_pull_request;
104
  if (keys %$commits_date && $expand) {
105
    $can_open_pull_request = 1;
106
  }
107
  
cleanup methods
Yuki Kimoto authored on 2016-04-13
108
  # Can merge
add automatical merge checki...
Yuki Kimoto authored on 2016-04-18
109
  my $merge_automatical;
cleanup methods
Yuki Kimoto authored on 2016-04-13
110
  if ($can_open_pull_request) {
111
    
improve create working repos...
Yuki Kimoto authored on 2016-04-15
112
    # Create working repository if it don't exist
cleanup
Yuki Kimoto authored on 2016-04-16
113
    $self->app->manager->create_work_rep($user, $project);
add fetch logic
Yuki Kimoto authored on 2016-04-15
114
    
115
    # Fetch repository
cleanup compare logic
Yuki Kimoto authored on 2016-04-18
116
    my $work_rep_info = app->work_rep_info($user, $project);
117
    my @git_fetch_cmd = $self->app->git->cmd($work_rep_info, 'fetch');
add fetch logic
Yuki Kimoto authored on 2016-04-15
118
    Gitprep::Util::run_command(@git_fetch_cmd)
119
      or Carp::croak "Can't execute git fetch: @git_fetch_cmd";
cleanup branch
Yuki Kimoto authored on 2016-04-16
120
    
add lock system
Yuki Kimoto authored on 2016-04-18
121
    # Lock repository
122
    my $lock = $self->app->manager->lock_rep($work_rep_info);
cleanup compare logic
Yuki Kimoto authored on 2016-04-18
123
    
124
    # Checkout tmp branch and git reset --hard from my remote branch
add lock system
Yuki Kimoto authored on 2016-04-18
125
    my $gitprep_tmp_branch_name = '__gitprep_tmp_branch__';
cleanup compare logic
Yuki Kimoto authored on 2016-04-18
126
    my @git_checkout_tmp_branch = $self->app->git->cmd(
127
      $work_rep_info,
128
      'checkout',
129
      $gitprep_tmp_branch_name,
130
    );
131
    Gitprep::Util::run_command(@git_checkout_tmp_branch)
132
      or Carp::croak "Can't execute git checkout: @git_checkout_tmp_branch";
133
    
134
    # git reset --hard
135
    my @git_reset_hard_cmd = $self->app->git->cmd(
136
      $work_rep_info,
137
      'reset',
138
      '--hard',
139
      "origin/$from_rev"
140
    );
141
    Gitprep::Util::run_command(@git_reset_hard_cmd)
142
      or Carp::croak "Can't execute git reset --hard: @git_reset_hard_cmd";
143
    
add automatical merge checki...
Yuki Kimoto authored on 2016-04-18
144
    # Check merge automatically
145
    $merge_automatical = $self->app->manager->check_merge_automatical(
146
      app->work_rep_info($user, $project),
147
      $gitprep_tmp_branch_name,
148
      "origin/$rev"
149
    );
cleanup methods
Yuki Kimoto authored on 2016-04-13
150
  }
151
  
add pulls page
Yuki Kimoto authored on 2016-04-12
152
  layout 'common', title => "Comparing $from_rev...$rev \x{30fb} $user/$project";
added feature that get branc...
Yuki Kimoto authored on 2013-02-04
153
%>
154

            
cleanup compare page
Yuki Kimoto authored on 2013-04-12
155

            
improve compare page design
Yuki Kimoto authored on 2016-02-04
156
%= javascript begin
157
  $(document).ready(function () {
158
    
159
    // Change base branch
160
    $('#base-branch-btn').on('click', function () {
161
      $('#base-branch-popup')
162
        .css('display', 'block')
163
        .css('top', '40px')
164
        .css('left', '10px')
165
      ;
166
    });
167
    $('#base-branch-close').on('click', function () {
168
      $('#base-branch-popup').css('display', 'none');
169
    });
170
    $('[name=base-branch]').on('keypress', function (e) {
171
      // Enter
172
      if (e.which == 13) {
show not able to merge
Yuki Kimoto authored on 2016-04-18
173
        var href = '<%= url_for("/$user/$project/compare/") %>' + $(this).val() + '...<%= $rev %>';
174
        if (<%= $expand ? 1 : 0 %>) {
175
          href = href + '?expand=1';
176
        }
177
        location.href = href;
improve compare page design
Yuki Kimoto authored on 2016-02-04
178
      }
179
    });
show not able to merge
Yuki Kimoto authored on 2016-04-18
180
    
improve compare page design
Yuki Kimoto authored on 2016-02-04
181
    // Change compare branch
182
    $('#compare-branch-btn').on('click', function () {
183
      $('#compare-branch-popup')
184
        .css('display', 'block')
185
        .css('top', '40px')
186
        .css('left', '96px')
187
      ;
188
    });
189
    $('#compare-branch-close').on('click', function () {
190
      $('#compare-branch-popup').css('display', 'none');
191
    });
192
    $('[name=compare-branch]').on('keypress', function (e) {
193
      // Enter
194
      if (e.which == 13) {
show not able to merge
Yuki Kimoto authored on 2016-04-18
195
        var href = '<%= url_for("/$user/$project/compare/") %>' + '<%= $from_rev %>...' + $(this).val();
196
        if (<%= $expand ? 1 : 0 %>) {
197
          href = href + '?expand=1';
198
        }
199
        location.href = href;
improve compare page design
Yuki Kimoto authored on 2016-02-04
200
      }
improved compare page design
Yuki Kimoto authored on 2013-02-07
201
    });
improve compare page design
Yuki Kimoto authored on 2016-02-04
202
  });
203
% end
cleanup
Yuki Kimoto authored on 2013-02-04
204

            
improve compare page design
Yuki Kimoto authored on 2016-02-04
205
%= include '/include/header';
cleanup
Yuki Kimoto authored on 2013-02-04
206

            
improve compare page design
Yuki Kimoto authored on 2016-02-04
207
<div class="container">
add pull request form
Yuki Kimoto authored on 2016-04-12
208
  <div class="topic1">
209
    % if ($can_open_pull_request) {
210
      Open a pull request
211
    % } else {
212
      Comparing changes
213
    % }
214
  </div>
improve compare page design
Yuki Kimoto authored on 2016-02-04
215
  <div class="compare-select">
216
    <div>
217
      <div>
218
        <button id="base-branch-btn" class="btn btn-small">
219
          <span>base:</span><b> <%= $from_rev %></b><i class="icon-arrow-down"></i>
220
        </button>
221
        ...
222
        <button id="compare-branch-btn" class="btn btn-small">
223
          <span>compare:</span> <b><%= $rev %></b><i class="icon-arrow-down"></i>
224
        </button>
add automatical merge checki...
Yuki Kimoto authored on 2016-04-18
225
        
show not able to merge
Yuki Kimoto authored on 2016-04-18
226
        % if ($can_open_pull_request) {
227
          % if ($merge_automatical) {
228
            <span style="margin-left:10px">
229
              <span style="color:green;font-weight:bold"><%= "\x{2714}" %>Able to merge.</span> These branches can be automatically merged.
230
            </span>
231
          % } else {
232
            <span style="margin-left:10px">
233
              <span style="color:red;font-weight:bold"><%= "×" %>Not able to merge.</span> These branches can't be automatically merged.
234
            </span>
235
          % }
add automatical merge checki...
Yuki Kimoto authored on 2016-04-18
236
        % }
cleanup
Yuki Kimoto authored on 2013-03-15
237
      </div>
improve compare page design
Yuki Kimoto authored on 2016-02-04
238
    </div>
show not able to merge
Yuki Kimoto authored on 2016-04-18
239

            
240
    <div id="base-branch-popup" style="display:none;width:330px;position:absolute">
241
      <div class="radius-top border-gray" style="background:#E6E6FA;padding:10px">
242
        <div style="overflow:hidden">
243
          <div style="float:left;width:90%;">
244
            <b>Choose a base branch</b>
245
          </div>
246
          <div style="float:left:width:10%;text-align:right;">
247
            <i id="base-branch-close" class="icon-remove-circle"></i>
added base branch selection ...
Yuki Kimoto authored on 2013-05-10
248
          </div>
show pull request only when ...
Yuki Kimoto authored on 2016-04-18
249
        </div>
improve compare page design
Yuki Kimoto authored on 2016-02-04
250
      </div>
show not able to merge
Yuki Kimoto authored on 2016-04-18
251
      <div class="border-gray" style="background:#F5F5F5;border-top:none;border-bottom:none;text-align:center;padding:10px 0">
252
        %= text_field 'base-branch', style => 'margin-bottom:0;width:270px', placeholder => 'Branch, tag, commit, or history marker';
253
      </div>
254
      <div style="background:white;max-height:500px;overflow:auto;">
255
        <ul class="nav nav-tabs nav-stacked">
256
          % for (my $i = 0; $i < @$branches; $i++) {
257
            % my $branch = $branches->[$i];
258
              <li>
259
                <a style="border-top-left-radius:0px;border-top-right-radius:0px;"
260
                  href="<%= url_with("/$user/$project/compare/$branch->{name}...$rev") %>">
261
                  <%= $branch->{name} %>
262
                </a>
263
              </li>
264
          % }
265
        </ul>
266
      </div>
267
    </div>
268

            
improve compare page design
Yuki Kimoto authored on 2016-02-04
269
    <div id="compare-branch-popup" style="display:none;width:330px;position:absolute">
270
      <div class="radius-top border-gray" style="background:#E6E6FA;padding:10px">
271
        <div style="overflow:hidden">
272
          <div style="float:left;width:90%;">
273
            <b>Choose a compare branch</b>
274
          </div>
275
          <div style="float:left:width:10%;text-align:right;">
276
            <i id="compare-branch-close" class="icon-remove-circle"></i>
added compare branch popup t...
Yuki Kimoto authored on 2013-05-10
277
          </div>
278
        </div>
279
      </div>
improve compare page design
Yuki Kimoto authored on 2016-02-04
280
      <div class="border-gray" style="background:#F5F5F5;border-top:none;border-bottom:none;text-align:center;padding:10px 0">
281
        %= text_field 'compare-branch', style => 'margin-bottom:0;width:270px', placeholder => 'Branch, tag, commit, or history marker';
282
      </div>
283
      <div style="background:white;max-height:500px;overflow:auto;">
284
      <ul class="nav nav-tabs nav-stacked">
285
        % for (my $i = 0; $i < @$branches; $i++) {
286
          % my $branch = $branches->[$i];
287
            <li>
show not able to merge
Yuki Kimoto authored on 2016-04-18
288
              <a style="border-top-left-radius:0px;border-top-right-radius:0px;"
289
                href="<%= url_with("/$user/$project/compare/$from_rev...$branch->{name}") %>">
improve compare page design
Yuki Kimoto authored on 2016-02-04
290
                <%= $branch->{name} %>
291
              </a>
292
            </li>
293
        % }
294
      </ul>
295
      </div>
added base branch selection ...
Yuki Kimoto authored on 2013-05-10
296
    </div>
improve compare page design
Yuki Kimoto authored on 2016-02-04
297
  </div>
add pull request form
Yuki Kimoto authored on 2016-04-12
298
  
show not able to merge
Yuki Kimoto authored on 2016-04-18
299
  % if ($merge_automatical) {
add pull request form
Yuki Kimoto authored on 2016-04-12
300
    <div class="compare-open-pull-request">
add create pull request logi...
Yuki Kimoto authored on 2016-04-19
301
      <form action="<%= url_for %>" method="post">
302
        <%= hidden_field op => 'create-pull-request' %>
add pull request form
Yuki Kimoto authored on 2016-04-12
303
        <div class="compare-open-pull-request-title">
cleanup methods
Yuki Kimoto authored on 2016-04-13
304
          <%= text_field 'title' => $commits->[0]{title_short}  %>
add pull request form
Yuki Kimoto authored on 2016-04-12
305
        </div>
306
        <div class="compare-open-pull-request-message">
307
          <%= text_area 'message' %>
308
        </div>
309
        <div class="compare-open-pull-request-button">
310
          <%= submit_button 'Create pull request', class => 'btn btn-success' %>
311
        </div>
312
      </form>
313
    </div>
314
  % }
added base branch popup to c...
Yuki Kimoto authored on 2013-05-10
315

            
improve compare page design
Yuki Kimoto authored on 2016-02-04
316
  % if (keys %$commits_date) {
317
    <ul class="compare-header">
318
      <li>
319
        <b><%= @$commits %></b> <span>commit</span>
320
      </li>
321
      <li>
322
        <b><%= $authors_count %></b> <span>contributor</span>
323
      </li>
324
      <li>
325
        
326
      </li>
327
      <li>
328
        
329
      </li>
330
    </ul>
improved compare page design
Yuki Kimoto authored on 2013-02-07
331
    
improve compare page design
Yuki Kimoto authored on 2016-02-04
332
    <div class="commits">
expand compare page tabs
Yuki Kimoto authored on 2013-08-10
333
      % for my $date (reverse sort keys %$commits_date) {
334
        % my $commits = $commits_date->{$date};
335
        
improve compare page design
Yuki Kimoto authored on 2016-02-04
336
        <div class="commit-date">
337
          <i class="icon-off"></i><span>Commits on <%= $date %></span>
expand compare page tabs
Yuki Kimoto authored on 2013-08-10
338
        </div>
339
        
improve compare page design
Yuki Kimoto authored on 2016-02-04
340
        <ul class="compare-commits-date-container">
expand compare page tabs
Yuki Kimoto authored on 2013-08-10
341
          % for my $commit (sort {$b->{author_epoch} <=> $a->{author_epoch}} @$commits) {
add user page link from user...
Yuki Kimoto authored on 2016-04-11
342
            <%
343
              my $commit_author_mail = $commit->{author_email};
344
              my $commit_author_id = app->dbi->model('user')->select(
345
                'id',
346
                where => {mail => $commit_author_mail}
347
              )->value;
348
            %>
improve compare page design
Yuki Kimoto authored on 2016-02-04
349
            <li>
350
              <div class="compare-commits-author">
add user page link from user...
Yuki Kimoto authored on 2016-04-11
351
                <span title="<%= $commit->{author_email} %>">
352
                  % if (defined $commit_author_id) {
353
                    <a href="<%= url_for("/$commit_author_id") %>"><%= $commit_author_id %></a>
354
                  % } else {
355
                    <%= $commit->{author_name} %>
356
                  % }
357
                </span>
expand compare page tabs
Yuki Kimoto authored on 2013-08-10
358
              </div>
improve compare page design
Yuki Kimoto authored on 2016-02-04
359
              <div class="compare-commits-commit-title">
360
                <a style="color:#333" href="<%= url_for("/$user/$project/commit/$commit->{id}") %>">
361
                  <%= $commit->{title_short} %>
362
                </a>
363
              </div>
364
              <div class="compare-commits-commit-id">
365
                <a href="<%= url_for("/$user/$project/commit/$commit->{id}") %>">
366
                  <%= substr($commit->{id}, 0, 7) %>
367
                </a>
368
              </div>
369
            </li>
improved branches page and c...
Yuki Kimoto authored on 2013-05-07
370
          % }
improve compare page design
Yuki Kimoto authored on 2016-02-04
371
        </ul>
expand compare page tabs
Yuki Kimoto authored on 2013-08-10
372
      % }
improve compare page design
Yuki Kimoto authored on 2016-02-04
373
    </div>
374
  
375
    %= include '/include/commit_body';
376
  % } else {
improve compare page
Yuki Kimoto authored on 2016-04-12
377
    <div class="compare-nothing">
378
      <div>
379
        <b><big>There isn't anything to compare.</big></b>
380
      </div>
381
      <div>
show not able to merge
Yuki Kimoto authored on 2016-04-18
382
        <b>
383
          <%= $from_rev %></b> is up to date with all commits from
384
          <b><%= $rev %></b>.
385
          Try <a href="<%= url_for("/$user/$project/compare/$rev...$from_rev") %>">switching the base</a> for your comparison.
improve compare page
Yuki Kimoto authored on 2016-04-12
386
      </div>
improve compare page design
Yuki Kimoto authored on 2016-02-04
387
    </div>
388
  % }
389
</div>
390
%= include '/include/footer';