Skip to content

Commit

Permalink
Addons: add a notification on each Sphinx build (#11514)
Browse files Browse the repository at this point in the history
* Addons: add a notification on each Sphinx build

Temporary notification added to all builds using Sphinx to build their docs.
This code should be removed after October 7th, when this behavior becomes the
default.

I'm not sure if this is the direction we want to go or not, but I think we want
to communicate this as much as possible.

* Render notification's header on build detail page

* Update tests
  • Loading branch information
humitos authored Aug 7, 2024
1 parent 05cd870 commit 0d1f5f5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
15 changes: 15 additions & 0 deletions readthedocs/projects/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
)

MESSAGE_PROJECT_SKIP_BUILDS = "project:invalid:skip-builds"
MESSAGE_PROJECT_ADDONS_BY_DEFAULT = "project:addons:by-default"
messages = [
Message(
id=MESSAGE_PROJECT_SKIP_BUILDS,
Expand Down Expand Up @@ -145,5 +146,19 @@
),
type=WARNING,
),
# Temporary notification until October 7th.
Message(
id=MESSAGE_PROJECT_ADDONS_BY_DEFAULT,
header=_("""Read the Docs Addons will be enabled by default on October 7th"""),
body=_(
textwrap.dedent(
"""
Read the <a href="https://about.readthedocs.com/blog/2024/07/addons-by-default/" target="_blank">full announcement in our blog</a>
to know if your project will be affected and how to update.
"""
).strip(),
),
type=INFO,
),
]
registry.add(messages)
7 changes: 7 additions & 0 deletions readthedocs/projects/tasks/builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
MkDocsYAMLParseError,
)
from readthedocs.projects.models import Feature
from readthedocs.projects.notifications import MESSAGE_PROJECT_ADDONS_BY_DEFAULT
from readthedocs.storage import build_media_storage
from readthedocs.telemetry.collectors import BuildDataCollector
from readthedocs.telemetry.tasks import save_build_data
Expand Down Expand Up @@ -819,6 +820,12 @@ def execute(self):
self.update_build(state=BUILD_STATE_BUILDING)
self.data.build_director.run_build_commands()
else:
# Temporal notification while we migrate to addons enabled by default.
if self.data.build_director.is_type_sphinx():
self.data.build_director.attach_notification(
MESSAGE_PROJECT_ADDONS_BY_DEFAULT
)

# Installing
self.update_build(state=BUILD_STATE_INSTALLING)
self.data.build_director.setup_environment()
Expand Down
29 changes: 17 additions & 12 deletions readthedocs/projects/tests/test_build_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,11 @@ def test_successful_build(
"builder": mock.ANY,
}

# NOTE: `request_history[5]` is a temporal notification that will be removed after October 7th
# https://github.com/readthedocs/readthedocs.org/pull/11514

# Update build state: installing
assert self.requests_mock.request_history[5].json() == {
assert self.requests_mock.request_history[6].json() == {
"id": 1,
"state": "installing",
"commit": "a1b2c3",
Expand Down Expand Up @@ -599,7 +602,7 @@ def test_successful_build(
},
}
# Update build state: building
assert self.requests_mock.request_history[6].json() == {
assert self.requests_mock.request_history[7].json() == {
"id": 1,
"state": "building",
"commit": "a1b2c3",
Expand All @@ -609,7 +612,7 @@ def test_successful_build(
"error": "",
}
# Update build state: uploading
assert self.requests_mock.request_history[7].json() == {
assert self.requests_mock.request_history[8].json() == {
"id": 1,
"state": "uploading",
"commit": "a1b2c3",
Expand All @@ -619,9 +622,9 @@ def test_successful_build(
"error": "",
}
# Update version state
assert self.requests_mock.request_history[8]._request.method == "PATCH"
assert self.requests_mock.request_history[8].path == "/api/v2/version/1/"
assert self.requests_mock.request_history[8].json() == {
assert self.requests_mock.request_history[9]._request.method == "PATCH"
assert self.requests_mock.request_history[9].path == "/api/v2/version/1/"
assert self.requests_mock.request_history[9].json() == {
"addons": False,
"build_data": None,
"built": True,
Expand All @@ -631,11 +634,13 @@ def test_successful_build(
"has_htmlzip": True,
}
# Set project has valid clone
assert self.requests_mock.request_history[9]._request.method == "PATCH"
assert self.requests_mock.request_history[9].path == "/api/v2/project/1/"
assert self.requests_mock.request_history[9].json() == {"has_valid_clone": True}
# Update build state: finished, success and builder
assert self.requests_mock.request_history[10]._request.method == "PATCH"
assert self.requests_mock.request_history[10].path == "/api/v2/project/1/"
assert self.requests_mock.request_history[10].json() == {
"has_valid_clone": True
}
# Update build state: finished, success and builder
assert self.requests_mock.request_history[11].json() == {
"id": 1,
"state": "finished",
"commit": "a1b2c3",
Expand All @@ -647,8 +652,8 @@ def test_successful_build(
"error": "",
}

assert self.requests_mock.request_history[11]._request.method == "POST"
assert self.requests_mock.request_history[11].path == "/api/v2/revoke/"
assert self.requests_mock.request_history[12]._request.method == "POST"
assert self.requests_mock.request_history[12].path == "/api/v2/revoke/"

assert BuildData.objects.all().exists()

Expand Down
2 changes: 1 addition & 1 deletion readthedocs/templates/builds/build_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
{% for notification in notifications %}
{% if notification.get_message.type != "error" %}
<p class="build-ideas">
{{ notification.get_message.get_rendered_body|safe }}
<strong>{{ notification.get_message.get_rendered_header|safe }}</strong>{{ notification.get_message.get_rendered_body|safe }}
</p>
{% endif %}
{% endfor %}
Expand Down

0 comments on commit 0d1f5f5

Please sign in to comment.