Skip to content

Commit

Permalink
Merge branch 'main' into scott/bundle-analysis-processor
Browse files Browse the repository at this point in the history
* main:
  fix: mark commits coming from forks in branch (#217)
  • Loading branch information
scott-codecov committed Dec 15, 2023
2 parents c4f9c63 + 8342820 commit 2721693
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,9 @@ requests==2.31.0
respx==0.20.2
# via -r requirements.in
rfc3986[idna2008]==1.4.0
# via httpx
# via
# httpx
# rfc3986
rsa==4.7.2
# via google-auth
s3transfer==0.3.4
Expand Down
8 changes: 7 additions & 1 deletion services/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,13 @@ async def update_commit_from_provider_info(repository_service, commit):
commit_updates = await repository_service.get_pull_request(
pullid=commit.pullid
)
commit.branch = commit_updates["head"]["branch"]
# There's a chance that the commit comes from a fork
# so we append the branch name with the fork slug
branch_name = commit_updates["head"]["branch"]
# TODO: 'slug' is in a `.get` because currently only GitHub returns that info
if commit_updates["head"].get("slug") != commit_updates["base"].get("slug"):
branch_name = commit_updates["head"]["slug"] + ":" + branch_name
commit.branch = branch_name
commit.merged = False
else:
possible_branches = await repository_service.get_best_effort_branches(
Expand Down
65 changes: 63 additions & 2 deletions services/tests/test_repository_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,10 @@ async def test_update_commit_from_provider_info_no_author_id(
"parents": [possible_parent_commit.commitid],
"timestamp": "2018-07-09T23:39:20Z",
}
get_pull_request_result = {"head": {"branch": "newbranchyeah"}}
get_pull_request_result = {
"head": {"branch": "newbranchyeah"},
"base": {"branch": "main"},
}
repository_service = mocker.MagicMock(
get_commit=mock.AsyncMock(return_value=f),
get_pull_request=mock.AsyncMock(return_value=get_pull_request_result),
Expand Down Expand Up @@ -796,7 +799,10 @@ async def test_update_commit_from_provider_info_with_author_id(
"parents": [possible_parent_commit.commitid],
"timestamp": "2018-07-09T23:39:20Z",
}
get_pull_request_result = {"head": {"branch": "newbranchyeah"}}
get_pull_request_result = {
"head": {"branch": "newbranchyeah"},
"base": {"branch": "main"},
}
repository_service = mocker.MagicMock(
get_commit=mock.AsyncMock(return_value=f),
get_pull_request=mock.AsyncMock(return_value=get_pull_request_result),
Expand All @@ -815,6 +821,61 @@ async def test_update_commit_from_provider_info_with_author_id(
assert commit.timestamp == datetime(2018, 7, 9, 23, 39, 20)
assert commit.author.username == "author_username"

@pytest.mark.asyncio
async def test_update_commit_from_provider_info_pull_from_fork(
self, dbsession, mocker
):
possible_parent_commit = CommitFactory.create(
message="possible_parent_commit", pullid=None
)
commit = CommitFactory.create(
message="",
author=None,
pullid=1,
totals=None,
_report_json=None,
repository=possible_parent_commit.repository,
)
dbsession.add(possible_parent_commit)
dbsession.add(commit)
dbsession.flush()
dbsession.refresh(commit)
f = {
"author": {
"id": "author_id",
"username": "author_username",
"email": "[email protected]",
"name": "Mario",
},
"message": "This message is brought to you by",
"parents": [possible_parent_commit.commitid],
"timestamp": "2018-07-09T23:39:20Z",
}
get_pull_request_result = {
"head": {"branch": "main", "slug": f"some-guy/{commit.repository.name}"},
"base": {
"branch": "main",
"slug": f"{commit.repository.owner.username}/{commit.repository.name}",
},
}
repository_service = mocker.MagicMock(
get_commit=mock.AsyncMock(return_value=f),
get_pull_request=mock.AsyncMock(return_value=get_pull_request_result),
)
await update_commit_from_provider_info(repository_service, commit)
dbsession.flush()
dbsession.refresh(commit)
assert commit.message == "This message is brought to you by"
assert commit.pullid == 1
assert commit.totals is None
assert commit.report_json == {}
assert commit.branch == f"some-guy/{commit.repository.name}:main"
assert commit.parent_commit_id == possible_parent_commit.commitid
assert commit.state == "complete"
assert commit.author is not None
assert commit.timestamp == datetime(2018, 7, 9, 23, 39, 20)
assert commit.author.username == "author_username"

@pytest.mark.asyncio
async def test_update_commit_from_provider_info_bitbucket_merge(
self, dbsession, mocker
Expand Down

0 comments on commit 2721693

Please sign in to comment.