Пример #1
0
                if completed.returncode != 0:
                    return 1
                completed = subprocess.run("git pull")
                if completed.returncode != 0:
                    return 1

            try:
                issue = jira.issue(args.issue, "summary")
                print("Creating branch for issue '{}'".format(
                    issue.fields.summary))
                suffix = input("Enter branch suffix name: ")
                if not suffix:
                    sys.stderr.write("No branch provided, aborting.")
                    return 1

                branch_name = "{}_{}".format(args.issue, suffix)
                branch_name = branch_name.replace(
                    " ", "_")  # Safety to prevent any weird stuff
                branch_prefix = "/" + args.prefix.replace(
                    " ", "_") if args.prefix else ""

                subprocess.run("git checkout -b {}{}".format(
                    branch_prefix, branch_name))

            except JIRAError as e:
                sys.stderr.write("Could not fetch issue '{}' (Code {})".format(
                    args.issue, e.status_code))
                return 1

    GakCommand.register_command(StartGakCommand())
Пример #2
0
        def command(self, args, root):
            # Default to the prefix of the current branch name
            issue = subprocess.getoutput(
                "git rev-parse --abbrev-ref HEAD").split('/')[-1].split('_')[0]

            jira = connect_to_jira(True)  # anonymous
            if not jira:
                return 1

            try:
                issue = jira.issue(issue, "summary")

                header = "{} {}".format(issue, issue.fields.summary)
                print("Commit for issue {}".format(header))

                command = "git commit -m \"{}\n\n{}\"{}".format(
                    header,
                    args.message if args.message else "",
                    "" if args.message else " -e",
                )

                subprocess.run(command)

            except JIRAError as e:
                sys.stderr.write("Could not fetch issue '{}' (Code {})".format(
                    issue, e.status_code))
                return 1

    GakCommand.register_command(CommitGakCommand())
Пример #3
0
                            for k, v in config.items())))
            return 0

        if args.what == "default":
            args.what = config.get("default")

        what = config.get(args.what)
        if what is not None:
            runner = open_user_config.get(what[0])
            if runner is None:
                sys.stderr.write(
                    f"'{what[0]}' not defined as an 'open' command\n")
                return 1

            if " " in what[1]:
                # Complex case, do a formatting of the root
                target = what[1].format(root=root)
            else:
                # Simple case, just prepend the root
                target = os.path.join(root, what[1])

            print("Opening {}".format(target))
            os.system(runner.format(target))
            return 0
        else:
            sys.stderr.write(f"No defined target '{args.what}'\n")
        return 1


GakCommand.register_command(OpenGakCommand())
Пример #4
0
                list(
                    map(print,
                        ("{}) {}".format(idx, branch) for idx, branch in zip(
                            range(len(target_branches)), target_branches))))
                value = input("Choose a branch (non-number to cancel): ")
            else:
                value = "n" \
                    if input("Switch to branch '{}'? (Yes: Enter, No: Any): ".format(target_branches[0])) \
                    else "0"

            if value.isdigit():
                value_int = int(value)
                if 0 <= value_int < len(target_branches):
                    cmd = "git checkout {}".format(target_branches[value_int])
                    print(cmd)
                    result = subprocess.getoutput(cmd)
                    if result:
                        print(result)
                else:
                    print("Value '{}' is not an option.".format(value_int))
            else:
                print("Operation canceled.")
            return 0
        else:
            print("No branch matching pattern '{}'".format(pattern))

        return 1


GakCommand.register_command(SwitchGakCommand())
Пример #5
0
                    default))
                return 1
        else:
            what = config.get(args.what)

        if what is not None:
            if args.configure or args.what == "configure":
                config_commands = config.get("configure")
                if config_commands:
                    for cc in config_commands:
                        os.system(cc.format(root=root))
                else:
                    print(
                        "No configure step defined in the build configuration")

            if what:
                if args.what != "configure":
                    for w in what:
                        build_cmd = w.format(root=root)
                        os.system(build_cmd)
                return 0
            else:
                print("Nothing defined to build!")
        else:
            print("No configuration defined for '{}'".format(args.what))

        return 1


GakCommand.register_command(BuildGakCommand())
Пример #6
0
            user_prefix = user_config.get("mkdev", {}).get("prefix")
            if not user_prefix:
                print("[WARNING] No dev prefix defined, default to 'dev'")
            else:
                prefix = user_prefix

        current_branch = subprocess.getoutput(
            "git rev-parse --abbrev-ref HEAD")
        split_current_branch = current_branch.split("/")
        is_dev_branch = "/".join(split_current_branch[0:-1]) == prefix

        cmd = None
        if not is_dev_branch:
            cmd = f"git branch -m {current_branch} {prefix}/{current_branch}"
        elif args.toggle:
            suffix = split_current_branch[-1]
            cmd = f"git branch -m {prefix}/{suffix} {suffix}"

        if cmd:
            print(cmd)
            result = subprocess.getoutput(cmd)
            if result:
                print(result)
            return 0
        else:
            print("Nothing to do, already prefixed by {}".format(prefix))
        return 1


GakCommand.register_command(MkdevGakCommand())
Пример #7
0
from gak.interface import GakCommand
from gak.utils import list_configs


class ListGakCommand(GakCommand):
    def init_parser(self, subparsers):
        list_parser = subparsers.add_parser(
            "list",
            aliases=['ls'],
            help="List configurations defined for this project")
        list_parser.set_defaults(func=self.command)

    def command(self, args, root):
        configs = list_configs(root)
        if configs:
            print("Configurations are defined for the following commands:")
            list(map(print, ("* {}".format(c.split(".")[0]) for c in configs)))
        else:
            print("No configuration defined!")
        return 0


GakCommand.register_command(ListGakCommand())
Пример #8
0
                                          help="Go to places in the repo")
        to_parser.add_argument("place", help="Place to go to")
        to_parser.set_defaults(func=self.command)

    def command(self, args, root):
        config = retrieve_config("to", root)

        # Add default places
        config.update({"root": ""})

        if args.place == "?":
            print("Defined values:")
            for k, v in config.items():
                print("* {} =>\t{}".format(
                    k, to_platform_path(os.path.join(root, v))))
            return 0

        target = config.get(args.place)
        if target is not None:
            target_platform_path = os.path.join(root, target)
            sys.stdout.write(to_platform_path(target_platform_path))
            return 0
        else:
            print(
                "No target called '{}' defined in the repository configuration"
                .format(args.place))
        return 1


GakCommand.register_command(ToGakCommand())
Пример #9
0
            )
            log_parser.add_argument("-m",
                                    "--message",
                                    help="Message for the worklog")
            log_parser.set_defaults(func=self.command)

        def command(self, args, root):
            if not args.issue:
                # Default to the prefix of the current branch name
                args.issue = subprocess.getoutput(
                    "git rev-parse --abbrev-ref HEAD").split('/')[-1].split(
                        '_')[0]

            print("About to log in issue {}".format(args.issue))

            jira = connect_to_jira()
            if not jira:
                return 1

            try:
                jira.add_worklog(args.issue, args.to_log, comment=args.message)
                print("Successfully logged {} in issue {}{}".format(
                    args.to_log, args.issue, " with mention '{}'".format(
                        args.message) if args.message else ""))
            except JIRAError as e:
                sys.stderr.write("Could not log (Code {})".format(
                    e.status_code))
                return 1

    GakCommand.register_command(LogGakCommand())