brynq-sdk-jira 3.0.1__tar.gz → 3.0.3__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: brynq_sdk_jira
3
- Version: 3.0.1
3
+ Version: 3.0.3
4
4
  Summary: JIRA wrapper from BrynQ
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -26,42 +26,60 @@ class Jira(BrynQ):
26
26
  :param expand_fields: an optional list of fields to expand
27
27
  :return: dataframe with issues
28
28
  """
29
- total_response = []
30
- got_all_results = False
31
- no_of_loops = 0
32
- while not got_all_results:
33
- query = {
34
- 'startAt': f'{100 * no_of_loops}',
35
- 'maxResults': '100',
36
- 'fields': ["summary", "issuetype", "timetracking", "timespent", "description", "assignee", "project"],
37
- 'fieldsByKeys': 'false'
29
+ if jira_filter_id is not None:
30
+ raise ValueError("Jira filter id is no longer supported, use jql_filter instead")
31
+
32
+ # Use new JQL search endpoint
33
+ url = f"{self.base_url}rest/api/3/search/jql"
34
+
35
+ all_issues = []
36
+ next_page_token = None
37
+
38
+ while True:
39
+ payload = {
40
+ "maxResults": 100,
41
+ "fields": ["summary", "issuetype", "timetracking", "timespent", "description", "assignee", "project"]
38
42
  }
43
+
44
+ if jql_filter:
45
+ payload["jql"] = jql_filter
46
+
47
+ if get_extra_fields:
48
+ payload["fields"].extend(get_extra_fields)
49
+
50
+ if expand_fields:
51
+ # Convert list to comma-delimited string
52
+ payload["expand"] = ",".join(expand_fields)
53
+
54
+ if next_page_token:
55
+ payload["nextPageToken"] = next_page_token
56
+
39
57
  if self.debug:
40
- print(query)
41
- if jql_filter is not None:
42
- query['jql'] = jql_filter
43
- if get_extra_fields is not None:
44
- query['fields'] += get_extra_fields
45
- if expand_fields is not None:
46
- query['expand'] = expand_fields
47
- if jira_filter_id is not None:
48
- url = f"{self.base_url}rest/api/3/search/jira/filter/{jira_filter_id}"
49
- else:
50
- url = f"{self.base_url}rest/api/3/search"
51
- response = requests.post(url=url, headers=self.headers, data=json.dumps(query), timeout=self.timeout)
58
+ print(f"Payload: {payload}")
59
+
60
+ response = requests.post(
61
+ url=url,
62
+ headers=self.headers,
63
+ data=json.dumps(payload),
64
+ timeout=self.timeout
65
+ )
66
+
52
67
  if response.status_code == 200:
53
68
  response_json = response.json()
54
- no_of_loops += 1
55
- got_all_results = False if len(response_json['issues']) == 100 else True
56
- total_response += response_json['issues']
69
+ all_issues.extend(response_json.get("issues", []))
70
+
71
+ # Check for next page
72
+ if "nextPageToken" in response_json:
73
+ next_page_token = response_json["nextPageToken"]
74
+ else:
75
+ break
57
76
  else:
58
77
  raise ConnectionError(f"Error getting issues from Jira with message: {response.status_code, response.text}")
59
78
 
60
79
  if self.debug:
61
- print(f"Received {len(total_response)} issues from Jira")
62
-
63
- df = pd.json_normalize(total_response)
80
+ print(f"Received {len(all_issues)} issues from Jira")
64
81
 
82
+ df = pd.json_normalize(all_issues)
65
83
  return df
66
84
 
67
85
  def get_projects(self) -> pd.DataFrame:
@@ -143,4 +161,4 @@ class Jira(BrynQ):
143
161
  print(f"Received {len(all_users)} jira users from Jira")
144
162
 
145
163
  df = pd.json_normalize(all_users)
146
- return df
164
+ return df
@@ -55,6 +55,82 @@ class Tempo(BrynQ):
55
55
 
56
56
  return total_response
57
57
 
58
+ def get_tempo_timesheet_approvals(self, from_date: str, to_date: str, team_id: int = 19) -> json:
59
+ """
60
+ This function retrieves approved timesheet approvals for a given team in Tempo
61
+ over the specified date range.
62
+
63
+ :param from_date: string <yyyy-MM-dd> - retrieve results starting with this date
64
+ :param to_date: string <yyyy-MM-dd> - retrieve results up to and including this date
65
+ :param team_id: int (default 19) - Tempo team ID whose approvals are retrieved
66
+ :return: json response with results
67
+ """
68
+ total_response = []
69
+ got_all_results = False
70
+ no_of_loops = 0
71
+
72
+ parameters = {
73
+ "from": from_date,
74
+ "to": to_date,
75
+ }
76
+
77
+ while not got_all_results:
78
+ loop_parameters = parameters | {"limit": 50, "offset": 50 * no_of_loops}
79
+ url = f"https://api.tempo.io/4/timesheet-approvals/team/{team_id}"
80
+ response = requests.get(
81
+ url,
82
+ headers=self.headers,
83
+ params=loop_parameters,
84
+ timeout=self.timeout
85
+ )
86
+
87
+ if response.status_code == 200:
88
+ response_json = response.json()
89
+ no_of_loops += 1
90
+ got_all_results = False if int(response_json['metadata']['count']) == 50 else True
91
+ total_response += response_json['results']
92
+ else:
93
+ raise ConnectionError(
94
+ f"Error getting timesheet approvals from Tempo: {response.status_code, response.text}"
95
+ )
96
+
97
+ if self.debug:
98
+ print(f"Received {len(total_response)} timesheet approvals from Tempo")
99
+
100
+ return total_response
101
+
102
+ def call_api(self, url: str, limit: int = 50) -> list[dict]:
103
+ """
104
+ Calls the Tempo API and retrieves all paginated results for a given endpoint.
105
+
106
+ Args:
107
+ url (str): The API endpoint URL to call.
108
+ limit (int): Max results to fetch per request (default 50).
109
+
110
+ Returns:
111
+ list[dict]: A list of all results across all pages.
112
+ """
113
+ all_results = []
114
+ offset = 0
115
+ while True:
116
+ querystring = {"limit": str(limit), "offset": str(offset)}
117
+ response = requests.get(url, headers=self.headers, params=querystring)
118
+ response.raise_for_status()
119
+ data = response.json()
120
+
121
+ # append results
122
+ results = data.get("results", [])
123
+ all_results.extend(results)
124
+
125
+ # pagination check
126
+ count = data.get("metadata", {}).get("count", 0)
127
+ if count < limit:
128
+ break
129
+
130
+ offset += limit
131
+
132
+ return all_results
133
+
58
134
  def get_tempo_teams(self, team_members: List[str] = None, name: str = None) -> json:
59
135
  """
60
136
  Fetches teams from the Tempo API in smaller batches to prevent long URLs if team_members is specified,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: brynq-sdk-jira
3
- Version: 3.0.1
3
+ Version: 3.0.3
4
4
  Summary: JIRA wrapper from BrynQ
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -2,7 +2,7 @@ from setuptools import setup, find_namespace_packages
2
2
 
3
3
  setup(
4
4
  name='brynq_sdk_jira',
5
- version='3.0.1',
5
+ version='3.0.3',
6
6
  description='JIRA wrapper from BrynQ',
7
7
  long_description='JIRA wrapper from BrynQ',
8
8
  author='BrynQ',
@@ -15,4 +15,4 @@ setup(
15
15
  'requests>=2,<=3'
16
16
  ],
17
17
  zip_safe=False,
18
- )
18
+ )
File without changes