Ejemplo n.º 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.merge("master", config.branch_to_be_released)
git_repo.push(True)

#############################
__log_step("Set next release version...")
#############################
git_repo.checkout(config.branch_to_be_released)
changed_files = maven.set_version(config.next_version + "-SNAPSHOT")
git_repo.add(changed_files)
git_repo.commit("Set next development version")
git_repo.push(True)

#############################
__log_step("Close GitHub release issue...")
#############################
if config.dry_run:
    log_info_dry("Would close GitHub release issue with no #" +
                 str(config.github_issue_no))
else:
    release_issue = github.find_issue(config.github_issue_no)
    # will never find closed issues
    closing_comment = "Automatically processed.\n\nThe decisions taken by the developer and the context of the decisions throughout the script:\n\n"
    for message in report_messages:
        closing_comment = closing_comment + "* " + message + "\n"
    release_issue.create_comment(closing_comment)
    release_issue.edit(state="closed")
    log_info("Closed issue #" + str(release_issue.number) + ": " +
             release_issue.title)

log_info("Congratz! A new release! Script executed successfully!")