-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathautomation_actions.py
More file actions
84 lines (60 loc) · 2.11 KB
/
automation_actions.py
File metadata and controls
84 lines (60 loc) · 2.11 KB
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
80
81
82
83
84
"""
Actions used for the automation rules.
Each function will receive the following args:
- version: The version object where the action will be applied
- action_arg: An additional argument to apply the action
"""
import structlog
from readthedocs.core.utils import trigger_build
from readthedocs.projects.constants import PRIVATE
from readthedocs.projects.constants import PUBLIC
log = structlog.get_logger(__name__)
def trigger_build_for_version(version, *args, **kwargs):
"""Trigger a build for this version."""
if version.active:
trigger_build(project=version.project, version=version, from_webhook=True)
def activate_version(version, *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, *args, **kwargs):
"""
Sets version as the project's default version.
The version is activated first.
"""
activate_version(version)
project = version.project
project.default_version = version.slug
project.save()
def hide_version(version, *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)
def set_public_privacy_level(version, *args, **kwargs):
"""Sets the privacy_level of the version to public."""
version.privacy_level = PUBLIC
version.save()
def set_private_privacy_level(version, *args, **kwargs):
"""Sets the privacy_level of the version to private."""
version.privacy_level = PRIVATE
version.save()
def delete_version(version, *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_slug=version.project.slug,
version_slug=version.slug,
)
return
version.delete()