Coverage for src\gibr\trackers\factory.py: 100%
32 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-20 09:51 +0300
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-20 09:51 +0300
1"""Factory for issue trackers."""
3from .github import GithubTracker
4from .jira import JiraTracker
7def get_tracker(config):
8 """Return issue tracker based on config."""
9 try:
10 tracker_type = config["issue-tracker"]["name"]
11 except KeyError:
12 raise ValueError("Missing 'issue-tracker.name' in config.")
13 if tracker_type == "github":
14 try:
15 github_config = config["github"]
16 except KeyError:
17 raise ValueError("Missing 'github' config.")
18 try:
19 repo = github_config["repo"]
20 token = github_config["token"]
21 except KeyError as e:
22 raise ValueError(f"Missing key in 'github' config: {e.args[0]}")
23 return GithubTracker(repo=repo, token=token)
24 elif tracker_type == "jira":
25 try:
26 jira_config = config["jira"]
27 except KeyError:
28 raise ValueError("Missing 'jira' config.")
29 try:
30 url = jira_config["url"]
31 user = jira_config["user"]
32 token = jira_config["token"]
33 project_key = jira_config["project_key"]
34 except KeyError as e:
35 raise ValueError(f"Missing key in 'jira' config: {e.args[0]}")
36 return JiraTracker(url=url, token=token, user=user, project_key=project_key)
37 else:
38 raise ValueError(f"Unsupported tracker type: {tracker_type}")