gitprep / templates / import-branch.html.ep /
Newer Older
176 lines | 5.413kb
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
1
<%
add import-branch authentica...
Yuki Kimoto authored on 2013-08-19
2
  
3
  my $api = gitprep_api;
4
  
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
5
  my $user = param('user');
6
  my $project = param('project');
add import branch tests
Yuki Kimoto authored on 2013-08-19
7
  my $remote_user = param('remote_user');
8
  my $remote_project = param('remote_project');
9
  my $remote_branch = param('remote-branch');
add import-branch authentica...
Yuki Kimoto authored on 2013-08-19
10
  
11
  # Authentication
12
  unless ($api->logined($user)) {
13
    $self->redirect_to('/');
14
    return;
15
  }
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
16
  
17
  # Branches
revert encoding support
Yuki Kimoto authored on 2013-11-22
18
  my $git = app->git;
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
19
  my $remote_branches = $git->branches($remote_user, $remote_project);
20
  my $remote_branch_names = [map { $_->{name} } @$remote_branches];
21
  
22
  my $op = param('op') || '';
23
  my $errors;
improve import-branch page d...
Yuki Kimoto authored on 2013-08-15
24
  if ($op eq 'import' && lc $self->req->method eq 'post') {
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
25
  
26
    # Validation
27
    my $api = gitprep_api;
28
    my $params = $api->params;
29
    my $rule = [
30
      user => [
improve import-branch page d...
Yuki Kimoto authored on 2013-08-15
31
        ['user_name' => 'User name is invalid.']
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
32
      ],
33
      project => [
improve import-branch page d...
Yuki Kimoto authored on 2013-08-15
34
        ['project_name' => 'Repository name is invalid.']
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
35
      ],
36
      branch => [
improve import-branch page d...
Yuki Kimoto authored on 2013-08-15
37
        ['not_blank' => 'Branch name is empty.']
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
38
      ],
39
      remote_user => [
improve import-branch page d...
Yuki Kimoto authored on 2013-08-15
40
        ['user_name' => 'Remote User name is invalid.']
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
41
      ],
42
      remote_project => [
improve import-branch page d...
Yuki Kimoto authored on 2013-08-15
43
        ['project_name' => 'Remote repository is invalid.']
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
44
      ],
add import branch tests
Yuki Kimoto authored on 2013-08-19
45
      'remote-branch' => [
improve import-branch page d...
Yuki Kimoto authored on 2013-08-15
46
        ['not_blank' => 'Remote branch name is empty.']
complete branch import featu...
Yuki Kimoto authored on 2013-08-15
47
      ],
48
      force => {require => 0} => [
49
        'any'
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
50
      ]
51
    ];
rename validator to vc to up...
Yuki Kimoto authored on 2013-12-02
52
    my $vresult = app->vc->validate($params, $rule);
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
53
    
54
    if ($vresult->is_ok) {
55
      my $safe_params = $vresult->data;
56
      
complete branch import featu...
Yuki Kimoto authored on 2013-08-15
57
      # Valid paramters
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
58
      my $user = $safe_params->{user};
59
      my $project = $safe_params->{project};
60
      my $branch = $safe_params->{branch};
61
      my $remote_user = $safe_params->{remote_user};
62
      my $remote_project = $safe_params->{remote_project};
add import branch tests
Yuki Kimoto authored on 2013-08-19
63
      my $remote_branch = $safe_params->{'remote-branch'};
complete branch import featu...
Yuki Kimoto authored on 2013-08-15
64
      my $force = $safe_params->{force};
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
65
      
complete branch import featu...
Yuki Kimoto authored on 2013-08-15
66
      # Check branch name
67
      my $branches = $git->branches($user, $project);
improve import-branch page d...
Yuki Kimoto authored on 2013-08-15
68
      
complete branch import featu...
Yuki Kimoto authored on 2013-08-15
69
      if (!$force && grep { $branch eq $_->{name} } @$branches) {
70
        $errors = ["Branch \"$branch\" is already exists. If you want to import this branch, check force option."];
improve import-branch page d...
Yuki Kimoto authored on 2013-08-15
71
      }
72
      else {
complete branch import featu...
Yuki Kimoto authored on 2013-08-15
73
        eval {
74
          $git->import_branch(
75
            $user,
76
            $project,
77
            $branch,
78
            $remote_user,
79
            $remote_project,
80
            $remote_branch,
81
            {force => $force}
82
          );
83
        };
84
        
85
        if ($@) {
86
          $errors = ['Internal Error'];
87
        }
88
        else {
89
          flash(message => "Success: " . ($force ? 'force ' : '') . "import \"$remote_user / $remote_project / $remote_branch\" into \"$user / $project / $branch\"");
90
          $self->redirect_to('current');
91
          return;
92
        }
improve import-branch page d...
Yuki Kimoto authored on 2013-08-15
93
      }
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
94
    }
95
    else {
improve import-branch page d...
Yuki Kimoto authored on 2013-08-15
96
      $errors = $vresult->messages;
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
97
    }
98
  }
99
%>
100

            
101
% layout 'common', title => "Import branch";
102
  %= include 'include/header';
improve import-branch page d...
Yuki Kimoto authored on 2013-08-15
103

            
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
104
  %= javascript begin
105
    $('document').ready(function () {
106
      
107
      // Select remote branch
108
      $('[name=copy-branch-name]').on('click', function () {
109
        $('[name=branch]').val($('[name=remote_branch]').val());
110
        return false;
111
      });
112
    });
113
  % end
114
  
115
  <div class="container">
improve import-branch page d...
Yuki Kimoto authored on 2013-08-15
116
    %= include '/include/project_header';
117
    % if (my $message = flash('message')) {
118
      <div class="alert alert-success">
119
        <button type="button" class="close" data-dismiss="alert">&times;</button>
120
        <%= $message %>
121
      </div>
122
    % }
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
123
    % if ($errors) {
124
      <div class="alert alert-error">
125
        <button type="button" class="close" data-dismiss="alert">&times;</button>
126
        % for my $error (@$errors) {
127
          <p><%= $error %></p>
128
        % }
129
      </div>
130
    % }
131
    <h3>Import branch</h3>
add import branch tests
Yuki Kimoto authored on 2013-08-19
132
    <form action="<%= url_for("/$user/$project/import-branch/$remote_user/$remote_project")->query(op => 'import') %>" method="post">
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
133
      <div class="row" style="font-size:22px">
improve import-branch page d...
Yuki Kimoto authored on 2013-08-15
134
        <div class="span6">
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
135
          <div class="well" style="text-align:center">
136
            <div style="color:blue;margin-bottom:15px">
137
              %= "$user / $project";
138
            </div>
139
            <div>
improve import-branch page d...
Yuki Kimoto authored on 2013-08-15
140
              %= text_field 'branch', placeholder => "Branch name", style => "margin-top:12px;width:250px";
141
              <button name="copy-branch-name", class="btn" style="font-size:12px; padding-left:3px;padding-right:3px;color:#666">Copy Branch Name</button>
142
            </div>
complete branch import featu...
Yuki Kimoto authored on 2013-08-15
143
            <table style="width:100%">
144
              <tr>
145
                <td style="width:80px;text-align:right">
146
                  %= submit_button 'Import', class => "btn";
147
                </td>
148
                <td style="width:20px;">
149
                  <%= check_box force => 1 %> 
150
                </td>
151
                <td style="font-size:13px;padding-top:7px;text-align:left">
152
                  Force
153
                </td>
154
              </tr>
155
            </table>
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
156
          </div>
157
        </div>
improve import-branch page d...
Yuki Kimoto authored on 2013-08-15
158
        <div class="span1">
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
159
          <div style="padding: 19px;text-align:center;font-size:26px">
160
            &lArr;
161
          </div>
162
        </div>
163
        <div class="span5">
164
          <div class="well" style="text-align:center">
165
            <div style="color:green;margin-bottom:15px">
166
              %= "$remote_user / $remote_project";
167
            </div>
168
            % param(remote_branch => $remote_branch);
add import branch tests
Yuki Kimoto authored on 2013-08-19
169
            %= select_field 'remote-branch' => $remote_branch_names, style => "width:250px";
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
170
          </div>
171
        </div>
172
      </div>
173
    </form>
174
  </div>
175
  
176
  %= include '/include/footer';