Mercurial > kallithea
annotate rhodecode/lib/hooks.py @ 4147:1c8f818787b3 rhodecode-2.2.5-gpl
old style: show the full link box on summary page - no overlap or truncation
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Wed, 02 Jul 2014 19:03:23 -0400 |
parents | 31e119cb02ef |
children | e9f6b533a8f6 |
rev | line source |
---|---|
913
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
1 # -*- coding: utf-8 -*- |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
2 # This program is free software: you can redistribute it and/or modify |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
3 # it under the terms of the GNU General Public License as published by |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
4 # the Free Software Foundation, either version 3 of the License, or |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
5 # (at your option) any later version. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1114
diff
changeset
|
6 # |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 # This program is distributed in the hope that it will be useful, |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 # GNU General Public License for more details. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1114
diff
changeset
|
11 # |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 # You should have received a copy of the GNU General Public License |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
13 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
14 """ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
15 rhodecode.lib.hooks |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
16 ~~~~~~~~~~~~~~~~~~~ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
17 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
18 Hooks runned by rhodecode |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
19 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
20 :created_on: Aug 6, 2010 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
21 :author: marcink |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
22 :copyright: (c) 2013 RhodeCode GmbH. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
23 :license: GPLv3, see LICENSE for more details. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
24 """ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
25 |
913
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
26 import os |
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
27 import sys |
2904
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
28 import time |
2324
1dbf07735af4
save full raw id in push log data for much faster revision lookup
Marcin Kuzminski <marcin@python-works.com>
parents:
2236
diff
changeset
|
29 import binascii |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 |
3941
3208aaefc9ca
Moved all Mercurial imports into hgcompat from vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
3840
diff
changeset
|
31 from rhodecode.lib.vcs.utils.hgcompat import nullrev, revrange |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
32 from rhodecode.lib import helpers as h |
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
33 from rhodecode.lib.utils import action_logger |
2404
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2402
diff
changeset
|
34 from rhodecode.lib.vcs.backends.base import EmptyChangeset |
4074
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
4017
diff
changeset
|
35 from rhodecode.lib.exceptions import HTTPLockedRC, UserCreationError |
3577
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
36 from rhodecode.lib.utils2 import safe_str, _extract_extras |
2818
3d0bd5f71dab
raise na OSERROR if repository data sent from git hook to hook handler is somehow invalid
Marcin Kuzminski <marcin@python-works.com>
parents:
2750
diff
changeset
|
37 from rhodecode.model.db import Repository, User |
1307 | 38 |
2904
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
39 |
2196
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
40 def _get_scm_size(alias, root_path): |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
41 |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
42 if not alias.startswith('.'): |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
43 alias += '.' |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
44 |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
45 size_scm, size_root = 0, 0 |
2963
742d1b8ca263
use str() on os.walk passing unicode can lead to UnicodeDecode errors when iterating
Marcin Kuzminski <marcin@python-works.com>
parents:
2958
diff
changeset
|
46 for path, dirs, files in os.walk(safe_str(root_path)): |
2196
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
47 if path.find(alias) != -1: |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
48 for f in files: |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
49 try: |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
50 size_scm += os.path.getsize(os.path.join(path, f)) |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
51 except OSError: |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
52 pass |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
53 else: |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
54 for f in files: |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
55 try: |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
56 size_root += os.path.getsize(os.path.join(path, f)) |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
57 except OSError: |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
58 pass |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
59 |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
60 size_scm_f = h.format_byte_size(size_scm) |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
61 size_root_f = h.format_byte_size(size_root) |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
62 size_total_f = h.format_byte_size(size_root + size_scm) |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
63 |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
64 return size_scm_f, size_root_f, size_total_f |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
65 |
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
66 |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 def repo_size(ui, repo, hooktype=None, **kwargs): |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
68 """ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
69 Presents size of repository after push |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1114
diff
changeset
|
70 |
913
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
71 :param ui: |
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
72 :param repo: |
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
73 :param hooktype: |
d173938d711b
filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
74 """ |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 |
2196
7ccf403b9c3f
made repo-size hook more generic
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
76 size_hg_f, size_root_f, size_total_f = _get_scm_size('.hg', repo.root) |
1814
9de452afbe01
small change for post update hook that displays repository size
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
77 |
9de452afbe01
small change for post update hook that displays repository size
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
78 last_cs = repo[len(repo) - 1] |
9de452afbe01
small change for post update hook that displays repository size
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
79 |
9de452afbe01
small change for post update hook that displays repository size
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
80 msg = ('Repository size .hg:%s repo:%s total:%s\n' |
9de452afbe01
small change for post update hook that displays repository size
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
81 'Last revision is now r%s:%s\n') % ( |
9de452afbe01
small change for post update hook that displays repository size
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
82 size_hg_f, size_root_f, size_total_f, last_cs.rev(), last_cs.hex()[:12] |
9de452afbe01
small change for post update hook that displays repository size
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
83 ) |
9de452afbe01
small change for post update hook that displays repository size
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
84 |
9de452afbe01
small change for post update hook that displays repository size
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
85 sys.stdout.write(msg) |
675
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
86 |
1307 | 87 |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
88 def pre_push(ui, repo, **kwargs): |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
89 # pre push function, currently used to ban pushing when |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
90 # repository is locked |
3577
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
91 ex = _extract_extras() |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
92 |
3577
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
93 usr = User.get_by_username(ex.username) |
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
94 if ex.locked_by[0] and usr.user_id != int(ex.locked_by[0]): |
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
95 locked_by = User.get(ex.locked_by[0]).username |
3522
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
96 # this exception is interpreted in git/hg middlewares and based |
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
97 # on that proper return code is server to client |
3577
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
98 _http_ret = HTTPLockedRC(ex.repository, locked_by) |
3522
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
99 if str(_http_ret.code).startswith('2'): |
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
100 #2xx Codes don't raise exceptions |
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
101 sys.stdout.write(_http_ret.title) |
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
102 else: |
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
103 raise _http_ret |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
104 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
105 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
106 def pre_pull(ui, repo, **kwargs): |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
107 # pre push function, currently used to ban pushing when |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
108 # repository is locked |
3577
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
109 ex = _extract_extras() |
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
110 if ex.locked_by[0]: |
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
111 locked_by = User.get(ex.locked_by[0]).username |
3522
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
112 # this exception is interpreted in git/hg middlewares and based |
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
113 # on that proper return code is server to client |
3577
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
114 _http_ret = HTTPLockedRC(ex.repository, locked_by) |
3522
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
115 if str(_http_ret.code).startswith('2'): |
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
116 #2xx Codes don't raise exceptions |
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
117 sys.stdout.write(_http_ret.title) |
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
118 else: |
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
119 raise _http_ret |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
120 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
121 |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
122 def log_pull_action(ui, repo, **kwargs): |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
123 """ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
124 Logs user last pull action |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1114
diff
changeset
|
125 |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
126 :param ui: |
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
127 :param repo: |
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
128 """ |
3577
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
129 ex = _extract_extras() |
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
130 |
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
131 user = User.get_by_username(ex.username) |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
132 action = 'pull' |
3577
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
133 action_logger(user, action, ex.repository, ex.ip, commit=True) |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
134 # extension hook call |
2406
7be31af5bc78
changed scope of calling EXTENSIONS from rhodecode for githooks to be able to execute them
Marcin Kuzminski <marcin@python-works.com>
parents:
2404
diff
changeset
|
135 from rhodecode import EXTENSIONS |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
136 callback = getattr(EXTENSIONS, 'PULL_HOOK', None) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
137 if callable(callback): |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
138 kw = {} |
3577
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
139 kw.update(ex) |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
140 callback(**kw) |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
141 |
3672
55585c86be83
hooks: make_lock is tristate
Mads Kiilerich <madski@unity3d.com>
parents:
3625
diff
changeset
|
142 if ex.make_lock is not None and ex.make_lock: |
3577
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
143 Repository.lock(Repository.get_by_repo_name(ex.repository), user.user_id) |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
144 #msg = 'Made lock on repo `%s`' % repository |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
145 #sys.stdout.write(msg) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
146 |
3577
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
147 if ex.locked_by[0]: |
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
148 locked_by = User.get(ex.locked_by[0]).username |
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
149 _http_ret = HTTPLockedRC(ex.repository, locked_by) |
3522
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
150 if str(_http_ret.code).startswith('2'): |
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
151 #2xx Codes don't raise exceptions |
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
152 sys.stdout.write(_http_ret.title) |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
153 return 0 |
503
3d6d548ad3cc
Added user action mapper to map push to changeset.
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
154 |
1307 | 155 |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
156 def log_push_action(ui, repo, **kwargs): |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
157 """ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1416
diff
changeset
|
158 Maps user last push action to new changeset id, from mercurial |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1114
diff
changeset
|
159 |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
160 :param ui: |
2236
37c143aa8616
fixes issue #436 git push error
Marcin Kuzminski <marcin@python-works.com>
parents:
2203
diff
changeset
|
161 :param repo: repo object containing the `ui` object |
503
3d6d548ad3cc
Added user action mapper to map push to changeset.
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
162 """ |
675
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
163 |
3577
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
164 ex = _extract_extras() |
2716
4c71667160e5
use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents:
2617
diff
changeset
|
165 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
166 action_tmpl = ex.action + ':%s' |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
167 revs = [] |
3577
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
168 if ex.scm == 'hg': |
2203
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
169 node = kwargs['node'] |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
170 |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
171 def get_revs(repo, rev_opt): |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
172 if rev_opt: |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
173 revs = revrange(repo, rev_opt) |
675
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
174 |
2203
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
175 if len(revs) == 0: |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
176 return (nullrev, nullrev) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
177 return max(revs), min(revs) |
2203
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
178 else: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
179 return len(repo) - 1, 0 |
675
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
180 |
2203
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2196
diff
changeset
|
181 stop, start = get_revs(repo, [node + ':']) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
182 _h = binascii.hexlify |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
183 revs = [_h(repo[r].node()) for r in xrange(start, stop + 1)] |
3577
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
184 elif ex.scm == 'git': |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
185 revs = kwargs.get('_git_revs', []) |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
186 if '_git_revs' in kwargs: |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
187 kwargs.pop('_git_revs') |
675
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
188 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
189 action = action_tmpl % ','.join(revs) |
3577
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
190 action_logger(ex.username, action, ex.repository, ex.ip, commit=True) |
675
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
191 |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
192 # extension hook call |
2406
7be31af5bc78
changed scope of calling EXTENSIONS from rhodecode for githooks to be able to execute them
Marcin Kuzminski <marcin@python-works.com>
parents:
2404
diff
changeset
|
193 from rhodecode import EXTENSIONS |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
194 callback = getattr(EXTENSIONS, 'PUSH_HOOK', None) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
195 if callable(callback): |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
196 kw = {'pushed_revs': revs} |
3577
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
197 kw.update(ex) |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
198 callback(**kw) |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
199 |
3672
55585c86be83
hooks: make_lock is tristate
Mads Kiilerich <madski@unity3d.com>
parents:
3625
diff
changeset
|
200 if ex.make_lock is not None and not ex.make_lock: |
3577
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
201 Repository.unlock(Repository.get_by_repo_name(ex.repository)) |
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
202 msg = 'Released lock on repo `%s`\n' % ex.repository |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
203 sys.stdout.write(msg) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
204 |
3577
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
205 if ex.locked_by[0]: |
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
206 locked_by = User.get(ex.locked_by[0]).username |
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3549
diff
changeset
|
207 _http_ret = HTTPLockedRC(ex.repository, locked_by) |
3522
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
208 if str(_http_ret.code).startswith('2'): |
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
209 #2xx Codes don't raise exceptions |
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
210 sys.stdout.write(_http_ret.title) |
7174ee850baa
configurable locking codes.
Marcin Kuzminski <marcin@python-works.com>
parents:
3478
diff
changeset
|
211 |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
212 return 0 |
1972
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
213 |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
214 |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
215 def log_create_repository(repository_dict, created_by, **kwargs): |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
216 """ |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
217 Post create repository Hook. This is a dummy function for admins to re-use |
2109 | 218 if needed. It's taken from rhodecode-extensions module and executed |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
219 if present |
1972
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
220 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1972
diff
changeset
|
221 :param repository: dict dump of repository object |
1972
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
222 :param created_by: username who created repository |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
223 |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
224 available keys of repository_dict: |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
225 |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
226 'repo_type', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
227 'description', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
228 'private', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
229 'created_on', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
230 'enable_downloads', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
231 'repo_id', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
232 'user_id', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
233 'enable_statistics', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
234 'clone_uri', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
235 'fork_id', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
236 'group_id', |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
237 'repo_name' |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
238 |
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
239 """ |
2406
7be31af5bc78
changed scope of calling EXTENSIONS from rhodecode for githooks to be able to execute them
Marcin Kuzminski <marcin@python-works.com>
parents:
2404
diff
changeset
|
240 from rhodecode import EXTENSIONS |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
241 callback = getattr(EXTENSIONS, 'CREATE_REPO_HOOK', None) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
242 if callable(callback): |
2105
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
243 kw = {} |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
244 kw.update(repository_dict) |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
245 kw.update({'created_by': created_by}) |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
246 kw.update(kwargs) |
926f55b038bc
added initial rc-extension module
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
247 return callback(**kw) |
1972
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
248 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1972
diff
changeset
|
249 return 0 |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
250 |
2904
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
251 |
4074
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
4017
diff
changeset
|
252 def check_allowed_create_user(user_dict, created_by, **kwargs): |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
253 # pre create hooks |
4074
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
4017
diff
changeset
|
254 from rhodecode import EXTENSIONS |
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
4017
diff
changeset
|
255 callback = getattr(EXTENSIONS, 'PRE_CREATE_USER_HOOK', None) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
256 if callable(callback): |
4074
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
4017
diff
changeset
|
257 allowed, reason = callback(created_by=created_by, **user_dict) |
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
4017
diff
changeset
|
258 if not allowed: |
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
4017
diff
changeset
|
259 raise UserCreationError(reason) |
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
4017
diff
changeset
|
260 |
3b136af34329
Added pre-create user hook.
Marcin Kuzminski <marcin@python-works.com>
parents:
4017
diff
changeset
|
261 |
4017
509923dac48d
Include the current user as a created_by/deleted_by attribute for USER_HOOK extensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
4016
diff
changeset
|
262 def log_create_user(user_dict, created_by, **kwargs): |
4016
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
263 """ |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
264 Post create user Hook. This is a dummy function for admins to re-use |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
265 if needed. It's taken from rhodecode-extensions module and executed |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
266 if present |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
267 |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
268 :param user_dict: dict dump of user object |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
269 |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
270 available keys for user_dict: |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
271 |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
272 'username', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
273 'full_name_or_username', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
274 'full_contact', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
275 'user_id', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
276 'name', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
277 'firstname', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
278 'short_contact', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
279 'admin', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
280 'lastname', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
281 'ip_addresses', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
282 'ldap_dn', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
283 'email', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
284 'api_key', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
285 'last_login', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
286 'full_name', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
287 'active', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
288 'password', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
289 'emails', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
290 'inherit_default_permissions' |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
291 |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
292 """ |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
293 from rhodecode import EXTENSIONS |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
294 callback = getattr(EXTENSIONS, 'CREATE_USER_HOOK', None) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
295 if callable(callback): |
4017
509923dac48d
Include the current user as a created_by/deleted_by attribute for USER_HOOK extensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
4016
diff
changeset
|
296 return callback(created_by=created_by, **user_dict) |
4016
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
297 |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
298 return 0 |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
299 |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
300 |
2904
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
301 def log_delete_repository(repository_dict, deleted_by, **kwargs): |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
302 """ |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
303 Post delete repository Hook. This is a dummy function for admins to re-use |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
304 if needed. It's taken from rhodecode-extensions module and executed |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
305 if present |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
306 |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
307 :param repository: dict dump of repository object |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
308 :param deleted_by: username who deleted the repository |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
309 |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
310 available keys of repository_dict: |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
311 |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
312 'repo_type', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
313 'description', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
314 'private', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
315 'created_on', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
316 'enable_downloads', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
317 'repo_id', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
318 'user_id', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
319 'enable_statistics', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
320 'clone_uri', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
321 'fork_id', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
322 'group_id', |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
323 'repo_name' |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
324 |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
325 """ |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
326 from rhodecode import EXTENSIONS |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
327 callback = getattr(EXTENSIONS, 'DELETE_REPO_HOOK', None) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
328 if callable(callback): |
2904
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
329 kw = {} |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
330 kw.update(repository_dict) |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
331 kw.update({'deleted_by': deleted_by, |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
332 'deleted_on': time.time()}) |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
333 kw.update(kwargs) |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
334 return callback(**kw) |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
335 |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
336 return 0 |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
337 |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2872
diff
changeset
|
338 |
4017
509923dac48d
Include the current user as a created_by/deleted_by attribute for USER_HOOK extensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
4016
diff
changeset
|
339 def log_delete_user(user_dict, deleted_by, **kwargs): |
4016
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
340 """ |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
341 Post delete user Hook. This is a dummy function for admins to re-use |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
342 if needed. It's taken from rhodecode-extensions module and executed |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
343 if present |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
344 |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
345 :param user_dict: dict dump of user object |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
346 |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
347 available keys for user_dict: |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
348 |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
349 'username', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
350 'full_name_or_username', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
351 'full_contact', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
352 'user_id', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
353 'name', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
354 'firstname', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
355 'short_contact', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
356 'admin', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
357 'lastname', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
358 'ip_addresses', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
359 'ldap_dn', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
360 'email', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
361 'api_key', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
362 'last_login', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
363 'full_name', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
364 'active', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
365 'password', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
366 'emails', |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
367 'inherit_default_permissions' |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
368 |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
369 """ |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
370 from rhodecode import EXTENSIONS |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
371 callback = getattr(EXTENSIONS, 'DELETE_USER_HOOK', None) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
372 if callable(callback): |
4017
509923dac48d
Include the current user as a created_by/deleted_by attribute for USER_HOOK extensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
4016
diff
changeset
|
373 return callback(deleted_by=deleted_by, **user_dict) |
4016
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
374 |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
375 return 0 |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
376 |
cce2d984b001
User create/delete hooks for rcextensions.
Jonathan Sternberg <jonathansternberg@gmail.com>
parents:
3960
diff
changeset
|
377 |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
378 handle_git_pre_receive = (lambda repo_path, revs, env: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
379 handle_git_receive(repo_path, revs, env, hook_type='pre')) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
380 handle_git_post_receive = (lambda repo_path, revs, env: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
381 handle_git_receive(repo_path, revs, env, hook_type='post')) |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
382 |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
383 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
384 def handle_git_receive(repo_path, revs, env, hook_type='post'): |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
385 """ |
2407
8a68e0292232
Change git & hg hooks to post. They shouldn't block as they are used just for logging actions. Futhermore post hooks have access to changesets, so it's much better flexible
Marcin Kuzminski <marcin@python-works.com>
parents:
2406
diff
changeset
|
386 A really hacky method that is runned by git post-receive hook and logs |
2409
761e00380370
whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2408
diff
changeset
|
387 an push action together with pushed revisions. It's executed by subprocess |
761e00380370
whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2408
diff
changeset
|
388 thus needs all info to be able to create a on the fly pylons enviroment, |
761e00380370
whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2408
diff
changeset
|
389 connect to database and run the logging code. Hacky as sh*t but works. |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
390 |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
391 :param repo_path: |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
392 :param revs: |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
393 :param env: |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
394 """ |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
395 from paste.deploy import appconfig |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
396 from sqlalchemy import engine_from_config |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
397 from rhodecode.config.environment import load_environment |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
398 from rhodecode.model import init_model |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
399 from rhodecode.model.db import RhodeCodeUi |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
400 from rhodecode.lib.utils import make_ui |
3590
47631be9f449
fix GIT env extraction
Marcin Kuzminski <marcin@python-works.com>
parents:
3589
diff
changeset
|
401 extras = _extract_extras(env) |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
402 |
2870
cbf0775ff6b4
There's no need to use special env variable for config file, it's already passed in in extras now
Marcin Kuzminski <marcin@python-works.com>
parents:
2818
diff
changeset
|
403 path, ini_name = os.path.split(extras['config']) |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
404 conf = appconfig('config:%s' % ini_name, relative_to=path) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
405 load_environment(conf.global_conf, conf.local_conf, test_env=False, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
406 test_index=False) |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
407 |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
408 engine = engine_from_config(conf, 'sqlalchemy.db1.') |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
409 init_model(engine) |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
410 |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
411 baseui = make_ui('db') |
2617
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
412 # fix if it's not a bare repo |
2872
17556a81ec6f
Make detecting bare Git repositories more robust
Stefan Engel <mail@engel-stefan.de>
parents:
2870
diff
changeset
|
413 if repo_path.endswith(os.sep + '.git'): |
17556a81ec6f
Make detecting bare Git repositories more robust
Stefan Engel <mail@engel-stefan.de>
parents:
2870
diff
changeset
|
414 repo_path = repo_path[:-5] |
2818
3d0bd5f71dab
raise na OSERROR if repository data sent from git hook to hook handler is somehow invalid
Marcin Kuzminski <marcin@python-works.com>
parents:
2750
diff
changeset
|
415 |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
416 repo = Repository.get_by_full_path(repo_path) |
2818
3d0bd5f71dab
raise na OSERROR if repository data sent from git hook to hook handler is somehow invalid
Marcin Kuzminski <marcin@python-works.com>
parents:
2750
diff
changeset
|
417 if not repo: |
3d0bd5f71dab
raise na OSERROR if repository data sent from git hook to hook handler is somehow invalid
Marcin Kuzminski <marcin@python-works.com>
parents:
2750
diff
changeset
|
418 raise OSError('Repository %s not found in database' |
3d0bd5f71dab
raise na OSERROR if repository data sent from git hook to hook handler is somehow invalid
Marcin Kuzminski <marcin@python-works.com>
parents:
2750
diff
changeset
|
419 % (safe_str(repo_path))) |
3d0bd5f71dab
raise na OSERROR if repository data sent from git hook to hook handler is somehow invalid
Marcin Kuzminski <marcin@python-works.com>
parents:
2750
diff
changeset
|
420 |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
421 _hooks = dict(baseui.configitems('hooks')) or {} |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
422 |
3278
c2bf0fa7b3cb
git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents:
3097
diff
changeset
|
423 if hook_type == 'pre': |
c2bf0fa7b3cb
git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents:
3097
diff
changeset
|
424 repo = repo.scm_instance |
c2bf0fa7b3cb
git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents:
3097
diff
changeset
|
425 else: |
c2bf0fa7b3cb
git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents:
3097
diff
changeset
|
426 #post push shouldn't use the cached instance never |
3549
e4a4006faceb
no_cache version of scm is now a function
Marcin Kuzminski <marcin@python-works.com>
parents:
3522
diff
changeset
|
427 repo = repo.scm_instance_no_cache() |
3278
c2bf0fa7b3cb
git hook handler shouldn't ever use cache instances
Marcin Kuzminski <marcin@python-works.com>
parents:
3097
diff
changeset
|
428 |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
429 if hook_type == 'pre': |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
430 pre_push(baseui, repo) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
431 |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
432 # if push hook is enabled via web interface |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
433 elif hook_type == 'post' and _hooks.get(RhodeCodeUi.HOOK_PUSH): |
2617
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
434 rev_data = [] |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
435 for l in revs: |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
436 old_rev, new_rev, ref = l.split(' ') |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
437 _ref_data = ref.split('/') |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
438 if _ref_data[1] in ['tags', 'heads']: |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
439 rev_data.append({'old_rev': old_rev, |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
440 'new_rev': new_rev, |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
441 'ref': ref, |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
442 'type': _ref_data[1], |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
443 'name': _ref_data[2].strip()}) |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
444 |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
445 git_revs = [] |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
446 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
447 for push_ref in rev_data: |
2617
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
448 _type = push_ref['type'] |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
449 if _type == 'heads': |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
450 if push_ref['old_rev'] == EmptyChangeset().raw_id: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
451 # update the symbolic ref if we push new repo |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
452 if repo.is_empty(): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
453 repo._repo.refs.set_symbolic_ref('HEAD', |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
454 'refs/heads/%s' % push_ref['name']) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4074
diff
changeset
|
455 |
2617
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
456 cmd = "for-each-ref --format='%(refname)' 'refs/heads/*'" |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
457 heads = repo.run_git_command(cmd)[0] |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
458 heads = heads.replace(push_ref['ref'], '') |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
459 heads = ' '.join(map(lambda c: c.strip('\n').strip(), |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
460 heads.splitlines())) |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
461 cmd = (('log %(new_rev)s' % push_ref) + |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
462 ' --reverse --pretty=format:"%H" --not ' + heads) |
2998
433428ffd13b
fixes #645 Fix git handler when doing delete remote branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2963
diff
changeset
|
463 git_revs += repo.run_git_command(cmd)[0].splitlines() |
433428ffd13b
fixes #645 Fix git handler when doing delete remote branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2963
diff
changeset
|
464 |
433428ffd13b
fixes #645 Fix git handler when doing delete remote branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2963
diff
changeset
|
465 elif push_ref['new_rev'] == EmptyChangeset().raw_id: |
433428ffd13b
fixes #645 Fix git handler when doing delete remote branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2963
diff
changeset
|
466 #delete branch case |
433428ffd13b
fixes #645 Fix git handler when doing delete remote branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2963
diff
changeset
|
467 git_revs += ['delete_branch=>%s' % push_ref['name']] |
2617
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
468 else: |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
469 cmd = (('log %(old_rev)s..%(new_rev)s' % push_ref) + |
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
470 ' --reverse --pretty=format:"%H"') |
2998
433428ffd13b
fixes #645 Fix git handler when doing delete remote branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2963
diff
changeset
|
471 git_revs += repo.run_git_command(cmd)[0].splitlines() |
433428ffd13b
fixes #645 Fix git handler when doing delete remote branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2963
diff
changeset
|
472 |
2617
c0ec29b20eb6
Fixed githooks for fetching multiple tags and branches.
Marcin Kuzminski <marcin@python-works.com>
parents:
2525
diff
changeset
|
473 elif _type == 'tags': |
2998
433428ffd13b
fixes #645 Fix git handler when doing delete remote branch
Marcin Kuzminski <marcin@python-works.com>
parents:
2963
diff
changeset
|
474 git_revs += ['tag=>%s' % push_ref['name']] |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
475 |
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2324
diff
changeset
|
476 log_push_action(baseui, repo, _git_revs=git_revs) |