Exemple #1
0
def cli(args=sys.argv[1:]):
    import optparse
    alias_config = Config(section='alias')
    if set(list(alias_config.items().keys())).intersection(args):
        for alias, target in list(alias_config.items()).items():
            if args[0] == alias:
                args = shlex.split(target) + args[1:]
                break
    parser = build_parser()
    try:
        config = Config()
        pre_opts, pre_args = None, None
        try:
            optparser = optparse.OptionParser()

            def void(*args):
                raise SystemExit()

            optparser.print_usage = void
            optparser.add_option("", "--version", action='store_true', default=False)
            pre_opts, pre_args = optparser.parse_args(args)
        except SystemExit:
            pass
        if pre_opts and pre_opts.version:
            print(__version__)
            return
        if not (pre_opts and ("configure" in pre_args or "clear_cache" in pre_args)):
            post_args = parser.parse_args(args)
            jira = initialize(
                config, post_args.jira_url, post_args.username, post_args.password,
                persist=not (post_args.username or post_args.jira_url),
                protocol='rest'
            )
            return post_args.cmd(jira, post_args).execute()
        else:
            if "configure" in pre_args:
                config.reset()
                initialize(
                    config, "", "", "", True,
                    protocol='rest'
                )
            elif "clear_cache" in pre_args:
                clear_cache()
                print_output(colorfunc("jira-cli cache cleared", "green"))
            return

    except KeyboardInterrupt:
        print_error("aborted", severity=WARNING)
    except UsageWarning as e:
        print_error(str(e), severity=WARNING)
    except (JiraCliError, UsageError) as e:
        print_error(str(e))
    except (WebFault) as e:
        print_error(JiraCliError(e))
    except (JIRAError) as e:
        print_error(JiraCliError(e))
    except NotImplementedError as e:
        print_error(e)
Exemple #2
0
def cli(args=sys.argv[1:]):
    parser = build_parser()
    try:
        config = Config()
        pre_opts, pre_args = None, None
        try:
            pre_opts, pre_args = fake_parse(args)
        except StopIteration:
            pre_opts, pre_args = None, None
            if not ("--v2" in args or config.v2):
                return old_main()
        except SystemExit:
            pass
        if pre_opts and pre_opts.version:
            print(__version__)
            return
        if (not (pre_opts or pre_args)
                or (pre_opts and (pre_opts.v2 or config.v2)) and
                not (pre_opts and
                     ("configure" in pre_args or "clear_cache" in pre_args))):
            post_args = parser.parse_args(args)
            jira = initialize(
                config,
                post_args.jira_url,
                post_args.username,
                post_args.password,
                persist=not (post_args.username or post_args.jira_url),
                protocol=post_args.protocol or config.protocol or 'soap')
            return post_args.cmd(jira, post_args).execute()
        else:
            if "configure" in pre_args:
                config.reset()
                initialize(config,
                           "",
                           "",
                           "",
                           True,
                           protocol=pre_opts.protocol or config.protocol
                           or 'soap')
            elif "clear_cache" in pre_args:
                clear_cache()
                print_output(colorfunc("jira-cli cache cleared", "green"))
            return

    except KeyboardInterrupt:
        print_error("aborted", severity=WARNING)
    except UsageWarning as e:
        print_error(str(e), severity=WARNING)
    except (JiraCliError, UsageError) as e:
        print_error(str(e))
    except (WebFault) as e:
        print_error(JiraCliError(e))
    except (JIRAError) as e:
        print_error(JiraCliError(e))
    except NotImplementedError as e:
        print_error(e)
Exemple #3
0
 def create_issue(self,
                  project,
                  type='bug',
                  summary="",
                  description="",
                  priority="minor",
                  parent=None):
     issue = {
         "project": project.upper(),
         "summary": summary,
         "description": description,
         "priority": self.get_priorities()[priority.lower()]["id"]
     }
     if type.lower() == 'epic':
         issue['customfield_11401'] = summary
     try:
         if parent:
             issue['type'] = self.get_subtask_issue_types()[
                 type.lower()]['id'],
             return soap_recursive_dict(
                 self.service.createIssueWithParent(self.token, issue,
                                                    parent))
         else:
             issue['type'] = self.get_issue_types()[type.lower()]['id'],
             return soap_recursive_dict(
                 self.service.createIssue(self.token, issue))
     except WebFault as e:
         raise JiraCliError(e)
Exemple #4
0
 def transition_issue(self, issue, transition, comment=""):
     transitions = self.get_available_transitions(issue)
     try:
         return self.jira.transition_issue(issue,
                                           transitions[transition]['id'])
     except KeyError:
         raise JiraCliError("Invalid transition '%s'. Use one of [%s]" %
                            (transition, ",".join(transitions)))
Exemple #5
0
 def transition_issue(self, issue, transition, comment=""):
     transitions = self.get_available_transitions(issue)
     try:
         return self.service.progressWorkflowAction(
             self.token, issue, transitions[transition]['id'])
     except KeyError:
         raise JiraCliError("Invalid transition '%s'. Use one of [%s]" %
                            (transition, ",".join(transitions)))
Exemple #6
0
 def transition_issue(self, issue, transition, resolution):
     transitions = self.get_available_transitions(issue)
     fields = {}
     if resolution:
         fields["resolution"] = self.get_resolutions()[resolution.lower()]
     try:
         return self.jira.transition_issue(issue, transitions[transition]['id'], fields=fields)
     except KeyError:
         raise JiraCliError("Invalid transition '%s'. Use one of [%s]" % (transition, ",".join(transitions)))
Exemple #7
0
 def create_issue(self,
                  project,
                  type='bug',
                  summary="",
                  description="",
                  priority="minor",
                  parent=None,
                  assignee="",
                  reporter="",
                  labels=[],
                  components={},
                  **extras):
     issue = {
         "project": project.upper(),
         "summary": summary,
         "description": description,
         "priority": self.get_priorities()[priority.lower()]["id"],
         "assignee": assignee,
         "reporter": reporter,
         "components": [{
             "name": k,
             "id": components[k]
         } for k in components]
     }
     if not issue["components"]:
         issue.pop("components")
     if type.lower() == 'epic':
         issue['customfield_11401'] = summary
     try:
         if parent:
             issue['type'] = self.get_subtask_issue_types()[
                 type.lower()]['id'],
             created_issue = soap_recursive_dict(
                 self.service.createIssueWithParent(self.token, issue,
                                                    parent))
         else:
             issue['type'] = self.get_issue_types()[type.lower()]['id'],
             created_issue = soap_recursive_dict(
                 self.service.createIssue(self.token, issue))
         if assignee or reporter or labels:
             if assignee:
                 created_issue = self.assign_issue(created_issue['key'],
                                                   assignee)
             if reporter:
                 created_issue = self.change_reporter(
                     created_issue['key'], reporter)
             if labels:
                 created_issue = self.add_labels(created_issue['key'],
                                                 labels)
             return soap_recursive_dict(created_issue)
         else:
             return created_issue
     except WebFault as e:
         raise JiraCliError(e)
Exemple #8
0
 def transition_issue(self, issue, transition, resolution):
     transitions = self.get_available_transitions(issue)
     try:
         fields = {}
         if resolution:
             fields.append(
                 {"resolution": self.get_resolutions()[resolution]["id"]})
         return self.service.progressWorkflowAction(
             self.token, issue, transitions[transition]['id'], fields)
     except KeyError:
         raise JiraCliError("Invalid transition '%s'. Use one of [%s]" %
                            (transition, ",".join(transitions)))
Exemple #9
0
    def create_issue(self,
                     project,
                     type='bug',
                     summary="",
                     description="",
                     priority="minor",
                     parent=None,
                     assignee="",
                     reporter=""):
        issue = {
            "project": project.upper(),
            "summary": summary,
            "description": description,
            "priority": self.get_priorities()[priority.lower()]["id"],
            "assignee": assignee,
            "reporter": reporter
        }
        if type.lower() == 'epic':
            issue['customfield_11401'] = summary
        try:
            if parent:
                issue['type'] = self.get_subtask_issue_types()[
                    type.lower()]['id'],
                created_issue = soap_recursive_dict(
                    self.service.createIssueWithParent(self.token, issue,
                                                       parent))
            else:
                issue['type'] = self.get_issue_types()[type.lower()]['id'],
                created_issue = soap_recursive_dict(
                    self.service.createIssue(self.token, issue))
            if assignee:
                created_issue = self.assign_issue(created_issue['key'],
                                                  assignee)
            if reporter:
                created_issue = self.change_reporter(created_issue['key'],
                                                     reporter)
            return soap_recursive_dict(created_issue)

        except WebFault as e:
            raise JiraCliError(e)
Exemple #10
0
def cli(args=sys.argv[1:]):
    alias_config = Config(section='alias')
    if set(alias_config.items().keys()).intersection(args):
        for alias, target in alias_config.items().items():
            if args[0] == alias:
                args = shlex.split(target) + args[1:]
                break
    parser = build_parser()
    try:
        config = Config()
        pre_opts, pre_args = None, None
        try:
            pre_opts, pre_args = fake_parse(args)
        except StopIteration:
            pre_opts, pre_args = None, None
            if "--v1" in args or config.v1:
                if '--v1' in sys.argv:
                    print_error(
                        "Use of the v1 interface is no longer supported. Please refer to jiracli.readthedocs.io",
                        WARNING)
                    sys.argv.remove("--v1")
                return old_main()
        except SystemExit:
            pass
        if pre_opts and pre_opts.version:
            print(__version__)
            return
        if (not (pre_opts or pre_args)
                or (pre_opts and not (pre_opts.v1 or config.v1)) and
                not (pre_opts and
                     ("configure" in pre_args or "clear_cache" in pre_args))):
            post_args = parser.parse_args(args)
            jira = initialize(
                config,
                post_args.jira_url,
                post_args.username,
                post_args.password,
                persist=not (post_args.username or post_args.jira_url),
                protocol=post_args.protocol or config.protocol or 'rest')
            return post_args.cmd(jira, post_args).execute()
        else:
            if "configure" in pre_args:
                config.reset()
                initialize(config,
                           "",
                           "",
                           "",
                           True,
                           protocol=pre_opts.protocol or config.protocol
                           or 'soap')
            elif "clear_cache" in pre_args:
                clear_cache()
                print_output(colorfunc("jira-cli cache cleared", "green"))
            return

    except KeyboardInterrupt:
        print_error("aborted", severity=WARNING)
    except UsageWarning as e:
        print_error(str(e), severity=WARNING)
    except (JiraCliError, UsageError) as e:
        print_error(str(e))
    except (WebFault) as e:
        print_error(JiraCliError(e))
    except (JIRAError) as e:
        print_error(JiraCliError(e))
    except NotImplementedError as e:
        print_error(e)
Exemple #11
0
 def get_available_transitions(self, issue):
     transitions = self.service.getAvailableActions(self.token, issue)
     if not transitions:
         raise JiraCliError("No transitions found for issue %s" % issue)
     return dict(
         (k.name.lower(), soap_recursive_dict(k)) for k in transitions)
Exemple #12
0
 def add_labels(self, issue_id, labels, merge=False):
     if merge:
         raise JiraCliError(
             "updating labels via the soap protocol is not supported")
     return self.update_issue(issue_id, labels=labels)