Skip to content

Commit

Permalink
Fix bug where the IQL search would return nothing if the result are l…
Browse files Browse the repository at this point in the history
…ess than 500 objects.
  • Loading branch information
dstengele committed Aug 19, 2021
1 parent ae02a72 commit 526c0da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
41 changes: 21 additions & 20 deletions jira_insight/insight.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,26 +277,26 @@ def search_iql(self, iql=None):
"objectSchemaId": self.id,
"resultPerPage": 500,
"includeTypeAttributes": "true",
"page": 1,
}
if iql is not None:
params["iql"] = iql
search_request = self.insight.do_api_request(api_path, params=params)
search_results = search_request
objects_json: list = search_results["objectEntries"]
if not objects_json:
raise StopIteration

# Get additional pages if necessary
if search_results["pageSize"] > 1:
for page_number in range(2, search_results["pageSize"] + 1):
params["page"] = page_number
logging.info(
f'Reading page {page_number} of {search_results["pageSize"]}'
)
page = self.insight.do_api_request(api_path, params=params)

for json_object in page["objectEntries"]:
yield InsightObject(self.insight, json_object["id"], json_object)

while True:
search_results = self.insight.do_api_request(api_path, params=params)
logging.info(
f'Got page {params["page"]} of {search_results["pageSize"]}'
)
objects_to_check: list = search_results["objectEntries"]

for json_object in objects_to_check:
yield InsightObject(self.insight, json_object["id"], json_object)

# Get additional pages if necessary
if params["page"] == search_results["pageSize"]:
raise StopIteration

params["page"] += 1

def object_exists(self, object_id):
return (
Expand Down Expand Up @@ -395,6 +395,7 @@ def __str__(self):
if __name__ == "__main__":
# Poor man's debugging
insight = Insight(os.environ["INSIGHT_URL"], None, webbrowser_auth=True)
insight_object = InsightObject(insight, os.environ["INSIGHT_OBJECT_ID"])
value = insight_object.attributes["Status"].value
pass
insight_object_schema = InsightObjectSchema(insight, 12)
object_gen = insight_object_schema.search_iql('objectType IN ("Desktop","Laptop","Tablet","Virtuelle Maschine")')

print([i for i in object_gen])
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="jira_insight",
version="0.5.4",
version="0.5.5",
author="Dennis Stengele",
author_email="[email protected]",
description="API client for the Insight app for Jira",
Expand Down

0 comments on commit 526c0da

Please sign in to comment.