Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mark commits coming from forks in branch #217

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
https://github.com/codecov/shared/archive/954a9ba17722f73f86f3d3bb3367f80d887fc800.tar.gz#egg=shared
https://github.com/codecov/shared/archive/8011818d251e23e3a59a1d821ce3c227d12fbc14.tar.gz#egg=shared
https://github.com/codecov/opentelem-python/archive/refs/tags/v0.0.4a1.tar.gz#egg=codecovopentelem
boto3
celery
Expand Down
14 changes: 9 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile requirements.in
Expand Down Expand Up @@ -98,10 +98,12 @@ django-six==1.0.5
# via
# django-admin
# django-excel-response2
ecdsa==0.16.1
ecdsa==0.18.0
# via tlslite-ng
excel-base==1.0.4
# via django-excel-response2
exceptiongroup==1.2.0
# via pytest
factory-boy==3.2.0
# via -r requirements.in
faker==8.8.2
Expand Down Expand Up @@ -331,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 All @@ -340,7 +344,7 @@ screen==1.0.1
# via excel-base
sentry-sdk==1.19.1
# via -r requirements.in
shared @ https://github.com/codecov/shared/archive/954a9ba17722f73f86f3d3bb3367f80d887fc800.tar.gz
shared @ https://github.com/codecov/shared/archive/8011818d251e23e3a59a1d821ce3c227d12fbc14.tar.gz
# via -r requirements.in
six==1.15.0
# via
Expand Down Expand Up @@ -380,7 +384,7 @@ timeconvert==3.0.13
# via excel-base
timestring==1.6.4
# via -r requirements.in
tlslite-ng==0.8.0a39
tlslite-ng==0.8.0b1
# via shared
tomli==2.0.1
# via pytest
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