Example #1
0
def main(args: argparse.Namespace) -> int:
    """Main entry point."""
    set_log_level(args.verbose)
    pr_info = PullRequestInfo(
        repo="ARMMbed/mbed-targets",
        head_branch=args.head_branch,
        base_branch=args.base_branch,
        subject=args.pr_subject,
        body=args.pr_description,
    )
    try:
        online_boards = Boards.from_online_database()
        if BOARD_DATABASE_PATH.exists():
            offline_boards = Boards.from_offline_database()
            added, removed = get_boards_added_or_removed(
                offline_boards, online_boards)
            if not (added or removed):
                logger.info("No changes to commit. Exiting.")
                return 0

            news_file_path = write_news_file_from_boards(added, removed)
        else:
            news_file_path = create_news_file(
                "Offline board database updated.", NewsType.feature)

        save_board_database(online_boards.json_dump(), BOARD_DATABASE_PATH)
        git_commit_and_push([BOARD_DATABASE_PATH, news_file_path],
                            pr_info.head_branch, pr_info.subject)
        raise_github_pr(pr_info)
        return 0
    except ToolsError as tools_error:
        log_exception(logger, tools_error)
        return 1
Example #2
0
def main(args: argparse.Namespace) -> int:
    """Main entry point."""
    set_log_level(args.verbose)
    try:
        online_boards = Boards.from_online_database()
        offline_boards = Boards.from_offline_database()
        result = compare_databases(offline_boards, online_boards)
        if not (result.boards_added or result.boards_removed or result.boards_modified):
            logger.info("No changes to commit. Exiting.")
            return 0

        news_file_text = create_news_file_text_from_result(result)
        create_news_file(news_file_text, NewsType.feature)
        save_board_database(online_boards.json_dump(), BOARD_DATABASE_PATH)
        return 0
    except ToolsError as tools_error:
        log_exception(logger, tools_error)
        return 1
    def test_creates_a_file_with_available_file_name_and_returns_its_path(self, _write_file, determine_news_file_path):
        news_file_path = pathlib.Path("some/1234501.feature")
        determine_news_file_path.return_value = news_file_path
        news_text = "Cool feature"
        news_type = NewsType.feature

        file_path = create_news_file(news_text, news_type)

        self.assertEqual(file_path, news_file_path)
        determine_news_file_path.assert_called_once_with(news_type)
        _write_file.assert_called_once_with(file_path, news_text)
Example #4
0
def write_news_file_from_boards(added: Boards, removed: Boards) -> Path:
    """Creates and writes a news file from the added and removed boards.

    Args:
        added: added Boards
        removed: removed Boards
    """
    news_item_text_added = create_news_item_text("Targets added: ", added)
    news_item_text_removed = create_news_item_text("Targets removed: ",
                                                   removed)
    news_item_text = f"{news_item_text_added}. {news_item_text_removed}"
    return create_news_file(news_item_text, NewsType.feature)