Exemple #1
0
def test_set_get_reset_settings():
    settings = Settings()
    settings.set_github_token("github_token")
    settings.set_github_login("github_login")
    settings.set_github_emails(
        ["github_email1", "github_email2", "github_email3"])

    assert settings.is_github_valid()
    assert not settings.is_slack_valid()
    assert settings.get_github_token() == "github_token"
    assert settings.get_github_login() == "github_login"
    assert settings.get_github_emails() == [
        "github_email1", "github_email2", "github_email3"
    ]

    settings.set_slack_token("slack_token")
    settings.set_slack_channel("slack_channel")

    assert settings.is_github_valid()
    assert settings.is_slack_valid()
    assert settings.get_slack_token() == "slack_token"
    assert settings.get_slack_channel() == "slack_channel"

    settings.reset_slack()
    assert not settings.is_slack_valid()
    settings.reset_github()
    assert not settings.is_github_valid()
    assert_empty_settings()
Exemple #2
0
def _setup_slack():
    settings = Settings()

    if settings.is_slack_valid():
        if not click.confirm("Reset Slack config?", prompt_suffix=" "):
            return
    else:
        if not click.confirm("(optional) Configure Slack integration?",
                             prompt_suffix=" "):
            return

    click.echo(get_slack_text())
    token = click.prompt("Slack token", type=click.STRING,
                         hide_input=True).strip()
    channel = click.prompt("Slack channel",
                           type=click.STRING,
                           prompt_suffix=": #").strip()
    settings.set_slack_token(token)
    settings.set_slack_channel(channel)

    try:
        auth_query = SlackAuthCheck()
        auth_query.execute()  # pylint: disable=no-value-for-parameter
        channel_query = SlackChannelListQuery()
        channel_query.execute()
        if channel not in channel_query.channels:
            raise click.ClickException("Channel does not exist")
    except Exception as exception:
        settings.reset_slack()
        raise exception

    click.secho("✓ Slack, hello {}! 🔌✨".format(auth_query.user),
                bold=True)
Exemple #3
0
def test_setup_does_not_erase_if_user_does_not_want(runner):
    result = runner.invoke(cli.main, ["account", "setup"],
                           input="\n".join(["n", "n"]))
    assert result.exit_code == ExitCode.NO_ERROR.value
    assert "Reset GitHub config?" in result.output
    assert "Reset Slack config?" in result.output
    settings = Settings()
    assert settings.is_github_valid()
    assert settings.is_slack_valid()
Exemple #4
0
def test_empty_settings():
    settings = Settings()
    assert not settings.is_github_valid()
    assert not settings.is_slack_valid()
    assert_empty_settings()
Exemple #5
0
def generate_scrum_report(report_dt):
    """
    Generate scrum report based on scrum report template

    Also copy the report in clipboard if wanted
    """
    report_settings = ScrumReportSettings()
    click.secho("Tips:", bold=True)
    click.echo("Рђб To customize report template, edit `{}`".format(
        report_settings.get_path()))
    click.echo("Рђб Begin line with an extra " +
               click.style("<space>", bold=True) + " to indent it")
    click.echo("")

    click.secho("GitHub's cheat sheet ­ЪўЈ:", bold=True)
    report_query = _exec_github_report_query(report_dt)
    if len(report_query.data) == 0:
        click.echo(
            "Рђб Sorry, nothing from GitHub may be you can ask your mum? ­ЪциРђЇ"
        )
    else:
        for contrib in report_query.get_contrib_str():
            click.echo("Рђб {}".format(contrib))
    click.echo("")

    data = {}
    questions = report_settings.get_questions()
    tpl = report_settings.get_template()
    suffix = "Рђб "

    click.secho("Report of {}".format(report_dt.date().isoformat()), bold=True)
    for idx, question in enumerate(questions):
        click.echo(
            click.style(question, bold=True) + " (empty line to move on)")
        answers = []
        while True:
            line = click.prompt("",
                                prompt_suffix=suffix,
                                default="",
                                show_default=False)
            if line == "":
                break
            line = suffix + line
            line = re.sub("^Рђб  ", "    РђБ ", line)
            answers.append(line)
        data["q{}".format(idx)] = question
        data["a{}".format(idx)] = "\n".join(answers)

    report_sections = []
    for section in tpl.get("sections", []):
        template = Template("\n".join(section))
        data["date"] = report_dt.date().isoformat()
        if "${github_report}" in template.template:
            data["github_report"] = report_query.tabulate()
        report_sections.append(template.safe_substitute(data))

    settings = Settings()
    if settings.is_slack_valid():
        if click.confirm("Send to Slack?", prompt_suffix=" "):
            try:
                first_query = None
                for section in report_sections:
                    query = SlackPostMessageQuery(section,
                                                  reply_to=first_query)
                    query.execute()
                    if first_query is None:
                        first_query = query
                query = SlackMessageLinkQuery(first_query)
                query.execute()
                click.secho("Sent! ­Ъцў {}".format(query.url), bold=True)
            except Exception as error:
                click.secho("Failed to send: {}".format(str(error)), bold=True)
                LOGGER.error(str(error))

    report = "\n".join(report_sections)
    if click.confirm("Copy to clipboard?", prompt_suffix=" "):
        try:
            pyperclip.copy(report)
            click.secho("Copied! ­Ъцў", bold=True)
        except Exception as error:
            click.echo(report)
            LOGGER.error(str(error))
            raise click.ClickException(
                "Not supported on your system, please `sudo apt-get install xclip`"
            )
    else:
        click.echo(report)