Skip to content

Commit

Permalink
Feature/74 activate the projects title filter (#78)
Browse files Browse the repository at this point in the history
* New logic for writing the configuration without specifying query-labes and project-title-filter.
  • Loading branch information
MobiTikula authored Dec 18, 2024
1 parent 8b8da09 commit f384b97
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 24 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ See the default action step definition:
```yaml
- name: Generate Living Documentation
id: generate_living_doc
uses: AbsaOSS/living-doc-generator@v0.3.0
uses: AbsaOSS/living-doc-generator@v0.4.0
env:
GITHUB-TOKEN: ${{ secrets.REPOSITORIES_ACCESS_TOKEN }}
with:
Expand All @@ -70,7 +70,7 @@ See the full example of action step definition (in example are used non-default
```yaml
- name: Generate Living Documentation
id: generate_living_doc
uses: AbsaOSS/living-doc-generator@v0.3.0
uses: AbsaOSS/living-doc-generator@v0.4.0
env:
GITHUB-TOKEN: ${{ secrets.REPOSITORIES_ACCESS_TOKEN }}
with:
Expand All @@ -89,14 +89,12 @@ See the full example of action step definition (in example are used non-default
{
"organization-name": "health-analytics",
"repository-name": "patient-data-analysis",
"query-labels": ["functionality"],
"projects-title-filter": ["Health Data Analysis Project"]
},
{
"organization-name": "open-source-initiative",
"repository-name": "community-driven-project",
"query-labels": ["improvement"],
"projects-title-filter": ["Community Outreach Initiatives", "CDD Project"]
"query-labels": ["improvement"]
}
]
liv-doc-project-state-mining: true # project state mining feature de/activation
Expand Down
20 changes: 5 additions & 15 deletions living_documentation_regime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ See the default minimal Living Documentation regime action step definition:
```yaml
- name: Generate Living Documentation
id: generate_living_doc
uses: AbsaOSS/living-doc-generator@v0.3.0
uses: AbsaOSS/living-doc-generator@v0.4.0
env:
GITHUB-TOKEN: ${{ secrets.REPOSITORIES_ACCESS_TOKEN }}
with:
Expand All @@ -47,15 +47,7 @@ See the default minimal Living Documentation regime action step definition:
[
{
"organization-name": "fin-services",
"repository-name": "investment-app",
"query-labels": ["feature", "enhancement"],
"projects-title-filter": []
},
{
"organization-name": "health-analytics",
"repository-name": "patient-data-analysis",
"query-labels": ["functionality"],
"projects-title-filter": ["Health Data Analysis Project"]
"repository-name": "investment-app"
}
]
```
Expand All @@ -65,7 +57,7 @@ See the full example of Living Documentation regime step definition (in example
```yaml
- name: Generate Living Documentation
id: generate_living_doc
uses: AbsaOSS/living-doc-generator@v0.3.0
uses: AbsaOSS/living-doc-generator@v0.4.0
env:
GITHUB-TOKEN: ${{ secrets.REPOSITORIES_ACCESS_TOKEN }}
with:
Expand Down Expand Up @@ -100,7 +92,7 @@ Configure the Living Documentation regime by customizing the following parameter
### Regime Inputs
- **liv-doc-repositories** (optional, `default: '[]'`)
- **Description**: A JSON string defining the repositories to be included in the documentation generation.
- **Usage**: List each repository with its organization name, repository name, query labels and attached projects you want to filter if any. Only projects with these titles will be considered. For no filtering projects, leave the list empty.
- **Usage**: Provide a list of repositories including the organization name, repository name, query labels, and any attached projects you wish to filter. The query-labels and projects-title-filter parameters are optional. Only issues with the specified labels and projects will be fetched. To fetch all issues (all labels), either omit these parameters or leave the lists empty.
- **Example**:
```yaml
with:
Expand All @@ -109,13 +101,11 @@ Configure the Living Documentation regime by customizing the following parameter
{
"organization-name": "fin-services",
"repository-name": "investment-app",
"query-labels": ["feature", "enhancement"],
"projects-title-filter": []
"query-labels": ["feature", "enhancement"]
},
{
"organization-name": "open-source-initiative",
"repository-name": "community-driven-project",
"query-labels": ["improvement"],
"projects-title-filter": ["Community Outreach Initiatives", "CDD Project"]
}
]
Expand Down
4 changes: 2 additions & 2 deletions living_documentation_regime/model/config_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def load_from_json(self, repository_json: dict) -> bool:
try:
self.__organization_name = repository_json["organization-name"]
self.__repository_name = repository_json["repository-name"]
self.__query_labels = repository_json["query-labels"]
self.__projects_title_filter = repository_json["projects-title-filter"]
self.__query_labels = repository_json.get("query-labels", [])
self.__projects_title_filter = repository_json.get("projects-title-filter", [])
return True
except KeyError as e:
logger.error("The key is not found in the repository JSON input: %s.", e, exc_info=True)
Expand Down
34 changes: 32 additions & 2 deletions tests/living_documentation_regime/model/test_config_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


def test_load_from_json_with_valid_input_loads_correctly():
# Arrange
config_repository = ConfigRepository()
organization_name = "organizationABC"
repository_name = "repositoryABC"
Expand All @@ -32,35 +33,64 @@ def test_load_from_json_with_valid_input_loads_correctly():
"other-field": other_value,
}

# Act
actual = config_repository.load_from_json(repository_json)

# Assert
assert actual
assert organization_name == config_repository.organization_name
assert repository_name == config_repository.repository_name
assert query_labels == config_repository.query_labels
assert projects_title_filter == config_repository.projects_title_filter


def test_load_from_json_with_valid_input_check_default_values():
# Arrange
config_repository = ConfigRepository()
organization_name = "organizationABC"
repository_name = "repositoryABC"
repository_json = {
"organization-name": organization_name,
"repository-name": repository_name
}

# Act
actual = config_repository.load_from_json(repository_json)

# Assert
assert actual
assert organization_name == config_repository.organization_name
assert repository_name == config_repository.repository_name
assert [] == config_repository.query_labels
assert [] == config_repository.projects_title_filter


def test_load_from_json_with_missing_key_logs_error(mocker):
# Arrange
config_repository = ConfigRepository()
mock_log_error = mocker.patch("living_documentation_regime.model.config_repository.logger.error")
repository_json = {"non-existent-key": "value"}
mock_log_error = mocker.patch("living_documentation_regime.model.config_repository.logger.error")

# Act
actual = config_repository.load_from_json(repository_json)

# Assert
assert actual is False
mock_log_error.assert_called_once_with(
"The key is not found in the repository JSON input: %s.", mocker.ANY, exc_info=True
)


def test_load_from_json_with_wrong_structure_input_logs_error(mocker):
# Arrange
config_repository = ConfigRepository()
mock_log_error = mocker.patch("living_documentation_regime.model.config_repository.logger.error")
repository_json = "not a dictionary"
mock_log_error = mocker.patch("living_documentation_regime.model.config_repository.logger.error")

# Act
actual = config_repository.load_from_json(repository_json)

# Assert
assert actual is False
mock_log_error.assert_called_once_with(
"The repository JSON input does not have a dictionary structure: %s.", mocker.ANY, exc_info=True
Expand Down

0 comments on commit f384b97

Please sign in to comment.