brynq-sdk-jira 3.0.2__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.2
3
+ Version: 3.0.3
4
4
  Summary: JIRA wrapper from BrynQ
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -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.2
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.2',
5
+ version='3.0.3',
6
6
  description='JIRA wrapper from BrynQ',
7
7
  long_description='JIRA wrapper from BrynQ',
8
8
  author='BrynQ',
File without changes