gitprep / templates / compare.html.ep /
Newer Older
399 lines | 12.976kb
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 {
add pulls description
Yuki Kimoto authored on 2016-04-20
41
        my $now_tm = Time::Moment->now_utc;
42
        my $now_epoch = $now_tm->epoch;
43
        my $user_row_id = app->dbi->model('user')->select(
44
          'row_id',
45
          where => {id => $user}
46
        )->value;
47
        
add create pull request logi...
Yuki Kimoto authored on 2016-04-19
48
        my $new_pull_request_params = {
49
          project => $project_row_id,
50
          branch1 => $from_rev,
51
          branch2 => $rev,
52
          title => $title,
create pull request list
Yuki Kimoto authored on 2016-04-20
53
          message => $message,
add pulls description
Yuki Kimoto authored on 2016-04-20
54
          open => 1,
55
          open_time => $now_epoch,
56
          open_user => $user_row_id
add create pull request logi...
Yuki Kimoto authored on 2016-04-19
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 => {
64
            project => $project_row_id,
65
            branch1 => $from_rev,
66
            branch2 => $rev
67
          }
68
        )->value;
69
        
70
        $self->redirect_to("/$user/$project/pulls/$new_pull_request_row_id");
71
        return;
72
      }
73
      
74
    }
75
  }
76
  
added feature that get branc...
Yuki Kimoto authored on 2013-02-04
77
  # Commits
cleanup method
Yuki Kimoto authored on 2016-04-16
78
  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
79
  my $commits_count = @$commits;
80
  my $commits_date = {};
improved compare page commit...
Yuki Kimoto authored on 2013-02-06
81
  my $authors = {};
added feature that get branc...
Yuki Kimoto authored on 2013-02-04
82
  for my $commit (@$commits) {
support time zone
Yuki Kimoto authored on 2014-03-08
83
    my $date = $commit->{age_string_date_local};
added feature that get branc...
Yuki Kimoto authored on 2013-02-04
84
    $commits_date->{$date} ||= [];
improved compare page commit...
Yuki Kimoto authored on 2013-02-06
85
    $authors->{$commit->{author}} = 1;
added feature that get branc...
Yuki Kimoto authored on 2013-02-04
86
    push @{$commits_date->{$date}}, $commit;
87
  }
improved compare page commit...
Yuki Kimoto authored on 2013-02-06
88
  my $authors_count = keys %$authors;
added compare page file chan...
Yuki Kimoto authored on 2013-02-07
89

            
90
  # Start commit
cleanup methods
Yuki Kimoto authored on 2016-04-16
91
  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
92

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

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

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

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

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

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

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

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