Skip to content

Commit

Permalink
Merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Haddon committed Jan 19, 2024
2 parents 9e1e164 + 24675f6 commit 90a9a5a
Show file tree
Hide file tree
Showing 64 changed files with 162 additions and 81 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
- Added a formatted representation of the UpdatePageAction dataclass for more
human-readable output.

## [v0.8.1] - 2024-01-18

### Fixed

- Migration error where discourse is in-line with the default branch but the
base content tag is behind. This no longer attempts migration and now also
moves the tag to the latest commit on the default branch.

## [v0.8.0] - 2023-11-30

### Added
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
FROM python:3.11-slim

Expand Down
2 changes: 1 addition & 1 deletion action.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
name: Upload Charm Docs
description: Upload charm documentation to charmhub
Expand Down
2 changes: 1 addition & 1 deletion generate-src-docs.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

rm -rf src-docs
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Main execution for the action."""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

[tool.bandit]
Expand Down
2 changes: 1 addition & 1 deletion src-docs/__init__.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Migrate existing docs from charmhub to local repository.

---

<a href="../src/__init__.py#L251"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/__init__.py#L259"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `pre_flight_checks`

Expand Down
18 changes: 13 additions & 5 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Library for uploading docs to charmhub."""
Expand Down Expand Up @@ -133,7 +133,7 @@ def run_reconcile(clients: Clients, user_inputs: UserInputs) -> ReconcileOutputs
index_url=index.server.url if index.server else "",
topics=(
{
f"{clients.discourse.absolute_url(row.navlink.link)}": ActionResult.SKIP
clients.discourse.absolute_url(row.navlink.link): ActionResult.SKIP
for row in table_rows
if row.navlink.link
}
Expand Down Expand Up @@ -221,11 +221,19 @@ def run_migrate(clients: Clients, user_inputs: UserInputs) -> MigrateOutputs | N

# Check difference with main
changes = recreate_docs(clients, DOCUMENTATION_TAG)
# Check whether there are still changes after switching to the base branch
if changes:
changes = clients.repository.is_dirty(user_inputs.base_branch)

# Move the tag if there are no changes
if not changes:
with clients.repository.with_branch(user_inputs.base_branch) as repo:
main_hash = repo.current_commit
clients.repository.tag_commit(DOCUMENTATION_TAG, main_hash)

if not changes:
logging.info(
"No community contribution found in commit %s. Discourse is inline with %s",
user_inputs.commit_sha,
DOCUMENTATION_TAG,
"No community contribution found, discourse is inline with %s", DOCUMENTATION_TAG
)
# Given there are NO diffs compared to the base, if a PR is open, it should be closed
if pull_request is not None:
Expand Down
2 changes: 1 addition & 1 deletion src/action.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Module for taking the required actions to match the server state with the local state."""
Expand Down
2 changes: 1 addition & 1 deletion src/check.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Module for running checks."""
Expand Down
2 changes: 1 addition & 1 deletion src/clients.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Module for Client class."""
Expand Down
2 changes: 1 addition & 1 deletion src/commit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Module for handling interactions with git commit."""
Expand Down
2 changes: 1 addition & 1 deletion src/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Shared constants.
Expand Down
2 changes: 1 addition & 1 deletion src/content.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Module for checking conflicts using 3-way merge and create content based on a 3 way merge."""
Expand Down
2 changes: 1 addition & 1 deletion src/discourse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Interface for Discourse interactions."""
Expand Down
2 changes: 1 addition & 1 deletion src/docs_directory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Class for reading the docs directory."""
Expand Down
2 changes: 1 addition & 1 deletion src/download.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Library for downloading docs folder from charmhub."""
Expand Down
2 changes: 1 addition & 1 deletion src/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Exceptions for uploading docs to charmhub."""
Expand Down
2 changes: 1 addition & 1 deletion src/index.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Execute the uploading of documentation."""
Expand Down
2 changes: 1 addition & 1 deletion src/metadata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Module for parsing metadata.yaml file."""
Expand Down
2 changes: 1 addition & 1 deletion src/migration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Module for migrating remote documentation into local git repository."""
Expand Down
2 changes: 1 addition & 1 deletion src/navigation_table.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Module for parsing and rendering a navigation table."""
Expand Down
2 changes: 1 addition & 1 deletion src/reconcile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Module for calculating required changes based on docs directory and navigation table."""
Expand Down
2 changes: 1 addition & 1 deletion src/repository.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Module for handling interactions with git repository."""
Expand Down
2 changes: 1 addition & 1 deletion src/sort.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Sort items for publishing."""
Expand Down
2 changes: 1 addition & 1 deletion src/types_.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Types for uploading docs to charmhub."""
Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Tests for uploading docs to charmhub."""
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Fixtures for all tests."""
Expand Down
4 changes: 2 additions & 2 deletions tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Factories for generating test data."""
Expand Down Expand Up @@ -337,7 +337,7 @@ class Meta:
abstract = False

hostname = factory.Sequence(lambda n: f"discourse/{n}")
category_id = factory.Sequence(lambda n: f"{n}")
category_id = factory.Sequence(str)
api_username = factory.Sequence(lambda n: f"discourse-test-user-{n}")
api_key = factory.Sequence(lambda n: f"discourse-test-key-{n}")

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Unit tests for uploading docs to charmhub."""
2 changes: 1 addition & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Fixtures for integration tests."""
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test___init__run_conflict.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Integration tests for running the action where there is a merge conflict."""
Expand Down Expand Up @@ -77,7 +77,7 @@ async def test_run_conflict(
caplog.clear()
index_url = discourse_api.create_topic(
title=f"{document_name.replace('-', ' ').title()} Documentation Overview",
content=f"{constants.NAVIGATION_TABLE_START}".strip(),
content=constants.NAVIGATION_TABLE_START.strip(),
)
create_metadata_yaml(
content=f"{metadata.METADATA_NAME_KEY}: name 1\n{metadata.METADATA_DOCS_KEY}: {index_url}",
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test___init__run_migrate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Integration tests for running the migrate action."""
Expand Down Expand Up @@ -246,8 +246,8 @@ def mock_edit(*args, **kwargs): # pylint: disable=W0613
assert output_migrate.action == PullRequestAction.CLOSED
assert_substrings_in_string(
[
"No community contribution found in commit",
f"Discourse is inline with {DOCUMENTATION_TAG}",
"No community contribution found",
f"discourse is inline with {DOCUMENTATION_TAG}",
],
caplog.text,
)
10 changes: 5 additions & 5 deletions tests/integration/test___init__run_reconcile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Integration tests for running the reconcile portion of the action."""
Expand Down Expand Up @@ -89,7 +89,7 @@ async def test_run(
caplog.clear()
index_url = discourse_api.create_topic(
title=f"{document_name.replace('-', ' ').title()} Documentation Overview",
content=f"{constants.NAVIGATION_TABLE_START}".strip(),
content=constants.NAVIGATION_TABLE_START.strip(),
)
create_metadata_yaml(
content=f"{metadata.METADATA_NAME_KEY}: name 1\n{metadata.METADATA_DOCS_KEY}: {index_url}",
Expand All @@ -114,7 +114,7 @@ async def test_run(
assert output_reconcile is not None
assert output_reconcile.index_url == index_url
index_topic = discourse_api.retrieve_topic(url=index_url)
assert index_topic == f"{constants.NAVIGATION_TABLE_START}".strip()
assert index_topic == constants.NAVIGATION_TABLE_START.strip()
assert_substrings_in_string((index_url, "Update", "'skip'"), caplog.text)
mock_github_repo.create_git_ref.assert_not_called()

Expand Down Expand Up @@ -508,7 +508,7 @@ async def test_run_hidden(
caplog.clear()
index_url = discourse_api.create_topic(
title=f"{document_name.replace('-', ' ').title()} Documentation Overview",
content=f"{constants.NAVIGATION_TABLE_START}".strip(),
content=constants.NAVIGATION_TABLE_START.strip(),
)
create_metadata_yaml(
content=f"{metadata.METADATA_NAME_KEY}: name 1\n{metadata.METADATA_DOCS_KEY}: {index_url}",
Expand Down Expand Up @@ -747,7 +747,7 @@ async def test_run_external(
caplog.clear()
index_url = discourse_api.create_topic(
title=f"{document_name.replace('-', ' ').title()} Documentation Overview",
content=f"{constants.NAVIGATION_TABLE_START}".strip(),
content=constants.NAVIGATION_TABLE_START.strip(),
)
create_metadata_yaml(
content=f"{metadata.METADATA_NAME_KEY}: name 1\n{metadata.METADATA_DOCS_KEY}: {index_url}",
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_discourse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Integration tests for discourse."""
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Useful types for integration tests."""
Expand Down
2 changes: 1 addition & 1 deletion tests/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Useful types for tests."""
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Unit tests for uploading docs to charmhub."""
2 changes: 1 addition & 1 deletion tests/unit/action/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Unit tests for actions."""
2 changes: 1 addition & 1 deletion tests/unit/action/test_other_actions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Unit tests for action."""
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/action/test_update_action.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Unit tests for action."""
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Fixtures for all unit tests."""
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Helper functions for tests."""
Expand Down
Loading

0 comments on commit 90a9a5a

Please sign in to comment.