def create_release(project_config_file):
    env = create_release_environment_variables()
    with open(project_config_file) as json_data_file:
        project_data = load_project_configuration(json_data_file)

        if env["artifact_sha"] is None:
            src_commit = commit_for_commitish(repo_at(env["repo_path"]),
                                              env["target_src_commit"])
            response = get_artifacts_for_commit(env["host"], env["api_token"],
                                                project_data, src_commit)
            env["artifact_sha"] = latest_artifact_for_commit(response)
            print(
                f"Found artifact {env['artifact_sha']} as latest artifact for source commit {env['target_src_commit']}"
            )

        commit_list = list_commits_between(repo_at(env["repo_path"]),
                                           env["target_src_commit"],
                                           env["base_src_commit"])
        release_json = build_release_json(env["artifact_sha"],
                                          env["description"], commit_list)
        url = ApiSchema.url_for_releases(env["host"], project_data)
        http_post_payload(url, release_json, env["api_token"])
Esempio n. 2
0
def test_url_for_releases():
    partial_project_data = {"name": "hadroncollider", "owner": "cern"}
    url = ApiSchema.url_for_releases(host="http://localhost",
                                     project_data=partial_project_data)
    assert url == "http://localhost/api/v1/projects/cern/hadroncollider/releases/"