Skip to content

Instantly share code, notes, and snippets.

@grundic
Created July 19, 2017 08:21
Show Gist options
  • Save grundic/cc26b30268fb633d512132dcbf561146 to your computer and use it in GitHub Desktop.
Save grundic/cc26b30268fb633d512132dcbf561146 to your computer and use it in GitHub Desktop.
JIRA issue dumper
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import time
from multiprocessing import Value
from multiprocessing.pool import ThreadPool
class JiraIssueDumper(object):
MAX_RESULTS = 50
def __init__(self, jira):
self.log = logging.getLogger(self.__class__.__name__)
self._jira = jira
def _total(self, jql_str):
result = self._jira.search_issues(jql_str=jql_str, maxResults=1)
return result.total
def collect(self, jql_str, fields=None, expand=None, callback=None):
total = self._total(jql_str)
start_intervals = range(0, total, self.MAX_RESULTS)
self.log.info(
"Total {total} issues are going to be requested by '{jql_str}' query."
.format(total=total, jql_str=jql_str)
)
counter = Value('i', 0)
shown = set()
def _exec_(start):
result = self._jira.search_issues(
jql_str=jql_str,
startAt=start,
maxResults=self.MAX_RESULTS,
fields=fields,
expand=expand
)
counter.value += len(result)
done_percent = float(counter.value * 100) / total
int_percent = int(done_percent)
if int_percent % 5 == 0 and int_percent not in shown:
self.log.info("Progress: {done}/{total} [{perc:.2f}%]".format(
done=counter.value, total=total, perc=done_percent)
)
shown.add(int_percent)
# save to db, dump json or similar
if callback and callable(callback):
callback(result)
pool = ThreadPool(processes=16)
self.log.info("Starting search...")
started = time.time()
pool.map(_exec_, start_intervals)
self.log.info(
"Search is complete, total {total} issues were found in {seconds}"
.format(total=total, seconds=time.time() - started)
)
@manishgcjain
Copy link

note sure .. how to run this.. can u please help in elaborating this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment