Beispiel #1
0
    def get_credentials_for(which):
        if not config.has_option(which, 'username'):
            if config.has_option('login', 'username'):
                config.set(which, 'username', config.get('login', 'username'))
            elif ((which == 'target') and query.yes_no(
                    "Do you wish to use the same credentials for the target repository?"
            )):
                config.set('target', 'username',
                           config.get('source', 'username'))
            else:
                query_str = "Enter your username for '%s' at '%s': " % (
                    config.get(which, 'repository'), config.get(
                        which, 'server'))
                config.set(which, 'username', query.username(query_str))

        if not config.has_option(which, 'password'):
            if config.has_option('login', 'password'):
                config.set(which, 'password', config.get('login', 'password'))
            elif ((which == 'target') and config.get('source', 'username')
                  == config.get('target', 'username') and config.get(
                      'source', 'server') == config.get('target', 'server')):
                config.set('target', 'password',
                           config.get('source', 'password'))
            else:
                query_str = "Enter your password for '%s' at '%s': " % (
                    config.get(which, 'repository'), config.get(
                        which, 'server'))
                config.set(which, 'password', query.password(query_str))
	def get_credentials_for(which):
		if not config.has_option(which, 'username'):
			if config.has_option('login', 'username'):
				config.set(which, 'username', config.get('login', 'username'))
			elif ( (which == 'target') and query.yes_no("Do you wish to use the same credentials for the target repository?") ):
				config.set('target', 'username', config.get('source', 'username'))
			else:
				query_str = "Enter your username for '%s' at '%s': " % (config.get(which, 'repository'), config.get(which, 'server'))
				config.set(which, 'username', query.username(query_str))
		
		if not config.has_option(which, 'password'):
			if config.has_option('login', 'password'):
				config.set(which, 'password', config.get('login', 'password'))
			elif ( (which == 'target') and config.get('source', 'username') == config.get('target', 'username') and config.get('source', 'server') == config.get('target', 'server') ):
				config.set('target', 'password', config.get('source', 'password'))
			else:
				query_str = "Enter your password for '%s' at '%s': " % (config.get(which, 'repository'), config.get(which, 'server'))
				config.set(which, 'password', query.password(query_str))

		if not config.has_option(which, 'token'):
			if config.has_option('login', 'token'):
				config.set(which, 'token', config.get('login', 'token'))
			elif ( (which == 'target') and query.yes_no("Do you wish to use the same credentials for the target repository?") ):
				config.set('target', 'token', config.get('source', 'token'))
			else:
				query_str = "Enter your token for '%s' at '%s': " % (config.get(which, 'repository'), config.get(which, 'server'))
				config.set(which, 'token', query.token(query_str))
    def get_credentials_for(which):
        if not config.has_option(which, "username"):
            if config.has_option("login", "username"):
                config.set(which, "username", config.get("login", "username"))
            elif (which == "target") and query.yes_no(
                "Do you wish to use the same credentials for the target repository?"
            ):
                config.set("target", "username", config.get("source", "username"))
            else:
                query_str = "Enter your username for '%s' at '%s': " % (
                    config.get(which, "repository"),
                    config.get(which, "server"),
                )
                config.set(which, "username", query.username(query_str))

        if not config.has_option(which, "password"):
            if config.has_option("login", "password"):
                config.set(which, "password", config.get("login", "password"))
            elif (
                (which == "target")
                and config.get("source", "username") == config.get("target", "username")
                and config.get("source", "server") == config.get("target", "server")
            ):
                config.set("target", "password", config.get("source", "password"))
            else:
                query_str = "Enter your password for '%s' at '%s': " % (
                    config.get(which, "repository"),
                    config.get(which, "server"),
                )
                config.set(which, "password", query.password(query_str))
def init_config():

    config.add_section("source")
    config.add_section("target")
    config.add_section("format")
    config.add_section("settings")

    arg_parser = argparse.ArgumentParser(description="Import issues from one GitHub repository into another.")

    arg_parser.add_argument(
        "--config",
        help="The location of the config file (either absolute, or relative to the current working directory). Defaults to `config.ini` found in the same folder as this script.",
    )
    arg_parser.add_argument(
        "-source_u",
        "--source_username",
        help="The SOURCE username of the account on the SOURCE server the issues are to be copied from. The username will not be stored anywhere if passed in as an argument.",
    )
    arg_parser.add_argument(
        "-source_p",
        "--source_password",
        help="The SOURCE password of the account on the SOURCE server the issues are to be copied from. The username will not be stored anywhere if passed in as an argument.",
    )
    arg_parser.add_argument(
        "-target_u",
        "--target_username",
        help="The TARGET username of the account on the TARGET server the issues are to be copied from. The username will not be stored anywhere if passed in as an argument.",
    )
    arg_parser.add_argument(
        "-target_p",
        "--target_password",
        help="The TARGET password of the account on the TARGET server the issues are to be copied from. The username will not be stored anywhere if passed in as an argument.",
    )
    arg_parser.add_argument(
        "-source_s",
        "--source_server",
        help="The SOURCE server which the issues should be copied from. e.g. `github.com` or `github.mycompany.com` (for enterprise).",
    )
    arg_parser.add_argument(
        "-target_s",
        "--target_server",
        help="The TARGET server which the issues should be copied to. e.g. `github.com` or `github.mycompany.com` (for enterprise).",
    )
    arg_parser.add_argument(
        "-source_r",
        "--source_repo",
        help="The source repository which the issues should be copied from. Should be in the format `user/repository`.",
    )
    arg_parser.add_argument(
        "-target_r",
        "--target_repo",
        help="The destination repository which the issues should be copied to. Should be in the format `user/repository`.",
    )

    arg_parser.add_argument(
        "--ignore-comments", dest="ignore_comments", action="store_true", help="Do not import comments in the issue."
    )
    arg_parser.add_argument(
        "--ignore-milestone",
        dest="ignore_milestone",
        action="store_true",
        help="Do not import the milestone attached to the issue.",
    )
    arg_parser.add_argument(
        "--ignore-labels", dest="ignore_labels", action="store_true", help="Do not import labels attached to the issue."
    )

    arg_parser.add_argument(
        "issues",
        type=int,
        nargs="*",
        help="The list of issues to import. If no issue ID is provided, all open issues will be imported.",
    )

    args = arg_parser.parse_args()

    config_file_name = default_config_file
    if args.config:
        config_file_name = args.config

    try:
        config_file = open(config_file_name)
        config.read_file(config_file)
    except FileNotFoundError:
        sys.exit("ERROR: Unable to find or open config file '%s'" % config_file_name)

    if args.source_username:
        config.set("source", "username", args.source_username)
    if args.source_password:
        config.set("source", "password", args.source_password)
    if args.target_username:
        config.set("target", "username", args.target_username)
    if args.target_password:
        config.set("target", "password", args.target_password)
    if args.source_server:
        config.set("source", "server", args.source_server)
    if args.target_server:
        config.set("target", "server", args.target_server)
    if args.source_repo:
        config.set("source", "repository", args.source_repo)
    if args.target_repo:
        config.set("target", "repository", args.target_repo)

    config.set("settings", "import-comments", str(not args.ignore_comments))
    config.set("settings", "import-milestone", str(not args.ignore_milestone))
    config.set("settings", "import-labels", str(not args.ignore_labels))

    # Make sure no required config values are missing
    if not config.has_option("source", "repository"):
        sys.exit("ERROR: There is no source repository specified either in the config file, or as an argument.")
    if not config.has_option("target", "repository"):
        sys.exit("ERROR: There is no target repository specified either in the config file, or as an argument.")

    # Prompt for SOURCE username/password if none is provided in either the config or an argument
    if not config.has_option("source", "username"):
        config.set("source", "username", query.username("Enter your username for GitHub.com: "))
    if not config.has_option("source", "password"):
        config.set("source", "password", query.password("Enter your password for GitHub.com: "))

    # Prompt for TARGET username/password if none is provided in either the config or an argument
    if not config.has_option("target", "username"):
        config.set("target", "username", query.username("Enter your TARGET username for GitHub.com: "))
    if not config.has_option("target", "password"):
        config.set("target", "password", query.password("Enter your TARGET password for GitHub.com: "))

    # Everything is here! Continue on our merry way...
    global source_url, target_url

    # if SOURCE server is not github.com, then assume ENTERPRISE github (yourdomain.com/api/v3...)
    if config.get("source", "server") != "github.com":
        source_api_server = config.get("source", "server")
        source_url = "https://%s/api/v3/repos/%s" % (source_api_server, config.get("source", "repository"))
    else:
        source_api_server = "api.github.com"
        source_url = "https://%s/repos/%s" % (source_api_server, config.get("source", "repository"))

    # if TARGET server is not github.com, then assume ENTERPRISE github (yourdomain.com/api/v3...)
    if config.get("target", "server") != "github.com":
        target_api_server = config.get("target", "server")
        target_url = "https://%s/api/v3/repos/%s" % (target_api_server, config.get("target", "repository"))
    else:
        target_api_server = "api.github.com"
        target_url = "https://%s/repos/%s" % (target_api_server, config.get("target", "repository"))

    return args.issues