예제 #1
0
def prompt_for_settings() -> tuple[dict[str, str], str]:
    """
    Return type: (settings, shortcut_name)
    """

    settings: dict[str, Any] = {}

    settings["--auth-cache"] = str(
        Path(
            ask(
                "Path to the authentification cache",
                default="~/.cache/ideaseed/auth.json",
            ), ).expanduser())
    settings["--check-for-updates"] = answered_yes_to("Check for updates?",
                                                      False)
    settings["--self-assign"] = answered_yes_to(
        "Assign yourself to issues if you don't assign anyone with -@ ?", True)

    settings["--create-missing"] = answered_yes_to(
        "Ask for creation when milestones, labels, projects, etc. are missing?",
        True)

    print("""
        Local Copy is a feature that allows you to save a copy of any idea
        locally, somewhere safe on your disk.

        Ideas will get saved as markdown files with a YAML header for metadata,
        see https://github.com/ewen-lbh/ideaseed#local-copy for learn more.
        """)

    if (local_copy_dir := ask(
            "Directory to save local copies to (leave blank to not save local copies)",
            is_valid=validate_directory)):
        settings["--local-copy"] = str(Path(local_copy_dir).expanduser())
예제 #2
0
    def login_manually(self,
                       method: str = None) -> Tuple[Github, dict[str, Any]]:
        LOGIN_METHODS = namedtuple("LoginMethods", ["PAT", "username"])(
            PAT="Personal Access Token",
            username="******",
        )

        method = method or ask(
            "Log in using",
            choices={
                "0": LOGIN_METHODS.PAT,
                "1": LOGIN_METHODS.username
            },
        )

        if method == LOGIN_METHODS.PAT:
            pat = ask("Personal access token", password=True)
            try:
                gh = Github(pat)
                # just instanciating does not mean auth succeeded
                # seems like you need to _really_ hit Auth-retricted APIs,
                # even gh.get_user() does not work.
                # There does not seem to be a method made for auth-checking,
                # so I'm using that. sigh...
                gh.get_user().get_user_issues().get_page(0)
                return gh, dict(method=method, pat=pat)
            except BadCredentialsException:
                print("Bad token")
                return self.login_manually(method=method)
            except Exception as e:
                print(repr(e))
                return self.login_manually(method=method)
        else:
            username = ask("Username")
            password = ask("Password", password=True)
            try:
                gh = Github(username, password)
                gh.get_user().get_user_issues().get_page(0)
                return gh, dict(method=method,
                                username=username,
                                password=password)
            except TwoFactorException:
                print(
                    "Your account uses two-factor authentification. Please use a personal access token instead."
                )
                return self.login_manually(method=LOGIN_METHODS.username)
            except BadCredentialsException:
                print("Bad credentials")
                return self.login_manually(method=method)
            except Exception as e:
                print(repr(e))
                return self.login_manually(method=method)
예제 #3
0
def get_project_and_column(
        repo: Repository, project_name: str, column_name: str,
        create_missing: bool
) -> tuple[Optional[Project], Optional[ProjectColumn]]:
    """
    Gets a project and column from a repo
    """
    project = search_for_object(
        repo.get_projects(),
        project_name,
        create_missing=create_missing,
        object_name="project",
        create=lambda: repo.create_project(
            name=project_name,
            body=ask("Enter the project's description..."),
        ),
    )

    if project is None:
        return None, None

    column = search_for_object(
        project.get_columns(),
        column_name,
        create_missing=create_missing,
        object_name="column",
        create=lambda: project.create_column(name=column_name),
    )

    return project, column
예제 #4
0
    def login_manually(
        self,
        username: Optional[str] = None,
        password: Optional[str] = None,
        entering_app_password: bool = False,
    ) -> Tuple[Keep, dict[str, Any]]:
        # Ask for creds
        if not username:
            username = ask("Email")
        if not password:
            password = ask(
                "App password" if entering_app_password else "Password",
                password=True)

        # Log in
        keep = Keep()

        try:
            keep.login(username, password)

            # elif keyring:
            #     service, name =
        except LoginException as error:
            # Handle errors...
            topic, _ = error.args
            if topic == "BadAuthentication":
                print("[red]Bad credentials")
                return self.login_manually()
            elif topic == "NeedsBrowser":
                print(
                    """[red]You have two-step authentification set up, please add an App Password.
    Go to https://myaccount.google.com/apppasswords (a tab should've been opened)""",
                )
                webbrowser.open("https://myaccount.google.com/apppasswords")
                try:
                    return self.login_manually(username=username,
                                               entering_app_password=True)
                except RecursionError:
                    print("Too much attempts.")
                    sys.exit()
            else:
                print(topic)
                sys.exit()
        return keep, {
            "master_token": keep.getMasterToken(),
            "email": username,
        }
예제 #5
0
def interactively_create_label(repo: Repository, name: str):
    label_data = {
        "color":
        get_random_color_hexstring(),
        "description":
        ask("A short description of your label (100 chars max)",
            is_valid=lambda answer: "" if len(answer) <= 100 else
            "Keep the description under 100 characters"),
        "name":
        name,
    }
    print(f"Creating label {ui.Label(name, label_data['color'])}...")
    return repo.create_label(**label_data)
예제 #6
0
        see https://github.com/ewen-lbh/ideaseed#local-copy for learn more.
        """)

    if (local_copy_dir := ask(
            "Directory to save local copies to (leave blank to not save local copies)",
            is_valid=validate_directory)):
        settings["--local-copy"] = str(Path(local_copy_dir).expanduser())

    print("""
        For the following questions, you can use {placeholders}.
        See https://github.com/ewen-lbh/ideaseed#placeholders
        for the full list of available placeholders.
        """)

    settings["--default-project"] = ask(
        "Enter the default value for the project name",
        is_valid=placeholders_validator({"repository", "owner"}),
    )
    settings["--default-column"] = ask(
        "Enter the default value for the column name",
        is_valid=placeholders_validator({"repository", "owner", "project"}),
    )

    if answered_yes_to("Define overrides for the [bold]user[/bold] command?"):
        print(
            "Note that here, {owner} and {repository} are not available: the user command adds cards to your user profile directly"
        )

        settings["--default-user-project"] = ask(
            "Enter the default value for the project name in user command",
            is_valid=placeholders_validator({"project"}),
        )