def main(): i = 0 jira = JIRA("http://localhost:8080", basic_auth=('pro', 'pro')) projects = jira.projects() for project in projects: print("Project Name: " + project.name) roles = jira.project_roles(project) for role in roles: print("Role Name: " + role) the_role = jira.project_role(project, role) for actor in role.actors: print("Actor Name: " + actor) sys.exit(42) my_array = [] for group in groups: j = 0 my_array.append([group]) print("Group Name: " + group) j = j + 1 members = jira.group_members(group) for member in members: my_array[i].append(member) print(" Member: " + member) j = j + 1 i = i + 1 pickle.dump(my_array, open("groupBackup.p", "wb"))
import time from datetime import datetime import os # get our login and server data from env vars server = os.environ['JIRA_SERVER'] project = os.environ['JIRA_PROJECT'] username = os.environ['JIRA_USERNAME'] password = os.environ['JIRA_PASSWORD'] # connect to Jira options = {"server": server} jira = JIRA(options, basic_auth=(username, password)) # get all the roles in the project roles = jira.project_roles(project) print(f"project = {project}") # for each role, get the role name for rolename in roles: roleid = roles[rolename]['id'] role = jira.project_role(project, roleid) roledescription = role.description or "<role description missing>" print(f" role = {rolename} ({roleid}, {roledescription})") # then look in that role's members, either groups or users or both for actor in role.actors: actorid = actor.id actorname = actor.name actordisplayname = actor.displayName actortype = actor.type
while top_ten: item = top_ten.pop() prj_name = item[0] issue_count = item[1] print("Project name : {name}, Assigned Count : {count}".format( name=prj_name, count=issue_count)) #project 상세 정보 표출 if prj_name == "BTVD": prj = jira.project(prj_name) print("=" * 30) print("Project name : %s" % prj.name) print("Project leader name : %s" % prj.lead.displayName) components = jira.project_components(prj) print("Components : " + str([c.name for c in components])) print("Roles : " + str(jira.project_roles(prj))) versions = jira.project_versions(prj) print("Versions : " + str([v.name for v in reversed(versions)])) print("=" * 30) else: continue break_loop = False for issue in issues: print("Issue summary : " + issue.fields.summary) watcher = jira.watchers(issue) if watcher.watchCount > 1: print("Issue has {} watchers(s)".format(watcher.watchCount)) for watcher in watcher.watchers: print(watcher) print(watcher.emailAddress)
from jira import JIRA, JIRAError import re options = {'server': 'http://localhost:2990/jira'} #options = {'server':'http://jira.icterra.com:8443'} #jira = JIRA(options,basic_auth=('oner.elmas','!Oner0201976')) jira = JIRA(options, basic_auth=('admin', 'admin')) projetcs = jira.projects() keys = sorted([project.key for project in projetcs])[:] print(keys) jra = jira.project('PROJ') roles = jira.project_roles(jra) print(roles) users = jira.search_users('.') print([user.name for user in users]) # Create multiple issues issue_list = [{ 'project': { 'key': 'PROJ-1' }, 'summary': 'First issue of many', 'description': 'Look into this one', 'issuetype': { 'name': ' Task' },
class Util(object): """ """ def __init__(self, **kwargs): """ """ if 'config' in kwargs: self._config = kwargs['config'] else: logging.critical("config was not defined") raise Exception("config was not defined") if 'username' in kwargs: self._username = kwargs['username'] else: logging.critical("username was not defined") raise Exception("username was not defined") if 'password' in kwargs: self._password = kwargs['password'] else: logging.critical("password was not defined") raise Exception("password was not defined") if 'project' in kwargs: self._project = kwargs['project'] else: if 'project' in self._config: self._project = self._config['project'] logging.info( "project was set to '%s' from the configuration file" % self._project) else: self._project = DEFAULT_PROJECT logging.info("project was set to default '%s'" % self._project) if 'base_url' in kwargs: self._base_url = kwargs['base_url'] else: if 'base_url' in self._config: self._base_url = self._config['base_url'] logging.info( "base_url was set to '%s' from the configuration file" % self._base_url) else: self._base_url = DEFAULT_BASE_URL logging.info("base_url was set to default '%s'" % self._base_url) if 'add_missing_watchers' in kwargs: self._add_missing_watchers = kwargs['add_missing_watchers'] else: if 'add_missing_watchers' in self._config: self._add_missing_watchers = self._config[ 'add_missing_watchers'] logging.info( "add_missing_watchers was set to '%s' from the configuration file" % self._add_missing_watchers) else: self._add_missing_watchers = DEFAULT_ADD_MISSING_WATCHERS logging.info("add_missing_watchers was set to default '%s'" % self._add_missing_watchers) self._jira = None self._jra = None self._initialize() def setProject(self, project): """ :param project: :return: """ self._project = project def setAddMissingWatchers(self, add_missing_watchers): """ :param add_missing_watchers: :return: """ self._add_missing_watchers = add_missing_watchers def _initialize(self): """ :return: """ print("Attempting to connect to JIRA at '%s'" % self._base_url) self._jira = JIRA(self._base_url, basic_auth=(self._username, self._password)) print("Attempting to retrieve info for project '%s'" % self._project) self._jra = self._jira.project(self._project) def getReport(self): """ :return: """ self.report_misc() self.report_components() self.report_roles() self.report_versions() self.report_open_issues() def report_misc(self): """ :return: """ print(Fore.BLUE + "Project name '%s'" % self._jra.name) print(Fore.BLUE + "Project lead '%s'" % self._jra.lead.displayName) print(Style.RESET_ALL) def report_components(self): """ :return: """ components = self._jira.project_components(self._jra) if len(components) > 0: print(Fore.BLUE + "Here are the components") print(Style.RESET_ALL) for c in components: print(c.name) else: print(Fore.RED + "There are no components") print(Style.RESET_ALL) def report_roles(self): """ :return: """ roles = self._jira.project_roles(self._jra) if len(roles) > 0: print(Fore.BLUE + "Here are the roles") print(Style.RESET_ALL) for r in roles: print(r) else: print(Fore.RED + "There are no roles") print(Style.RESET_ALL) def report_versions(self): """ :return: """ versions = self._jira.project_versions(self._jra) if len(versions) > 0: print(Fore.BLUE + "Here are the versions") print(Style.RESET_ALL) for v in reversed(versions): print(v.name) else: print(Fore.RED + "There are no versions") print(Style.RESET_ALL) def report_watchers(self, issue): """ :param issue: :return: """ watcher = self._jira.watchers(issue) print("Issue '%s' has '%d' watcher(s)" % (issue.key, watcher.watchCount)) current_watchers_email = {} for watcher in watcher.watchers: current_watchers_email[watcher.emailAddress] = True print("'%s' - '%s'" % (watcher, watcher.emailAddress)) # watcher is instance of jira.resources.User: # print(watcher.emailAddress) for watcher_email in self._config['members_email_lookup']: if not watcher_email in current_watchers_email: print(Fore.RED + "member '%s' needs to be added as a watcher to '%s'" % (watcher_email, issue.key)) username = self._config['members_email_lookup'][watcher_email] print("Need to add username '%s'" % username) print(Style.RESET_ALL) if self._add_missing_watchers: self._jira.add_watcher(issue, username) print("Exiting") sys.exit(0) print(Style.RESET_ALL) def checkWatchers(self): """ :return: """ issues = self._jira.search_issues('project= LO AND status != Done', maxResults=DEFAULT_MAX_RESULTS) if len(issues) > 0: for issue in issues: self.report_watchers(issue) def report_open_issues(self): issues = self._jira.search_issues('project= LO AND status != Done', maxResults=DEFAULT_MAX_RESULTS) if len(issues) > 0: print(Fore.BLUE + "Found the following '%d' open issues" % len(issues)) print(Style.RESET_ALL) for issue in issues: summary = issue.fields.summary id = issue.id key = issue.key print("id '%s' key '%s' summary : '%s'" % (id, key, summary)) if DEFAULT_REPORT_WATCHERS: self._report_watchers(issue) print(Style.RESET_ALL) def getComments(self, key): """ :param key: :return: """ logging.info("Attempting to retrieve the issue with key '%s'" % key) issues = self._jira.search_issues('key = ' + key) if len(issues) > 1: raise Exception("Expected only one issue for '%s' but found '%d'" % (key, len(issues))) if len(issues) == 1: # comments = issues[0].fields.comment.comments # comments = issues[0].raw['fields']['comment']['comments'] comments = self._jira.comments(issues[0]) if len(comments) > 0: print("Found the following '%d' comments" % len(comments)) comment_ctr = 0 for comment_id in comments: print("-----------------------------------") comment_ctr += 1 comment = self._jira.comment(key, comment_id) author = comment.author.displayName date_created = comment.created body = comment.body print(Fore.BLUE + "%d. author '%s' date '%s'" % (comment_ctr, author, date_created)) print(Style.RESET_ALL) print(body)