alita-sdk 0.3.130__py3-none-any.whl → 0.3.132__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,99 @@
1
+ import os
2
+ import pytest
3
+ from dotenv import load_dotenv
4
+
5
+ from elitea_analyse.ado.azure_search import AzureSearch
6
+
7
+ from ..alita_sdk.community.analysis.ado_analyse.api_wrapper import (
8
+ GetAdoWorkItemsArgs, AdoCommitsArgs, AdoAnalyseWrapper)
9
+
10
+ from ..alita_sdk.clients.client import AlitaClient
11
+ from ..alita_sdk.tools.artifact import ArtifactWrapper
12
+ from ..alita_sdk.community.utils import check_schema
13
+
14
+ # Load environment variables from .env file
15
+ load_dotenv()
16
+
17
+
18
+ @pytest.fixture
19
+ def ado_api_wrapper():
20
+ base_url = os.getenv("DEPLOYMENT_URL")
21
+ project_id = os.getenv("PROJECT_ID")
22
+ api_key = os.getenv("API_KEY")
23
+
24
+ if not base_url or not project_id or not api_key:
25
+ raise ValueError("Environment variables DEPLOYMENT_URL, PROJECT_ID, and API_KEY must be set.")
26
+
27
+ client = AlitaClient(
28
+ base_url=base_url,
29
+ project_id=int(project_id),
30
+ auth_token=api_key,
31
+ )
32
+
33
+ artifacts_wrapper = ArtifactWrapper(
34
+ client=client, bucket=os.getenv("ARTIFACT_BUCKET_PATH", "analyse-ado")
35
+ )
36
+ check_schema(artifacts_wrapper)
37
+ ado_search = AzureSearch(
38
+ organization=os.getenv("ADO_ORGANIZATION", "john.doe@epam.com"),
39
+ user=os.getenv("ADO_USER", "ado_user"),
40
+ token=os.getenv("ADO_TOKEN", "1111"),
41
+ )
42
+
43
+ ado_wrapper = AdoAnalyseWrapper(
44
+ artifacts_wrapper=artifacts_wrapper,
45
+ project_keys=os.getenv("ADO_PROJECTS", "project1,project2"),
46
+ default_branch_name=os.getenv("ADO_DEFAULT_BRANCH", "main"),
47
+ area=os.getenv("ADO_AREA", ""),
48
+ ado_search=ado_search,
49
+ )
50
+ check_schema(ado_wrapper)
51
+
52
+ return ado_wrapper
53
+
54
+ def test_get_projects_list(ado_api_wrapper):
55
+ result = ado_api_wrapper.get_projects_list()
56
+ assert isinstance(result, str)
57
+ assert "You have access to" in result
58
+
59
+ def test_get_work_items(ado_api_wrapper):
60
+ args = GetAdoWorkItemsArgs(
61
+ resolved_after="2023-01-01",
62
+ updated_after="2023-01-01",
63
+ created_after="2023-01-01",
64
+ )
65
+ result = ado_api_wrapper.get_work_items(
66
+ resolved_after=args.resolved_after,
67
+ updated_after=args.updated_after,
68
+ created_after=args.created_after,
69
+ area=args.area,
70
+ project_keys=args.project_keys
71
+ )
72
+ assert isinstance(result, str)
73
+ assert f"Work items for {ado_api_wrapper.project_keys} have been successfully retrieved and saved to the bucket" in result
74
+
75
+ @pytest.mark.asyncio
76
+ async def test_get_commits(ado_api_wrapper):
77
+ args = AdoCommitsArgs(
78
+ since_date="2023-01-01",
79
+ )
80
+
81
+ result = await ado_api_wrapper.get_commits(since_date=args.since_date)
82
+ # breakpoint()
83
+ assert isinstance(result, str)
84
+ assert f"Commits for {ado_api_wrapper.project_keys} have been successfully" in result
85
+
86
+
87
+ def test_get_merge_requests(ado_api_wrapper):
88
+ args = AdoCommitsArgs(
89
+ since_date="2023-01-01",
90
+ )
91
+
92
+ result = ado_api_wrapper.get_merge_requests(since_date=args.since_date)
93
+ assert isinstance(result, str)
94
+ assert f"Pull requests for {ado_api_wrapper.project_keys} have been successfully retrieved" in result
95
+
96
+ def test_get_pipelines_runs(ado_api_wrapper):
97
+ result = ado_api_wrapper.get_pipelines_runs()
98
+ assert isinstance(result, str)
99
+ assert f"Pipeline runs for {ado_api_wrapper.project_keys} have been successfully retrieved " in result
@@ -0,0 +1,87 @@
1
+ import os
2
+ from unittest.mock import patch
3
+ import pytest
4
+ from dotenv import load_dotenv
5
+
6
+ from elitea_analyse.github.github_org import GitHubGetOrgLvl
7
+ from ..alita_sdk.community.analysis.github_analyse.api_wrapper import (
8
+ GetGithubCommitsFromReposArgs, GetGithubRepositoriesListArgs, GitHubAnalyseWrapper
9
+ )
10
+
11
+ from ..alita_sdk.clients.client import AlitaClient
12
+ from ..alita_sdk.tools.artifact import ArtifactWrapper
13
+ from ..alita_sdk.community.utils import check_schema
14
+
15
+
16
+ # Load environment variables from .env file
17
+ load_dotenv()
18
+
19
+
20
+ @pytest.fixture
21
+ def github_api_wrapper():
22
+ base_url = os.getenv("DEPLOYMENT_URL")
23
+ project_id = os.getenv("PROJECT_ID")
24
+ api_key = os.getenv("API_KEY")
25
+
26
+ if not base_url or not project_id or not api_key:
27
+ raise ValueError("Environment variables DEPLOYMENT_URL, PROJECT_ID, and API_KEY must be set.")
28
+
29
+ client = AlitaClient(
30
+ base_url=base_url,
31
+ project_id=int(project_id),
32
+ auth_token=api_key,
33
+ )
34
+
35
+ artifacts_wrapper = ArtifactWrapper(
36
+ client=client, bucket=os.getenv("ARTIFACT_BUCKET_PATH", "analyse-gitlab")
37
+ )
38
+ check_schema(artifacts_wrapper)
39
+
40
+ owner = os.getenv("GITHUB_OWNER")
41
+ token = os.getenv("GITHUB_TOKEN")
42
+ if not owner or not token:
43
+ raise ValueError("GitHub owner and token are required")
44
+
45
+ git = GitHubGetOrgLvl(owner, token)
46
+
47
+ github_wrapper = GitHubAnalyseWrapper(
48
+ artifacts_wrapper=artifacts_wrapper,
49
+ repos=os.getenv("GITHUB_REPOS", ""),
50
+ git=git
51
+ )
52
+
53
+ check_schema(github_wrapper)
54
+
55
+ return github_wrapper
56
+
57
+ def test_get_commits_from_repos(github_api_wrapper):
58
+ args = GetGithubCommitsFromReposArgs(since_after="2025-06-01")
59
+ result = github_api_wrapper.get_commits_from_repos(since_after=args.since_after)
60
+ assert isinstance(result, str)
61
+ assert f"GitHub commits data for {github_api_wrapper.repos} saved" in result
62
+
63
+ def test_get_pull_requests_from_repos(github_api_wrapper):
64
+ args = GetGithubCommitsFromReposArgs(since_after="2025-06-01")
65
+ result = github_api_wrapper.get_pull_requests_from_repos(since_after=args.since_after)
66
+ assert isinstance(result, str)
67
+ assert "GitHub pull requests data saved" in result
68
+
69
+ def test_get_repositories_list(github_api_wrapper):
70
+ with patch(
71
+ "src.alita_sdk.community.analysis.github_analyse.api_wrapper.dispatch_custom_event",
72
+ return_value=None,
73
+ ):
74
+ args = GetGithubRepositoriesListArgs(pushed_after="2025-06-01")
75
+ result = github_api_wrapper.get_repositories_list(pushed_after=args.pushed_after)
76
+ assert isinstance(result, str)
77
+ assert "GitHub repositories list saved" in result
78
+
79
+ def test_get_repositories_extended_data(github_api_wrapper):
80
+ with patch(
81
+ "src.alita_sdk.community.analysis.github_analyse.api_wrapper.dispatch_custom_event",
82
+ return_value=None,
83
+ ):
84
+ args = GetGithubRepositoriesListArgs(pushed_after="2025-06-01")
85
+ result = github_api_wrapper.get_repositories_extended_data(pushed_after=args.pushed_after)
86
+ assert isinstance(result, str)
87
+ assert "Extended repository info that you have access saved" in result
@@ -0,0 +1,96 @@
1
+ import os
2
+ import pytest
3
+ from dotenv import load_dotenv
4
+
5
+ from elitea_analyse.git.git_search import GitLabV4Search
6
+
7
+
8
+ from ..alita_sdk.community.analysis.gitlab_analyse.api_wrapper import (
9
+ GitLabProjectsListArgs,
10
+ GitLabCommitsArgs, GitLabAnalyseWrapper
11
+ )
12
+
13
+ from ..alita_sdk.clients.client import AlitaClient
14
+ from ..alita_sdk.tools.artifact import ArtifactWrapper
15
+ from ..alita_sdk.community.utils import check_schema
16
+
17
+
18
+ # Load environment variables from .env file
19
+ load_dotenv()
20
+
21
+
22
+ @pytest.fixture
23
+ def gitlab_api_wrapper():
24
+ base_url = os.getenv("DEPLOYMENT_URL")
25
+ project_id = os.getenv("PROJECT_ID")
26
+ api_key = os.getenv("API_KEY")
27
+
28
+ if not base_url or not project_id or not api_key:
29
+ raise ValueError("Environment variables DEPLOYMENT_URL, PROJECT_ID, and API_KEY must be set.")
30
+
31
+ client = AlitaClient(
32
+ base_url=base_url,
33
+ project_id=int(project_id),
34
+ auth_token=api_key,
35
+ )
36
+
37
+ artifacts_wrapper = ArtifactWrapper(
38
+ client=client, bucket=os.getenv("ARTIFACT_BUCKET_PATH", "analyse-gitlab")
39
+ )
40
+ check_schema(artifacts_wrapper)
41
+
42
+ gitlab_url = os.getenv("GITLAB_URL")
43
+ gitlab_token = os.getenv("GITLAB_TOKEN")
44
+
45
+ if not gitlab_url or not gitlab_token:
46
+ raise ValueError("Environment variables GITLAB_URL and GITLAB_TOKEN must be set.")
47
+
48
+ gitlab_search = GitLabV4Search(
49
+ url=gitlab_url,
50
+ default_branch_name=os.getenv("GITLAB_DEFAULT_BRANCH", "master"),
51
+ token=gitlab_token,
52
+ )
53
+
54
+ project_keys = os.getenv("GITLAB_JIRA_PROJECTS", "project1,project2")
55
+ project_ids = os.getenv("GITLAB_PROJECTS_IDS", "123")
56
+
57
+ gitlab_analyse_wrapper = GitLabAnalyseWrapper(
58
+ artifacts_wrapper=artifacts_wrapper,
59
+ jira_project_keys=project_keys,
60
+ project_ids=project_ids,
61
+ gitlab_search=gitlab_search,
62
+ )
63
+ check_schema(gitlab_analyse_wrapper)
64
+
65
+ return gitlab_analyse_wrapper
66
+
67
+ def test_get_gitlab_projects_list(gitlab_api_wrapper):
68
+ args = GitLabProjectsListArgs(date="2025-05-01")
69
+ result = gitlab_api_wrapper.get_gitlab_projects_list(date=args.date)
70
+ assert isinstance(result, str)
71
+ assert "You have access to" in result
72
+
73
+ def test_get_gitlab_projects_that_in_jira(gitlab_api_wrapper):
74
+ result = gitlab_api_wrapper.get_gitlab_projects_that_in_jira()
75
+ assert isinstance(result, str)
76
+ assert "GitLab projects that match Jira project names." in result
77
+
78
+ def test_get_gitlab_commits(gitlab_api_wrapper):
79
+ project_ids = os.getenv("GITLAB_PROJECTS_IDS")
80
+ if not project_ids:
81
+ raise ValueError("Environment variable GITLAB_PROJECTS_IDS must be set.")
82
+
83
+ args = GitLabCommitsArgs(project_ids=project_ids, since_date="2010-01-01")
84
+ result = gitlab_api_wrapper.get_gitlab_commits(
85
+ project_ids=args.project_ids, since_date=args.since_date
86
+ )
87
+ assert isinstance(result, str)
88
+ assert f"Commits data for project {gitlab_api_wrapper.project_ids} has been saved. " in result
89
+
90
+
91
+ def test_get_gitlab_merge_requests(gitlab_api_wrapper):
92
+ since_date = "2010-01-01"
93
+ args = GitLabCommitsArgs(since_date=since_date)
94
+ result = gitlab_api_wrapper.get_gitlab_merge_requests(project_ids=args.project_ids, since_date=args.since_date)
95
+ assert isinstance(result, str)
96
+ assert f"There are no merge requests in the project {gitlab_api_wrapper.project_ids} created after {since_date}"
@@ -18,13 +18,24 @@ load_dotenv()
18
18
 
19
19
 
20
20
  @pytest.fixture
21
- def eda_api_wrapper():
21
+ def jira_api_wrapper():
22
+ base_url = os.getenv("DEPLOYMENT_URL")
23
+ project_id = os.getenv("PROJECT_ID")
24
+ api_key = os.getenv("API_KEY")
25
+ artifact_bucket_path = os.getenv("ARTIFACT_BUCKET_PATH", "analyse-jira")
26
+
27
+ if not base_url or not project_id or not api_key:
28
+ raise ValueError("Environment variables DEPLOYMENT_URL, PROJECT_ID, and API_KEY must be set.")
29
+
22
30
  client = AlitaClient(
23
- base_url=os.getenv("DEPLOYMENT_URL"),
24
- project_id=int(os.getenv("PROJECT_ID")),
25
- auth_token=os.getenv("API_KEY"),
31
+ base_url=base_url,
32
+ project_id=int(project_id),
33
+ auth_token=api_key,
26
34
  )
27
35
 
36
+ artifacts_wrapper = ArtifactWrapper(client=client, bucket=artifact_bucket_path)
37
+ check_schema(artifacts_wrapper)
38
+
28
39
  jira_credentials = {
29
40
  "username": os.getenv("JIRA_USER"),
30
41
  "base_url": os.getenv("JIRA_SERVER"),
@@ -33,24 +44,22 @@ def eda_api_wrapper():
33
44
  "verify_ssl": False,
34
45
  }
35
46
  jira = connect_to_jira(credentials=jira_credentials)
47
+ if not jira:
48
+ raise ValueError("Failed to connect to Jira. Please check your credentials.")
36
49
 
37
- artifacts_wrapper = ArtifactWrapper(
38
- client=client, bucket=os.getenv("ARTIFACT_BUCKET_PATH")
39
- )
40
-
41
- check_schema(artifacts_wrapper)
42
- eda_wrapper = JiraAnalyseWrapper(
50
+ jira_wrapper = JiraAnalyseWrapper(
43
51
  artifacts_wrapper=artifacts_wrapper,
44
52
  jira=jira,
45
- closed_status=os.getenv("JIRA_CLOSED_STATUS"),
46
- defects_name=os.getenv("JIRA_DEFECTS_NAME"),
53
+ closed_status=os.getenv("JIRA_CLOSED_STATUS", "Done"),
54
+ defects_name=os.getenv("JIRA_DEFECTS_NAME", "Defect"),
47
55
  custom_fields={"team": "", "defects_environment": ""},
56
+ project_keys=os.getenv("JIRA_PROJECT", "CARRIER"),
48
57
  )
49
- check_schema(eda_wrapper)
50
- return eda_wrapper
58
+ check_schema(jira_wrapper)
59
+ return jira_wrapper
51
60
 
52
61
 
53
- def test_get_number_of_all_issues(eda_api_wrapper):
62
+ def test_get_number_of_all_issues(jira_api_wrapper):
54
63
  with patch(
55
64
  "src.alita_sdk.community.analysis.jira_analyse.api_wrapper.dispatch_custom_event",
56
65
  return_value=None,
@@ -58,27 +67,14 @@ def test_get_number_of_all_issues(eda_api_wrapper):
58
67
  args = GetJiraFieldsArgs(
59
68
  project_keys=os.getenv("JIRA_PROJECT"), after_date="2025-01-01"
60
69
  )
61
- result = eda_api_wrapper.get_number_off_all_issues(
70
+ result = jira_api_wrapper.get_number_off_all_issues(
62
71
  args.project_keys, args.after_date
63
72
  )
64
73
  assert "projects" in result
65
74
  assert "projects_summary" in result
66
75
 
67
76
 
68
- def test_get_all_jira_fields(eda_api_wrapper):
69
- with patch(
70
- "src.alita_sdk.community.analysis.jira_analyse.api_wrapper.dispatch_custom_event",
71
- return_value=None,
72
- ):
73
- args = GetJiraFieldsArgs(
74
- project_keys=os.getenv("JIRA_PROJECT"), after_date="2025-01-01"
75
- )
76
- result = eda_api_wrapper.get_all_jira_fields(args.project_keys, args.after_date)
77
- assert "overall_stat" in result
78
- assert "issue_types_stat" in result
79
-
80
-
81
- def test_get_jira_issues(eda_api_wrapper):
77
+ def test_get_jira_issues(jira_api_wrapper):
82
78
  with patch(
83
79
  "src.alita_sdk.community.analysis.jira_analyse.api_wrapper.dispatch_custom_event",
84
80
  return_value=None,
@@ -91,12 +87,12 @@ def test_get_jira_issues(eda_api_wrapper):
91
87
  created_after="2025-01-01",
92
88
  add_filter="",
93
89
  )
94
- result = eda_api_wrapper.get_jira_issues(
95
- args.project_keys,
96
- args.closed_issues_based_on,
97
- args.resolved_after,
98
- args.updated_after,
99
- args.created_after,
100
- args.add_filter,
90
+ result = jira_api_wrapper.get_jira_issues(
91
+ closed_issues_based_on=args.closed_issues_based_on,
92
+ resolved_after=args.resolved_after,
93
+ updated_after=args.updated_after,
94
+ created_after=args.created_after,
95
+ project_keys=args.project_keys,
96
+ add_filter=args.add_filter,
101
97
  )
102
98
  assert "Data has been extracted successfully." in result