forked from readthedocs/readthedocs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
automation_actions.py
79 lines (58 loc) · 2.13 KB
/
automation_actions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
Actions used for the automation rules.
Each function will receive the following args:
- version: The version object where the action will be applied
- match_result: The result from the match option
- action_arg: An additional argument to apply the action
"""
import logging
from readthedocs.core.utils import trigger_build
from readthedocs.projects.constants import PRIVATE, PUBLIC
log = logging.getLogger(__name__)
def activate_version(version, match_result, action_arg, *args, **kwargs):
"""
Sets version as active.
It triggers a build if the version isn't built.
"""
version.active = True
version.save()
if not version.built:
trigger_build(
project=version.project,
version=version
)
def set_default_version(version, match_result, action_arg, *args, **kwargs):
"""
Sets version as the project's default version.
The version is activated first.
"""
activate_version(version, match_result, action_arg)
project = version.project
project.default_version = version.slug
project.save()
def hide_version(version, match_result, action_arg, *args, **kwargs):
"""
Sets version as hidden.
It also activates the version and triggers a build.
"""
version.hidden = True
version.save()
if not version.active:
activate_version(version, match_result, action_arg)
def set_public_privacy_level(version, match_result, action_arg, *args, **kwargs):
"""Sets the privacy_level of the version to public."""
version.privacy_level = PUBLIC
version.save()
def set_private_privacy_level(version, match_result, action_arg, *args, **kwargs):
"""Sets the privacy_level of the version to private."""
version.privacy_level = PRIVATE
version.save()
def delete_version(version, match_result, action_arg, *args, **kwargs):
"""Delete a version if isn't marked as the default version."""
if version.project.default_version == version.slug:
log.info(
"Skipping deleting default version. project=%s version=%s",
version.project.slug, version.slug,
)
return
version.delete()