From aaef960abacfed7e92194c047e0e30fc2013e7f3 Mon Sep 17 00:00:00 2001 From: Dmitriy Diachkov Date: Tue, 22 Oct 2019 15:39:14 +0300 Subject: [PATCH 1/2] Bamboo: add 2 methods, update docs --- atlassian/bamboo.py | 26 ++++++++++++++++++++++---- docs/bamboo.rst | 6 ++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/atlassian/bamboo.py b/atlassian/bamboo.py index 602c99f7f..89800fb17 100755 --- a/atlassian/bamboo.py +++ b/atlassian/bamboo.py @@ -34,7 +34,7 @@ def _get_generator(self, path, elements_key='results', element_key='result', dat params['start-index'] = start_index response = self.get(path, data, flags, params, headers) results = response[elements_key] - size = 0 + size = 0 # Check if we still can get results if size > max_results or results['size'] == 0: @@ -87,7 +87,7 @@ def project_plans(self, project_key): def plans(self, expand=None, favourite=False, clover_enabled=False, start_index=0, max_results=25): return self.base_list_call("plan", expand, favourite, clover_enabled, start_index, max_results, elements_key='plans', element_key='plan') - + def plan_directory_info(self, plan_key): """ Returns information about the directories where artifacts, build logs, and build results will be stored. @@ -99,6 +99,15 @@ def plan_directory_info(self, plan_key): resource = 'planDirectoryInfo/{}'.format(plan_key) return self.get(self.resource_url(resource)) + def get_plan(self, plan_key): + """ + Get plan information. + :param plan_key: + :return: + """ + resource = 'rest/api/latest/plan/{}'.format(plan_key) + return self.get(resource) + def delete_plan(self, plan_key): """ Marks plan for deletion. Plan will be deleted by a batch job. @@ -118,7 +127,7 @@ def enable_plan(self, plan_key): return self.post(self.resource_url(resource)) """ Branches """ - + def search_branches(self, plan_key, include_default_branch=True, max_results=25): params = { 'max-result': max_results, @@ -171,6 +180,15 @@ def create_branch(self, plan_key, branch_name, vcs_branch=None, enabled=False, c cleanupEnabled='true' if cleanup_enabled else 'false') return self.put(self.resource_url(resource), params=params) + def get_vcs_branches(self, plan_key, max_results=25): + """ + Get all vcs names for the current plan + :param plan_key: str TST-BLD + :return: + """ + resource = 'plan/{plan_key}/vcsBranches'.format(plan_key=plan_key) + return self.base_list_call(resource, start_index=0, max_results=max_results) + """ Build results """ def results(self, project_key=None, plan_key=None, job_key=None, build_number=None, expand=None, favourite=False, @@ -523,7 +541,7 @@ def get_custom_expiry(self, limit=25): """ url = "rest/api/latest/admin/expiry/custom/plan?limit={}".format(limit) return self.get(url) - + def reports(self, max_results=25): params = {'max-results': max_results} return self._get_generator(self.resource_url('chart/reports'), elements_key='reports', element_key='report', diff --git a/docs/bamboo.rst b/docs/bamboo.rst index 82c089b79..777b781a9 100644 --- a/docs/bamboo.rst +++ b/docs/bamboo.rst @@ -21,6 +21,9 @@ Projects & Plans # Get information about plan build directory plan_directory_info(plan_key) + # Get plan information + get_plan(plan_key) + # Delete a plan (or a plan branch) delete_plan(plan_key) @@ -44,6 +47,9 @@ Branches # Create new branch (vcs or simple) create_branch(plan_key, branch_name, vcs_branch=None, enabled=False, cleanup_enabled=False) + # Get VCS Branches + get_vcs_branches(plan_key, max_results=25) + Build results ------------- From 4d4622a0e182e3aaa4a5f9952a9caed35de04a10 Mon Sep 17 00:00:00 2001 From: Dmitriy Diachkov Date: Tue, 22 Oct 2019 16:41:40 +0300 Subject: [PATCH 2/2] Add raw response return in the rest_client GET method --- atlassian/rest_client.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/atlassian/rest_client.py b/atlassian/rest_client.py index 3b7279589..a44dd11af 100644 --- a/atlassian/rest_client.py +++ b/atlassian/rest_client.py @@ -198,18 +198,20 @@ def get(self, path, data=None, flags=None, params=None, headers=None, not_json_r :param trailing: OPTIONAL: for wrap slash symbol in the end of string :return: """ - answer = self.request('GET', path=path, flags=flags, params=params, data=data, headers=headers, + response = self.request('GET', path=path, flags=flags, params=params, data=data, headers=headers, trailing=trailing) + if self.advanced_mode: + return response if not_json_response: - return answer.content + return response.content else: - if not answer.text: + if not response.text: return None try: - return answer.json() + return response.json() except Exception as e: log.error(e) - return answer.text + return response.text def post(self, path, data=None, headers=None, files=None, params=None, trailing=None): response = self.request('POST', path=path, data=data, headers=headers, files=files, params=params,