Skip to content

Commit

Permalink
Merge branch 'main' into renovate/pygithub-2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
arturo-seijas authored May 27, 2024
2 parents 9e85329 + bf37156 commit 7718554
Show file tree
Hide file tree
Showing 78 changed files with 911 additions and 440 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
!/main.py
!/requirements.txt
!/src
!/pyproject.toml
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
# Changelog

## [Unreleased]
## Unreleased

- Project prepared to be installed with `pip install`, so it can be reused in
the repository https://github.com/canonical/gatekeeper-repo-test

## [v0.9.0] - 2024-04-04

### Added

- Added a formatted representation of the UpdatePageAction dataclass for more
human-readable output.
- To address a race condition between the conflict check and when content is
updated on discourse, the action now checks that the content hasn't changed
since the conflict check was completed, before pushing updates to discourse.
- If metadata.yaml does not exist, read the name and doc information from the
charmcraft.yaml file.
- New input environment variable INPUT_CHARM_DIR. metadata.yaml or charmcraft.yaml
will be read from this directory instead of the base one and the documentation
will also be searched under this directory.

## [v0.8.2] - 2024-02-16

Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ RUN apt-get update && \

RUN mkdir /usr/src/app
WORKDIR /usr/src/app
COPY requirements.txt /usr/src/app
RUN pip install --no-cache-dir -r requirements.txt

COPY . /usr/src/app
RUN pip install --no-cache-dir /usr/src/app

ENV PYTHONPATH /usr/src/app
CMD ["/usr/src/app/main.py"]
8 changes: 8 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ inputs:
variable GITHUB_SHA.
required: false
type: string
charm_dir:
description: |
Relative name of the directory where the metadata.yaml or charmcraft.yaml files are located
if they are not in the root directory of the repository. The docs directory is also located
under this directory.
default: ''
required: false
type: string
outputs:
index_url:
description: |
Expand Down
2 changes: 1 addition & 1 deletion generate-src-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# See LICENSE file for licensing details.

rm -rf src-docs
lazydocs --no-watermark --output-path src-docs src/*.py
lazydocs --no-watermark --output-path src-docs src/gatekeeper/*.py
17 changes: 13 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@
from functools import partial
from pathlib import Path

from src import GETTING_STARTED, exceptions, pre_flight_checks, run_migrate, run_reconcile, types_
from src.clients import get_clients
from src.constants import DEFAULT_BRANCH
from src.types_ import ActionResult, PullRequestAction
from gatekeeper import (
GETTING_STARTED,
exceptions,
pre_flight_checks,
run_migrate,
run_reconcile,
types_,
)
from gatekeeper.clients import get_clients
from gatekeeper.constants import DEFAULT_BRANCH
from gatekeeper.types_ import ActionResult, PullRequestAction

GITHUB_HEAD_REF_ENV_NAME = "GITHUB_HEAD_REF"
GITHUB_OUTPUT_ENV_NAME = "GITHUB_OUTPUT"
Expand All @@ -45,6 +52,7 @@ def _parse_env_vars() -> types_.UserInputs:
github_access_token = os.getenv("INPUT_GITHUB_TOKEN")
base_branch = os.getenv("INPUT_BASE_BRANCH", DEFAULT_BRANCH)
commit_sha = os.getenv("INPUT_COMMIT_SHA")
charm_dir = os.getenv("INPUT_CHARM_DIR", "")

event_path = os.getenv("GITHUB_EVENT_PATH")
if not event_path:
Expand Down Expand Up @@ -79,6 +87,7 @@ def _parse_env_vars() -> types_.UserInputs:
github_access_token=github_access_token,
commit_sha=commit_sha,
base_branch=base_branch,
charm_dir=charm_dir,
)


Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

[project]
name = "discourse-gatekeeper"
version = "0.9.0"
dynamic = ["dependencies"]

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}

[tool.bandit]
exclude_dirs = ["/venv/", ".tox"]
[tool.bandit.assert_used]
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GitPython>=3.1,<3.2
pydiscourse>=1.6,<1.7
pydiscourse>=1.7,<1.8
PyGithub>=2.3,<2.4
PyYAML>=6.0,<6.1
requests>=2.31,<2.32
requests>=2.32,<2.33
more-itertools>=10.2,<10.3
9 changes: 4 additions & 5 deletions src-docs/__init__.py.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- markdownlint-disable -->

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

# <kbd>module</kbd> `__init__.py`
Library for uploading docs to charmhub.
Expand All @@ -9,14 +9,13 @@ Library for uploading docs to charmhub.
---------------
- **DRY_RUN_NAVLINK_LINK**
- **FAIL_NAVLINK_LINK**
- **DOCUMENTATION_FOLDER_NAME**
- **DOCUMENTATION_TAG**
- **DEFAULT_BRANCH_NAME**
- **GETTING_STARTED**

---

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

## <kbd>function</kbd> `run_reconcile`

Expand Down Expand Up @@ -51,7 +50,7 @@ Upload the documentation to charmhub.

---

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

## <kbd>function</kbd> `run_migrate`

Expand All @@ -76,7 +75,7 @@ Migrate existing docs from charmhub to local repository.

---

<a href="../src/__init__.py#L255"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/gatekeeper/__init__.py#L255"><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
4 changes: 2 additions & 2 deletions src-docs/action.py.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- markdownlint-disable -->

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

# <kbd>module</kbd> `action.py`
Module for taking the required actions to match the server state with the local state.
Expand All @@ -15,7 +15,7 @@ Module for taking the required actions to match the server state with the local

---

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

## <kbd>function</kbd> `run_all`

Expand Down
8 changes: 4 additions & 4 deletions src-docs/check.py.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- markdownlint-disable -->

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

# <kbd>module</kbd> `check.py`
Module for running checks.
Expand All @@ -11,7 +11,7 @@ Module for running checks.

---

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

## <kbd>function</kbd> `get_path_with_diffs`

Expand All @@ -37,7 +37,7 @@ Generate the paths that have either local or server content changes.

---

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

## <kbd>function</kbd> `conflicts`

Expand Down Expand Up @@ -67,7 +67,7 @@ The second type of conflict is a logical conflict which arises out of that there

---

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

## <kbd>function</kbd> `external_refs`

Expand Down
4 changes: 2 additions & 2 deletions src-docs/clients.py.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!-- markdownlint-disable -->

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

# <kbd>module</kbd> `clients.py`
Module for Client class.


---

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

## <kbd>function</kbd> `get_clients`

Expand Down
4 changes: 2 additions & 2 deletions src-docs/commit.py.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!-- markdownlint-disable -->

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

# <kbd>module</kbd> `commit.py`
Module for handling interactions with git commit.


---

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

## <kbd>function</kbd> `parse_git_show`

Expand Down
2 changes: 1 addition & 1 deletion src-docs/constants.py.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- markdownlint-disable -->

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

# <kbd>module</kbd> `constants.py`
Shared constants.
Expand Down
8 changes: 4 additions & 4 deletions src-docs/content.py.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!-- markdownlint-disable -->

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

# <kbd>module</kbd> `content.py`
Module for checking conflicts using 3-way merge and create content based on a 3 way merge.


---

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

## <kbd>function</kbd> `conflicts`

Expand All @@ -34,7 +34,7 @@ Check for merge conflicts based on the git merge algorithm.

---

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

## <kbd>function</kbd> `merge`

Expand Down Expand Up @@ -66,7 +66,7 @@ Create the merged content based on the git merge algorithm.

---

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

## <kbd>function</kbd> `diff`

Expand Down
22 changes: 11 additions & 11 deletions src-docs/discourse.py.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!-- markdownlint-disable -->

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

# <kbd>module</kbd> `discourse.py`
Interface for Discourse interactions.


---

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

## <kbd>function</kbd> `create_discourse`

Expand Down Expand Up @@ -50,7 +50,7 @@ Interact with a discourse server.

Attrs: host: The host of the discourse server.

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

### <kbd>function</kbd> `__init__`

Expand Down Expand Up @@ -80,7 +80,7 @@ The HTTP protocol and hostname for discourse (e.g., https://discourse).

---

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

### <kbd>function</kbd> `absolute_url`

Expand All @@ -103,7 +103,7 @@ Get the URL including base path for a topic.

---

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

### <kbd>function</kbd> `check_topic_read_permission`

Expand All @@ -128,7 +128,7 @@ Uses whether retrieve topic succeeds as indication whether the read permission i

---

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

### <kbd>function</kbd> `check_topic_write_permission`

Expand All @@ -151,7 +151,7 @@ Check whether the credentials have write permission on a topic.

---

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

### <kbd>function</kbd> `create_topic`

Expand Down Expand Up @@ -181,7 +181,7 @@ Create a new topic.

---

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

### <kbd>function</kbd> `delete_topic`

Expand Down Expand Up @@ -210,7 +210,7 @@ Delete a topic.

---

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

### <kbd>function</kbd> `retrieve_topic`

Expand Down Expand Up @@ -239,7 +239,7 @@ Retrieve the topic content.

---

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

### <kbd>function</kbd> `topic_url_valid`

Expand All @@ -264,7 +264,7 @@ Validations: 1. The URL must start with the base path configured during constru

---

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

### <kbd>function</kbd> `update_topic`

Expand Down
Loading

0 comments on commit 7718554

Please sign in to comment.