Exemple #1
0
def init_git_dependent_config(config: Config, github: GitHub, git_repo: GitRepo):

    while(True):
        config.branch_to_be_released = prompt_enter_value("the name of the branch to be released")
        if(is_valid_branch(config)):
            break

    config.release_version = ""
    version_pattern = re.compile(r'[0-9]\.[0-9]\.[0-9]')
    while(not version_pattern.match(config.release_version)):
        config.release_version = prompt_enter_value("release version number without 'v' in front")

    config.next_version = ""
    while(not version_pattern.match(config.next_version)):
        config.next_version = prompt_enter_value("next version number (after releasing) without 'v' in front")

    config.build_folder = __get_build_folder(config)
    config.build_folder_abs = os.path.join(config.root_path, config.build_folder)
    config.build_artifacts_root_search_path = __get_build_artifacts_root_search_path(config)
    config.cobigenwiki_title_name = __get_cobigenwiki_title_name(config)
    config.tag_name = __get_tag_name(config) + config.release_version
    config.tag_core_name = __get_tag_name_specific_branch(config, config.branch_core)

    if git_repo.exists_tag(config.tag_name):
        log_error("Git tag " + config.tag_name + " already exists. Maybe you entered the wrong release version? Please fix the problem and try again.")
        sys.exit()

    config.issue_label_name = config.tag_name[:-7]

    config.expected_milestone_name = config.tag_name[:-7] + "-v" + config.release_version
    config.expected_core_milestone_name = config.tag_core_name[:-2] + "-v"
    milestone = github.find_release_milestone()
    if milestone:
        log_info("Milestone '"+milestone.title+"' found!")
    else:
        log_error("Milestone not found! Searched for milestone with name '" + config.expected_milestone_name+"'. Aborting...")
        sys.exit()

    while(True):
        github_issue_no: str = prompt_enter_value(
            "release issue number without # prefix in case you already created one or type 'new' to create an issue automatically")
        if github_issue_no == 'new':
            issue_text = "This issue has been automatically created. It serves as a container for all release related commits"
            config.github_issue_no = github.create_issue("Release " + config.expected_milestone_name, body=issue_text, milestone=milestone)
            if not config.github_issue_no:
                log_error("Could not create issue! Aborting...")
                sys.exit()
            else:
                log_info('Successfully created issue #' + str(github_issue_no))
            break
        else:
            try:
                if github.find_issue(int(github_issue_no)):
                    config.github_issue_no = int(github_issue_no)
                    log_info("Issue #" + str(config.github_issue_no) + " found remotely!")
                    break
                else:
                    log_error("Issue with number #" + str(config.github_issue_no) + " not found! Typo?")
            except ValueError:
                log_error("Please enter a number.")
        git_repo.reset()
        sys.exit()

#############################
__log_step("Create Tag...")
#############################
if config.dry_run:
    log_info_dry("Would create Git tag with name " + config.tag_name)
else:
    git_repo.create_tag_on_last_commit()
    git_repo.push()

#############################
__log_step("Close GitHub Milestone...")
#############################
milestone: Milestone = github.find_release_milestone()
if config.dry_run:
    log_info_dry("Would close the milestone: " + milestone.title)
else:
    if (milestone.state == "closed"):
        log_info("Milestone '" + milestone.title +
                 "' is already closed, please check.")
    else:
        milestone.edit(milestone.title, "closed", milestone.description)
        log_info("New status of Milestone '" + milestone.title + "' is: " +
                 milestone.state)

#############################
__log_step("Create new GitHub release...")
#############################
github.create_release(milestone, core_version_in_eclipse_pom)