Exemplo n.º 1
0
def workflow(changed_files, repo_str):
    global current_repo, current_user
    current_repo = Repo(name=repo_str, user=current_user, status="starting", started_at=datetime.now(), progress=10)
    current_repo.save()
    dolog("deleting the repo if exists")
    change_status("preparation", 10)
    delete_forked_repo(repo_str)
    time.sleep(60)  # for GitHub to avoid the unknown issues
    dolog("forking the repo %s" % repo_str)
    change_status("forking", 20)
    repo_url = fork_repo(repo_str)
    dolog("cloning the repo %s" % repo_url)
    change_status("cloning", 30)
    clone_repo(repo_url)
    # fork_cleanup()
    change_status("updating the fork", 40)
    update_fork(repo_str)  # update from upstream as the cloned repo is an old fork due to Github limitation
    dolog("getting jar configurations")
    change_status("getting configurations", 50)
    target_files, jar_command = get_jar_config(os.path.join(get_repo_abs_path(), 'jar.cfg'))
    if target_files is None or jar_command is None:
        dolog("get jar config failed")
        change_status("Error getting configurations", 100)
        delete_local_copy()
        return "get jar config failed"
    else:
        change_status("configuration parsed", 60)
    dolog("running if target")
    change_status("running if target", 70)
    is_found, msg = run_if_target(changed_files, target_files, jar_command)
    dolog("after running")
    if is_found:
        dolog("is found")
        change_status("pushing changes", 80)
        push_changes()
        dolog("after pushing the changes")
        change_status("creating pull request", 90)
        if create_pull_request(repo_str):
            dolog("pull request is True")
            change_status("pull request created", 100)
            current_repo.completed_at = datetime.now()
            current_repo.save()
            msg += " And pull request is created"
            dolog("deleting the forked repo attempt")
        else:
            dolog("pull request is False")
            change_status("pull failed to be created", 100)
            current_repo.completed_at = datetime.now()
            current_repo.save()
            msg += " And pull request failed to be created"
    else:
        change_status("not found", 100)
        dolog("not found")
        current_repo.completed_at = datetime.now()
        current_repo.save()
    return msg