Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion libraries/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,12 @@
# List of versions for which we know docs are missing
VERSION_DOCS_MISSING = ["boost-1.33.0"]

# File paths where library description content might be stored, in priority order.
DESCRIPTION_FILES = ["doc/library-detail.adoc", "README.md", "README.adoc"]

# This constant is for library-versions missing a README
README_MISSING = (
"⚠️ This library has no README.md or library-details.adoc; "
"⚠️ This library has no README file or library-detail.adoc; "
"consider contributing one."
)

Expand Down
9 changes: 4 additions & 5 deletions libraries/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from libraries.managers import IssueManager
from mailing_list.models import EmailData
from versions.models import ReportConfiguration
from .constants import LIBRARY_GITHUB_URL_OVERRIDES
from .constants import DESCRIPTION_FILES, LIBRARY_GITHUB_URL_OVERRIDES

from .utils import (
generate_random_string,
Expand Down Expand Up @@ -335,13 +335,12 @@ def save(self, *args, **kwargs):
def get_description(self, client, tag="develop"):
"""Get description from the appropriate file on GitHub.

For more recent versions, that will be `/doc/library-details.adoc`.
For more recent versions, that will be `/doc/library-detail.adoc`.
For older versions, or libraries that have not adopted the adoc file,
that will be `/README.md`.
that will be `/README.md` or `/README.adoc`.
"""
content = None
# File paths/names where description data might be stored.
files = ["doc/library-detail.adoc", "README.md"]
files = DESCRIPTION_FILES

# Try to get the content from the cache first
static_content_cache = caches["static_content"]
Expand Down
34 changes: 34 additions & 0 deletions libraries/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import datetime
from unittest.mock import MagicMock, patch

import pytest
from django.core.cache import caches
from django.db.models import Sum
from model_bakery import baker

from core.models import RenderedContent
from libraries.constants import DESCRIPTION_FILES
from libraries.models import CommitAuthor
from mailing_list.models import EmailData

Expand Down Expand Up @@ -140,6 +146,34 @@ def test_library_version_first_boost_version_property(library):
assert library.first_boost_version == version_3


@pytest.mark.parametrize(
"first_available, expected",
[(0, "<p>adoc</p>"), (1, "<p>md</p>"), (2, "<p>adoc</p>"), (None, None)],
ids=["library-detail.adoc", "README.md-fallback", "README.adoc-fallback", "none"],
)
@patch("libraries.models.process_md", return_value=("", "<p>md</p>"))
@patch("libraries.models.write_content_to_tempfile")
@patch("libraries.models.convert_adoc_to_html", return_value="<p>adoc</p>")
def test_get_description_file_priority(
_adoc, mock_tempfile, _md, library, first_available, expected
):
"""Files are tried in order; the first available file wins."""
caches["static_content"].clear()
RenderedContent.objects.all().delete()
mock_tempfile.return_value.name = "/tmp/fake"

available = dict.fromkeys(DESCRIPTION_FILES)
if first_available is not None:
for f in DESCRIPTION_FILES[first_available:]:
available[f] = b"content"

client = MagicMock()
client.get_file_content.side_effect = (
lambda repo_slug, tag, file_path: available.get(file_path)
)
assert library.get_description(client) == expected


def test_merge_author_deletes_author():
author_1_email = baker.make("libraries.CommitAuthorEmail")
author_1 = author_1_email.author
Expand Down
Loading