gitprep / templates / import-branch.html.ep /
Newer Older
182 lines | 5.343kb
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;
cleanup rep_info
Yuki Kimoto authored on 2016-04-16
19
  my $remote_branches = $git->branches($self->app->rep_info($remote_user, $remote_project));
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
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') {
cleanup import-branch valida...
Yuki Kimoto authored on 2016-02-11
25
    # Parameters
26
    my $user = param('user');
27
    my $project = param('project');
28
    my $branch = param('branch');
29
    my $remote_user = param('remote_user');
30
    my $remote_project = param('remote_project');
31
    my $remote_branch = param('remote-branch');
32
    my $force = param('force');
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
33
    
cleanup import-branch valida...
Yuki Kimoto authored on 2016-02-11
34
    # Validator
35
    my $vc = app->vc;
36
    
37
    # Validation result
38
    my $validation = $vc->validation;
39
    
40
    # "user"
41
    if (!$vc->check($user, 'user_name')) {
42
      $validation->add_failed('User name is invalid.');
43
    }
44
    
45
    # "project"
46
    if (!$vc->check($project, 'project_name')) {
47
      $validation->add_failed('Repository name is invalid.');
48
    }
49
    
50
    # "branch"
51
    if (!(defined $branch && length $branch)) {
52
      $validation->add_failed('Branch name is empty.');
53
    }
54
    
55
    # "remote_user"
56
    if (!$vc->check($remote_user, 'user_name')) {
57
      $validation->add_failed('Remote User name is invalid.');
58
    }
59
    
60
    # "remote_project"
61
    if (!$vc->check($remote_project, 'project_name')) {
62
      $validation->add_failed('Remote repository is invalid.');
63
    }
64
    
65
    # "remote-branch"
66
    if (!(defined $remote_branch && length $remote_branch)) {
67
      $validation->add_failed('Remote branch name is empty.');
68
    }
69
    
70
    # "force"
71
    $force = $force ? 1 : 0;
72
    
73
    if ($validation->is_valid) {
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
74
      
complete branch import featu...
Yuki Kimoto authored on 2013-08-15
75
      # Check branch name
cleanup rep_info
Yuki Kimoto authored on 2016-04-16
76
      my $branches = $git->branches($self->app->rep_info($user, $project));
improve import-branch page d...
Yuki Kimoto authored on 2013-08-15
77
      
complete branch import featu...
Yuki Kimoto authored on 2013-08-15
78
      if (!$force && grep { $branch eq $_->{name} } @$branches) {
79
        $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
80
      }
81
      else {
complete branch import featu...
Yuki Kimoto authored on 2013-08-15
82
        eval {
83
          $git->import_branch(
cleanup import_branch
Yuki Kimoto authored on 2016-04-16
84
            app->rep_info($user, $project),
complete branch import featu...
Yuki Kimoto authored on 2013-08-15
85
            $branch,
cleanup import_branch
Yuki Kimoto authored on 2016-04-16
86
            app->rep_info($remote_user, $remote_project),
complete branch import featu...
Yuki Kimoto authored on 2013-08-15
87
            $remote_branch,
88
            {force => $force}
89
          );
90
        };
91
        
cleanup import-branch valida...
Yuki Kimoto authored on 2016-02-11
92
        if (my $e = $@) {
complete branch import featu...
Yuki Kimoto authored on 2013-08-15
93
          $errors = ['Internal Error'];
cleanup import-branch valida...
Yuki Kimoto authored on 2016-02-11
94
          app->log->error(url_for . ": $e");
complete branch import featu...
Yuki Kimoto authored on 2013-08-15
95
        }
96
        else {
97
          flash(message => "Success: " . ($force ? 'force ' : '') . "import \"$remote_user / $remote_project / $remote_branch\" into \"$user / $project / $branch\"");
98
          $self->redirect_to('current');
99
          return;
100
        }
improve import-branch page d...
Yuki Kimoto authored on 2013-08-15
101
      }
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
102
    }
103
    else {
cleanup import-branch valida...
Yuki Kimoto authored on 2016-02-11
104
      $errors = $validation->messages;
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
105
    }
106
  }
improve import-branch page d...
Yuki Kimoto authored on 2016-02-08
107

            
108
  layout 'common', title => "Import branch";
change pull feature to impor...
Yuki Kimoto authored on 2013-08-14
109
%>
110

            
111
  %= include 'include/header';
improve import-branch page d...
Yuki Kimoto authored on 2013-08-15
112

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