Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colorize "extended support" column and re-order date columns #191

Merged
merged 6 commits into from
Jan 24, 2024
Merged
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
13 changes: 8 additions & 5 deletions src/norwegianblue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ def _colourify(data: list[dict], *, is_html: bool = False) -> list[dict]:
six_months_from_now = now + relativedelta(months=+6)

for cycle in data:
for property_ in ("support", "eol", "discontinued"):
for property_ in ("discontinued", "support", "eol", "extendedSupport"):
if property_ not in cycle:
continue

# Handle Boolean
if isinstance(cycle[property_], bool):
if property_ == "support":
colour = "green" if cycle["support"] else "red"
else: # "eol" and "discontinued"
if property_ in ("support", "extendedSupport"):
colour = "green" if cycle[property_] else "red"
else: # "discontinued" or "eol"
colour = "red" if cycle[property_] else "green"

cycle[property_] = _apply_colour(
Expand Down Expand Up @@ -184,6 +184,8 @@ def _tabulate(
row["release"] = row.pop("releaseDate")
if "latestReleaseDate" in row:
row["latest release"] = row.pop("latestReleaseDate")
if "extendedSupport" in row:
row["extended support"] = row.pop("extendedSupport")

headers = sorted(set().union(*(d.keys() for d in data)))

Expand All @@ -200,9 +202,10 @@ def _tabulate(
"release",
"latest",
"latest release",
"support",
"discontinued",
"support",
"eol",
"extended support",
):
if preferred in headers:
new_headers.append(preferred)
Expand Down
11 changes: 11 additions & 0 deletions tests/data/expected_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,14 @@
| 3.3 | 2012-09-29 | 3.3.7 | 2017-09-19 | 2017-09-29 |
| 2.7 | 2010-07-03 | 2.7.18 | 2020-04-19 | 2020-01-01 |
"""

EXPECTED_MD_RHEL = """
| cycle | release | latest | latest release | support | eol | extended support |
|:------|:----------:|:-------|:--------------:|:----------:|:----------:|:----------------:|
| 9 LTS | 2022-05-17 | 9.3 | 2023-11-07 | 2027-05-31 | 2032-05-31 | 2035-05-31 |
| 8 LTS | 2019-05-07 | 8.9 | 2023-11-14 | 2024-05-31 | 2029-05-31 | 2032-05-31 |
| 7 LTS | 2013-12-11 | 7.9 | 2020-09-29 | 2019-08-06 | 2024-06-30 | 2028-06-30 |
| 6 LTS | 2010-11-09 | 6.10 | 2018-06-19 | 2016-05-10 | 2020-11-30 | 2024-06-30 |
| 5 LTS | 2007-03-15 | 5.11 | 2014-09-16 | 2013-01-08 | 2017-03-31 | 2020-11-30 |
| 4 | 2005-02-15 | 4.9 | 2011-02-16 | 2009-03-31 | 2012-02-29 | 2017-03-31 |
""" # noqa: E501
65 changes: 65 additions & 0 deletions tests/data/sample_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,71 @@
]
"""

SAMPLE_RESPONSE_JSON_RHEL = """
[
{
"cycle": "9",
"releaseDate": "2022-05-17",
"support": "2027-05-31",
"eol": "2032-05-31",
"lts": "2032-05-31",
"extendedSupport": "2035-05-31",
"latest": "9.3",
"latestReleaseDate": "2023-11-07"
},
{
"cycle": "8",
"releaseDate": "2019-05-07",
"support": "2024-05-31",
"eol": "2029-05-31",
"lts": "2029-05-31",
"extendedSupport": "2032-05-31",
"latest": "8.9",
"latestReleaseDate": "2023-11-14"
},
{
"cycle": "7",
"releaseDate": "2013-12-11",
"support": "2019-08-06",
"eol": "2024-06-30",
"lts": "2024-06-30",
"extendedSupport": "2028-06-30",
"latest": "7.9",
"latestReleaseDate": "2020-09-29"
},
{
"cycle": "6",
"releaseDate": "2010-11-09",
"support": "2016-05-10",
"eol": "2020-11-30",
"lts": "2020-11-30",
"extendedSupport": "2024-06-30",
"latest": "6.10",
"latestReleaseDate": "2018-06-19"
},
{
"cycle": "5",
"releaseDate": "2007-03-15",
"support": "2013-01-08",
"eol": "2017-03-31",
"lts": "2017-03-31",
"extendedSupport": "2020-11-30",
"latest": "5.11",
"latestReleaseDate": "2014-09-16"
},
{
"cycle": "4",
"releaseDate": "2005-02-15",
"support": "2009-03-31",
"eol": "2012-02-29",
"extendedSupport": "2017-03-31",
"latest": "4.9",
"latestReleaseDate": "2011-02-16",
"lts": false
}
]
"""

SAMPLE_RESPONSE_JSON_UBUNTU = """
[
{
Expand Down
5 changes: 5 additions & 0 deletions tests/test_norwegianblue.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
EXPECTED_MD_COLOUR,
EXPECTED_MD_LOG4J,
EXPECTED_MD_PYTHON,
EXPECTED_MD_RHEL,
EXPECTED_PRETTY,
EXPECTED_PRETTY_WITH_TITLE,
EXPECTED_RST,
Expand All @@ -32,6 +33,7 @@
SAMPLE_RESPONSE_ALL_JSON,
SAMPLE_RESPONSE_JSON_LOG4J,
SAMPLE_RESPONSE_JSON_PYTHON,
SAMPLE_RESPONSE_JSON_RHEL,
SAMPLE_RESPONSE_JSON_UBUNTU,
)

Expand Down Expand Up @@ -110,6 +112,9 @@ def test_norwegianblue_formats(
pytest.param(
"python", SAMPLE_RESPONSE_JSON_PYTHON, EXPECTED_MD_PYTHON, id="python"
),
pytest.param(
"rhel", SAMPLE_RESPONSE_JSON_RHEL, EXPECTED_MD_RHEL, id="rhel"
),
],
)
def test_norwegianblue_products(
Expand Down
Loading