Skip to content

Commit

Permalink
Allow just repository or sha (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaclarke committed Aug 19, 2021
1 parent 6dde555 commit 9cdd5ca
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 13 deletions.
3 changes: 2 additions & 1 deletion conbench/entities/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def create_github_context(sha, repository, github):
s.Index(
"commit_index",
Commit.sha,
Commit.repository,
unique=True,
)

Expand Down Expand Up @@ -126,7 +127,7 @@ def repository_to_name(repository):

def repository_to_url(repository):
name = repository_to_name(repository)
return f"https://github.com/{name}"
return f"https://github.com/{name}" if name else ""


def get_github_commit(repository, sha):
Expand Down
4 changes: 2 additions & 2 deletions conbench/entities/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ def create(data):
repository = repository_to_url(data["github"]["repository"])

# create if not exists
commit = Commit.first(sha=sha)
commit = Commit.first(sha=sha, repository=repository)
if not commit:
github = get_github_commit(repository, sha)
if github:
commit = Commit.create_github_context(sha, repository, github)
elif sha and repository:
elif sha or repository:
commit = Commit.create_unknown_context(sha, repository)
else:
commit = Commit.create_no_context()
Expand Down
60 changes: 55 additions & 5 deletions conbench/tests/api/test_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
from ...tests.helpers import _uuid


ARROW_REPO = "https://github.com/apache/arrow"
CONBENCH_REPO = "https://github.com/ursacomputing/conbench"


def _expected_entity(summary):
return _api_benchmark_entity(
summary.id,
Expand Down Expand Up @@ -411,14 +415,14 @@ def test_create_unknown_commit_context(self, client):
data = copy.deepcopy(self.valid_payload)
data["run_id"] = _uuid()
data["github"]["commit"] = "unknown commit"
data["github"]["repository"] = "https://github.com/apache/arrow"
data["github"]["repository"] = ARROW_REPO

# create benchmark with unknown commit context
response = client.post("/api/benchmarks/", json=data)
new_id = response.json["id"]
summary = Summary.one(id=new_id)
assert summary.run.commit.sha == "unknown commit"
assert summary.run.commit.repository == "https://github.com/apache/arrow"
assert summary.run.commit.repository == ARROW_REPO
assert summary.run.commit.parent == "unknown"
location = "http://localhost/api/benchmarks/%s/" % new_id
self.assert_201_created(response, _expected_entity(summary), location)
Expand All @@ -429,7 +433,7 @@ def test_create_unknown_commit_context(self, client):
new_id = response.json["id"]
summary = Summary.one(id=new_id)
assert summary.run.commit.sha == "unknown commit"
assert summary.run.commit.repository == "https://github.com/apache/arrow"
assert summary.run.commit.repository == ARROW_REPO
assert summary.run.commit.parent == "unknown"
location = "http://localhost/api/benchmarks/%s/" % new_id
self.assert_201_created(response, _expected_entity(summary), location)
Expand All @@ -445,7 +449,7 @@ def test_create_different_git_repo_format(self, client):
new_id = response.json["id"]
summary = Summary.one(id=new_id)
assert summary.run.commit.sha == "testing repository with git@g"
assert summary.run.commit.repository == "https://github.com/apache/arrow"
assert summary.run.commit.repository == ARROW_REPO
assert summary.run.commit.parent == "unknown"
location = "http://localhost/api/benchmarks/%s/" % new_id
self.assert_201_created(response, _expected_entity(summary), location)
Expand All @@ -461,7 +465,53 @@ def test_create_repo_not_full_url(self, client):
new_id = response.json["id"]
summary = Summary.one(id=new_id)
assert summary.run.commit.sha == "testing repository with just org/repo"
assert summary.run.commit.repository == "https://github.com/apache/arrow"
assert summary.run.commit.repository == ARROW_REPO
assert summary.run.commit.parent == "unknown"
location = "http://localhost/api/benchmarks/%s/" % new_id
self.assert_201_created(response, _expected_entity(summary), location)

def test_create_allow_just_repository(self, client):
self.authenticate(client)
data = copy.deepcopy(self.valid_payload)
data["run_id"] = _uuid()
data["github"]["commit"] = ""
data["github"]["repository"] = ARROW_REPO

response = client.post("/api/benchmarks/", json=data)
new_id = response.json["id"]
summary = Summary.one(id=new_id)
assert summary.run.commit.sha == ""
assert summary.run.commit.repository == ARROW_REPO
assert summary.run.commit.parent == "unknown"
location = "http://localhost/api/benchmarks/%s/" % new_id
self.assert_201_created(response, _expected_entity(summary), location)

# And again with a different repository with an empty sha
data["run_id"] = _uuid()
data["github"]["commit"] = ""
data["github"]["repository"] = CONBENCH_REPO

response = client.post("/api/benchmarks/", json=data)
new_id = response.json["id"]
summary = Summary.one(id=new_id)
assert summary.run.commit.sha == ""
assert summary.run.commit.repository == CONBENCH_REPO
assert summary.run.commit.parent == "unknown"
location = "http://localhost/api/benchmarks/%s/" % new_id
self.assert_201_created(response, _expected_entity(summary), location)

def test_create_allow_just_sha(self, client):
self.authenticate(client)
data = copy.deepcopy(self.valid_payload)
data["run_id"] = _uuid()
data["github"]["commit"] = "something something"
data["github"]["repository"] = ""

response = client.post("/api/benchmarks/", json=data)
new_id = response.json["id"]
summary = Summary.one(id=new_id)
assert summary.run.commit.sha == "something something"
assert summary.run.commit.repository == ""
assert summary.run.commit.parent == "unknown"
location = "http://localhost/api/benchmarks/%s/" % new_id
self.assert_201_created(response, _expected_entity(summary), location)
Expand Down
4 changes: 2 additions & 2 deletions conbench/tests/entities/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def test_repository_to_name():

def test_repository_to_url():
expected = "https://github.com/apache/arrow"
assert repository_to_url(None) == "https://github.com/"
assert repository_to_url("") == "https://github.com/"
assert repository_to_url(None) == ""
assert repository_to_url("") == ""
assert repository_to_url("blah blah") == "https://github.com/blah blah"
assert repository_to_url("apache/arrow") == expected
assert repository_to_url("https://github.com/apache/arrow") == expected
Expand Down
2 changes: 1 addition & 1 deletion conbench/tests/entities/test_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from ...tests.helpers import _uuid


REPO = "arrow"
REPO = "https://github.com/org/something"
MACHINE = "diana-2-4-17179869184"

COMMIT_INDEX = """WITH ordered_commits AS
Expand Down
2 changes: 1 addition & 1 deletion conbench/tests/entities/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ...tests.helpers import _uuid


REPO = "arrow"
REPO = "https://github.com/org/something"
MACHINE = "diana-2-4-17179869184"


Expand Down
25 changes: 25 additions & 0 deletions migrations/versions/659d5e9ca5a7_alter_commit_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""alter commit index
Revision ID: 659d5e9ca5a7
Revises: fb23ffd732d3
Create Date: 2021-08-19 10:50:53.545163
"""
from alembic import op


# revision identifiers, used by Alembic.
revision = "659d5e9ca5a7"
down_revision = "fb23ffd732d3"
branch_labels = None
depends_on = None


def upgrade():
op.drop_index("commit_index", table_name="commit")
op.create_index("commit_index", "commit", ["sha", "repository"], unique=True)


def downgrade():
op.drop_index("commit_index", table_name="commit")
op.create_index("commit_index", "commit", ["sha"], unique=False)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setuptools.setup(
name="conbench",
version="1.7.0",
version="1.8.0",
description="Continuous Benchmarking (CB) Framework",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 9cdd5ca

Please sign in to comment.