def create_approval(project_config_file, env):
    env = create_approval_environment_variables(env)
    with open(project_config_file) as json_data_file:
        project_data = load_project_configuration(json_data_file)

        if env["artifact_sha256"] 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_sha256"] = latest_artifact_for_commit(response)
            print(
                f"Found artifact {env['artifact_sha256']} as latest artifact for source commit {env['target_src_commit']}"
            )

        commit_list = list_commits_between(
            repo_at(env["repo_path"]),
            target_commit=env["target_src_commit"],
            base_commit=env["base_src_commit"])

        approval_json = build_approval_json(
            artifact_sha256=env["artifact_sha256"],
            description=env["description"],
            is_approved=env["is_externally_approved"],
            src_commit_list=commit_list)

        url = ApiSchema.url_for_approvals(env["host"], project_data)
        http_post_payload(url, approval_json, env["api_token"])
Beispiel #2
0
 def __call__(self):
     commit_list = list_commits_between(repo_at(self.src_repo_root.value),
                                        self.newest_src_commitish.value,
                                        self.oldest_src_commitish.value)
     payload = {
         "artifact_sha256":
         self.fingerprint.sha,
         "description":
         self.description.value,
         "src_commit_list":
         commit_list,
         "user_data":
         self.user_data.value,
         "approvals": [{
             "state": self.approval_state(),
             "comment": self.description.value,
             "approved_by": "External",
             "approval_url": "undefined"
         }]
     }
     url = ApiSchema.url_for_approvals(self.host.value, self.merkelypipe)
     http_post_payload(url, payload, self.api_token.value)
     return 'Posting', url, payload
def test_url_for_approvals():
    partial_project_data = {"name": "hadroncollider", "owner": "cern"}
    url = ApiSchema.url_for_approvals(host="http://localhost",
                                      project_data=partial_project_data)
    assert url == "http://localhost/api/v1/projects/cern/hadroncollider/approvals/"