Show More
@@ -1,110 +1,109 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 |
# Copyright (C) 201 |
|
|
3 | # Copyright (C) 2017-2017 RhodeCode GmbH | |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import logging |
|
22 | 22 | from pyramid.view import view_config |
|
23 | 23 | |
|
24 | 24 | from rhodecode.apps._base import RepoAppView |
|
25 | 25 | from rhodecode.lib.auth import (LoginRequired, HasRepoPermissionAnyDecorator, |
|
26 | 26 | NotAnonymous) |
|
27 | ||
|
27 | from rhodecode.lib.ext_json import json | |
|
28 | 28 | |
|
29 | 29 | log = logging.getLogger(__name__) |
|
30 | 30 | |
|
31 | 31 | |
|
32 | 32 | class StripView(RepoAppView): |
|
33 | 33 | def load_default_context(self): |
|
34 | 34 | c = self._get_local_tmpl_context() |
|
35 | 35 | |
|
36 | 36 | # TODO(marcink): remove repo_info and use c.rhodecode_db_repo instead |
|
37 | 37 | c.repo_info = self.db_repo |
|
38 | 38 | |
|
39 | 39 | self._register_global_c(c) |
|
40 | 40 | return c |
|
41 | 41 | |
|
42 | 42 | @LoginRequired() |
|
43 | 43 | @NotAnonymous() |
|
44 | 44 | @HasRepoPermissionAnyDecorator('repository.admin') |
|
45 | 45 | @view_config( |
|
46 | 46 | route_name='strip', request_method='GET', |
|
47 | 47 | renderer='rhodecode:templates/admin/repos/repo_edit.mako') |
|
48 | 48 | def strip(self): |
|
49 | 49 | c = self.load_default_context() |
|
50 | 50 | c.active = 'strip' |
|
51 | 51 | c.strip_limit = 10 |
|
52 | 52 | |
|
53 | 53 | return self._get_template_context(c) |
|
54 | 54 | |
|
55 | 55 | @LoginRequired() |
|
56 | 56 | @NotAnonymous() |
|
57 | 57 | @HasRepoPermissionAnyDecorator('repository.admin') |
|
58 | 58 | @view_config( |
|
59 | 59 | route_name='strip_check', request_method='POST', |
|
60 | renderer='json', xhr=True | |
|
61 | ) | |
|
60 | renderer='json', xhr=True) | |
|
62 | 61 | def strip_check(self): |
|
63 | 62 | from rhodecode.lib.vcs.backends.base import EmptyCommit |
|
64 | 63 | data = {} |
|
65 | 64 | rp = self.request.POST |
|
66 | 65 | for i in range(1, 11): |
|
67 | chset = 'changeset_id-%d'%(i,) | |
|
66 | chset = 'changeset_id-%d' % (i,) | |
|
68 | 67 | check = rp.get(chset) |
|
69 | 68 | if check: |
|
70 | 69 | data[i] = self.db_repo.get_changeset(rp[chset]) |
|
71 | 70 | if isinstance(data[i], EmptyCommit): |
|
72 | 71 | data[i] = {'rev': None, 'commit': rp[chset]} |
|
73 | 72 | else: |
|
74 |
data[i] = {'rev': data[i].raw_id, 'branch': data[i].branch, |
|
|
73 | data[i] = {'rev': data[i].raw_id, 'branch': data[i].branch, | |
|
74 | 'author': data[i].author, | |
|
75 | 75 | 'comment': data[i].message} |
|
76 | 76 | else: |
|
77 | 77 | break |
|
78 | 78 | return data |
|
79 | 79 | |
|
80 | 80 | @LoginRequired() |
|
81 | 81 | @NotAnonymous() |
|
82 | 82 | @HasRepoPermissionAnyDecorator('repository.admin') |
|
83 | 83 | @view_config( |
|
84 | 84 | route_name='strip_execute', request_method='POST', |
|
85 | renderer='json', xhr=True | |
|
86 | ) | |
|
85 | renderer='json', xhr=True) | |
|
87 | 86 | def strip_execute(self): |
|
88 | ||
|
89 | 87 | from rhodecode.model.scm import ScmModel |
|
90 | from rhodecode.lib.ext_json import json | |
|
91 | 88 | |
|
92 | 89 | c = self.load_default_context() |
|
93 | 90 | user = self._rhodecode_user |
|
94 | 91 | rp = self.request.POST |
|
95 | 92 | data = {} |
|
96 | 93 | for idx in rp: |
|
97 | 94 | commit = json.loads(rp[idx]) |
|
98 | #If someone put two times the same branch | |
|
95 | # If someone put two times the same branch | |
|
99 | 96 | if commit['branch'] in data.keys(): |
|
100 | 97 | continue |
|
101 | 98 | try: |
|
102 |
ScmModel().strip( |
|
|
103 | commit_id=commit['rev'], branch=commit['branch']) | |
|
104 | log.info('Stripped commit %s from repo `%s` by %s' % (commit['rev'], c.repo_info.repo_name, user)) | |
|
99 | ScmModel().strip( | |
|
100 | repo=c.repo_info, | |
|
101 | commit_id=commit['rev'], branch=commit['branch']) | |
|
102 | log.info('Stripped commit %s from repo `%s` by %s' % ( | |
|
103 | commit['rev'], c.repo_info.repo_name, user)) | |
|
105 | 104 | data[commit['rev']] = True |
|
106 |
except Exception |
|
|
105 | except Exception as e: | |
|
107 | 106 | data[commit['rev']] = False |
|
108 |
log.debug('Stripped commit %s from repo `%s` failed by %s, exeption %s' % ( |
|
|
109 | c.repo_info.repo_name, user, e.message)) | |
|
107 | log.debug('Stripped commit %s from repo `%s` failed by %s, exeption %s' % ( | |
|
108 | commit['rev'], self.db_repo_name, user, e.message)) | |
|
110 | 109 | return data |
General Comments 0
You need to be logged in to leave comments.
Login now