Skip to content

Commit

Permalink
Move URLs and rules path to configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Nov 25, 2024
1 parent 3f13a95 commit a7674ae
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ Task state can be one of:

Below is list of environment variables supported in the container image:

- `RETASC_CONFIG` - Configuration file
- `RETASC_JIRA_URL` - Jira URL
- `RETASC_CONFIG` - Path to the main configuration file
- `RETASC_JIRA_TOKEN` - Jira access token
- `RETASC_RULES_PATH` - Path to rules
- `RETASC_PP_URL` - Product Pages URL
- `RETASC_LOGGING_CONFIG` - Path to JSON file with the logging configuration;
see details in [Configuration dictionary
schema](https://docs.python.org/3/library/logging.config.html#logging-config-dictschema)
Expand Down
4 changes: 4 additions & 0 deletions examples/config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
rules_path: examples/rules
product_pages_url: https://pp.example.com
jira_url: https://jira.example.com

jira_fields:
description: description
labels: labels
Expand Down
4 changes: 4 additions & 0 deletions src/retasc/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@


class Config(BaseModel):
rules_path: str = Field(description="Path to rules (processed recursively)")
product_pages_url: str = Field(description="Product Pages URL")
jira_url: str = Field(description="Jira URL")

jira_label: str = Field(description="Label for the managed issues in Jira")
jira_label_prefix: str = Field(
description="Prefix for labels identifying the issue in Jira"
Expand Down
9 changes: 3 additions & 6 deletions src/retasc/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ def drop_issues(context: RuntimeContext):


def run(*, dry_run: bool) -> Report:
jira_url = os.environ["RETASC_JIRA_URL"]
jira_token = os.environ["RETASC_JIRA_TOKEN"]
pp_url = os.environ["RETASC_PP_URL"]
path = os.environ["RETASC_RULES_PATH"]
config_path = os.environ["RETASC_CONFIG"]

with open(config_path) as f:
Expand All @@ -85,9 +82,9 @@ def run(*, dry_run: bool) -> Report:
config = Config(**config_data)
session = requests_session()
jira_cls = DryRunJiraClient if dry_run else JiraClient
jira = jira_cls(api_url=jira_url, token=jira_token, session=session)
pp = ProductPagesApi(pp_url, session=session)
rules = parse_rules(path)
jira = jira_cls(api_url=config.jira_url, token=jira_token, session=session)
pp = ProductPagesApi(config.product_pages_url, session=session)
rules = parse_rules(config.rules_path)
template = TemplateManager()
report = Report()
context = RuntimeContext(
Expand Down
5 changes: 1 addition & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,8 @@ def invalid_rule_file(rule_path, rule_dict):

@fixture(autouse=True)
def mock_env(monkeypatch):
monkeypatch.setenv("RETASC_JIRA_URL", "")
monkeypatch.setenv("RETASC_JIRA_TOKEN", "")
monkeypatch.setenv("RETASC_PP_URL", "")
monkeypatch.setenv("RETASC_RULES_PATH", "examples/rules")
monkeypatch.setenv("RETASC_CONFIG", "examples/config.yaml")
monkeypatch.setenv("RETASC_JIRA_TOKEN", "")


def mock_jira_cls(cls: str, new_issue_key: str):
Expand Down
3 changes: 3 additions & 0 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ def test_run_rule_jira_issue_fields_config(monkeypatch, tmpdir):
jira_label: retasc-managed
jira_label_prefix: retasc-id-
jira_release_field_name: affectedVersion
rules_path: examples/rules
product_pages_url: https://pp.example.com
jira_url: https://jira.example.com
""")
expected_error = (
"Jira templates must not override property 'affectedVersion'"
Expand Down

0 comments on commit a7674ae

Please sign in to comment.