diff --git a/requirements.in b/requirements.in index 38ce5c9c1..f527262bd 100644 --- a/requirements.in +++ b/requirements.in @@ -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 diff --git a/requirements.txt b/requirements.txt index 29568307e..64f5f7445 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/services/repository.py b/services/repository.py index f2ea5b83d..b7d425d11 100644 --- a/services/repository.py +++ b/services/repository.py @@ -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( diff --git a/services/tests/test_repository_service.py b/services/tests/test_repository_service.py index 481769ebe..2eaa9952f 100644 --- a/services/tests/test_repository_service.py +++ b/services/tests/test_repository_service.py @@ -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), @@ -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), @@ -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@email.com", + "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