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

Use get_branch in get_behind_by instead of get_branches #79

Merged
merged 3 commits into from
Aug 30, 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.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ s3transfer==0.3.4
# via boto3
sentry-sdk==1.19.1
# via -r requirements.in
shared @ git+ssh://[email protected]/codecov/shared.git@6a8a33248804a9c101d34f417efda7c11e4bbe63
shared @ git+ssh://[email protected]/codecov/shared.git@4f65b0040ab6bb3dba2190ce544ade9a0ea3e354
# via -r requirements.in
six==1.15.0
# via
Expand Down
26 changes: 16 additions & 10 deletions services/comparison/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

from shared.reports.changes import get_changes_using_rust, run_comparison_using_rust
from shared.reports.types import Change
from shared.torngit.exceptions import (
TorngitClientError,
TorngitClientGeneralError,
TorngitError,
TorngitObjectNotFoundError,
)

from database.enums import CompareCommitState
from database.models import CompareCommit
Expand Down Expand Up @@ -162,25 +168,25 @@ async def get_behind_by(self):
"Comparison does not have provider pull request information, unable to get behind_by"
)
return None
branch_to_get = provider_pull["base"]["branch"]
if self._branch is None:
branches = await self.repository_service.get_branches()
branch = [
b for b in branches if b[0] == provider_pull["base"]["branch"]
]

if len(branch) == 0:
try:
branch_response = await self.repository_service.get_branch(
branch_to_get
)
except TorngitClientGeneralError:
log.warning(
"Unable to find branch in list of branches on repo",
"Unable to fetch base branch from Git provider",
extra=dict(
branch=provider_pull["base"]["branch"],
branch=branch_to_get,
),
)
return None

self._branch = branch
self._branch = branch_response

distance = await self.repository_service.get_distance_in_commits(
self._branch[0][1],
self._branch["sha"],
self.comparison.base.commit.commitid,
with_commits=False,
)
Expand Down
7 changes: 6 additions & 1 deletion services/comparison/tests/unit/test_behind_by.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from shared.torngit.exceptions import TorngitClientGeneralError

from services.comparison import ComparisonProxy

Expand Down Expand Up @@ -36,7 +37,11 @@ async def test_get_behind_by_no_provider_pull(self, mocker):

@pytest.mark.asyncio
async def test_get_behind_by_no_matching_branches(self, mocker, mock_repo_provider):
mock_repo_provider.get_branches.return_value = []
mock_repo_provider.get_branch.side_effect = TorngitClientGeneralError(
404,
None,
"Branch not found",
)
mocker.patch(
"services.comparison.get_repo_provider_service",
return_value=mock_repo_provider,
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -197,29 +197,60 @@ interactions:
method: POST
uri: https://gitlab.com/api/v4/projects/47404140/merge_requests/1/notes
response:
content: "{\"id\":1457135397,\"type\":null,\"body\":\"## [Codecov](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1?src=pr\\u0026el=h1\\u0026utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French)
Report\\n\\u003e Merging [#1](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1?src=pr\\u0026el=desc\\u0026utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French)
(0b6a213) into [main](https://app.codecov.io/gl/joseph-sentry/example-python/commit/0fc784af11c401449e56b24a174bae7b9af86c98?el=desc\\u0026utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French)
(0fc784a) will **increase** coverage by `10.00%`.\\n\\u003e The diff coverage
is `n/a`.\\n\\n[![Impacted file tree graph](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1/graphs/tree.svg?width=650\\u0026height=150\\u0026src=pr\\u0026token=abcdefghij\\u0026utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French)](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1?src=pr\\u0026el=tree\\u0026utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French)\\n\\n```diff\\n@@
\ Coverage Diff @@\\n## main #1
\ +/- ##\\n=============================================\\n+ Coverage
\ 50.00% 60.00% +10.00% \\n+ Complexity 11 10 -1
\ \\n=============================================\\n Files 2
\ 2 \\n Lines 6 10 +4 \\n
\ Branches 0 1 +1 \\n=============================================\\n+
Hits 3 6 +3 \\n Misses 3 3
\ \\n- Partials 0 1 +1 \\n```\\n\\n|
Flag | Coverage \u0394 | Complexity \u0394 | |\\n|---|---|---|---|\\n| integration
| `?` | `?` | |\\n| unit | `100.00% \\u003c\xF8\\u003e (?)` | `0.00 \\u003c\xF8\\u003e
(?)` | |\\n\\nFlags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French#carryforward-flags-in-the-pull-request-comment)
to find out more.\\n\\n[see 2 files with indirect coverage changes](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1/indirect-changes?src=pr\\u0026el=tree-more\\u0026utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French)\\n\\n------\\n\\n[Continue
to review full report in Codecov by Sentry](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1?src=pr\\u0026el=continue\\u0026utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French).\\n\\u003e
**Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French)\\n\\u003e
`\u0394 = absolute \\u003crelative\\u003e (impact)`, `\xF8 = not affected`,
`? = missing data`\\n\\u003e Powered by [Codecov](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1?src=pr\\u0026el=footer\\u0026utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French).
Last update [0fc784a...0b6a213](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1?src=pr\\u0026el=lastupdated\\u0026utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French).
Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French).\",\"attachment\":null,\"author\":{\"id\":15014576,\"username\":\"joseph-sentry\",\"name\":\"joseph-sentry\",\"state\":\"active\",\"avatar_url\":\"https://secure.gravatar.com/avatar/b8db468edebbae1ffa228d3095c230c5?s=80\\u0026d=identicon\",\"web_url\":\"https://gitlab.com/joseph-sentry\"},\"created_at\":\"2023-07-04T17:54:03.693Z\",\"updated_at\":\"2023-07-04T17:54:03.693Z\",\"system\":false,\"noteable_id\":234535703,\"noteable_type\":\"MergeRequest\",\"project_id\":47404140,\"resolvable\":false,\"confidential\":false,\"internal\":false,\"noteable_iid\":1,\"commands_changes\":{}}"
content: "{\"id\":1457135397,\"type\":null,\"body\":\"## [Codecov](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1?src=pr\\\
u0026el=h1\\u0026utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\\
u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French) Report\\n\\u003e Merging\
\ [#1](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1?src=pr\\\
u0026el=desc\\u0026utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\\
u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French) (0b6a213) into [main](https://app.codecov.io/gl/joseph-sentry/example-python/commit/0fc784af11c401449e56b24a174bae7b9af86c98?el=desc\\\
u0026utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\\
u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French) (0fc784a) will **increase**\
\ coverage by `10.00%`.\\n\\u003e The diff coverage is `n/a`.\\n\\n[![Impacted\
\ file tree graph](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1/graphs/tree.svg?width=650\\\
u0026height=150\\u0026src=pr\\u0026token=abcdefghij\\u0026utm_medium=referral\\\
u0026utm_source=gitlab\\u0026utm_content=comment\\u0026utm_campaign=pr+comments\\\
u0026utm_term=Gina+French)](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1?src=pr\\\
u0026el=tree\\u0026utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\\
u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French)\\n\\n```diff\\n@@\
\ Coverage Diff @@\\n## main #1\
\ +/- ##\\n=============================================\\n+ Coverage\
\ 50.00% 60.00% +10.00% \\n+ Complexity 11 10 \
\ -1 \\n=============================================\\n Files \
\ 2 2 \\n Lines 6 10 +4\
\ \\n Branches 0 1 +1 \\n=============================================\\\
n+ Hits 3 6 +3 \\n Misses 3 \
\ 3 \\n- Partials 0 1 +1 \\n```\\\
n\\n| Flag | Coverage \u0394 | Complexity \u0394 | |\\n|---|---|---|---|\\n|\
\ integration | `?` | `?` | |\\n| unit | `100.00% \\u003c\xF8\\u003e (?)` |\
\ `0.00 \\u003c\xF8\\u003e (?)` | |\\n\\nFlags with carried forward coverage\
\ won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral\\\
u0026utm_source=gitlab\\u0026utm_content=comment\\u0026utm_campaign=pr+comments\\\
u0026utm_term=Gina+French#carryforward-flags-in-the-pull-request-comment) to\
\ find out more.\\n\\n[see 2 files with indirect coverage changes](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1/indirect-changes?src=pr\\\
u0026el=tree-more\\u0026utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\\
u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French)\\n\\n------\\n\\n[Continue\
\ to review full report in Codecov by Sentry](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1?src=pr\\\
u0026el=continue\\u0026utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\\
u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French).\\n\\u003e **Legend**\
\ - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral\\\
u0026utm_source=gitlab\\u0026utm_content=comment\\u0026utm_campaign=pr+comments\\\
u0026utm_term=Gina+French)\\n\\u003e `\u0394 = absolute \\u003crelative\\u003e\
\ (impact)`, `\xF8 = not affected`, `? = missing data`\\n\\u003e Powered by\
\ [Codecov](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1?src=pr\\\
u0026el=footer\\u0026utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\\
u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French). Last update [0fc784a...0b6a213](https://app.codecov.io/gl/joseph-sentry/example-python/pull/1?src=pr\\\
u0026el=lastupdated\\u0026utm_medium=referral\\u0026utm_source=gitlab\\u0026utm_content=comment\\\
u0026utm_campaign=pr+comments\\u0026utm_term=Gina+French). Read the [comment\
\ docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral\\\
u0026utm_source=gitlab\\u0026utm_content=comment\\u0026utm_campaign=pr+comments\\\
u0026utm_term=Gina+French).\",\"attachment\":null,\"author\":{\"id\":15014576,\"\
username\":\"joseph-sentry\",\"name\":\"joseph-sentry\",\"state\":\"active\"\
,\"avatar_url\":\"https://secure.gravatar.com/avatar/b8db468edebbae1ffa228d3095c230c5?s=80\\\
u0026d=identicon\",\"web_url\":\"https://gitlab.com/joseph-sentry\"},\"created_at\"\
:\"2023-07-04T17:54:03.693Z\",\"updated_at\":\"2023-07-04T17:54:03.693Z\",\"\
system\":false,\"noteable_id\":234535703,\"noteable_type\":\"MergeRequest\"\
,\"project_id\":47404140,\"resolvable\":false,\"confidential\":false,\"internal\"\
:false,\"noteable_iid\":1,\"commands_changes\":{}}"
headers:
CF-Cache-Status:
- DYNAMIC
Expand Down Expand Up @@ -270,4 +301,79 @@ interactions:
- '0.228506'
http_version: HTTP/1.1
status_code: 201
- request:
body: ''
headers:
accept:
- application/json
accept-encoding:
- gzip, deflate
connection:
- keep-alive
host:
- gitlab.com
user-agent:
- Default
method: GET
uri: https://gitlab.com/api/v4/projects/47404140/repository/branches/main
response:
content: '{"message":"401 Unauthorized"}'
headers:
CF-Cache-Status:
- MISS
CF-RAY:
- 7fef2fd0182436fe-YYZ
Cache-Control:
- no-cache
Connection:
- keep-alive
Content-Length:
- '30'
Content-Security-Policy:
- default-src 'none'
Content-Type:
- application/json
Date:
- Wed, 30 Aug 2023 18:44:44 GMT
GitLab-LB:
- fe-05-lb-gprd
GitLab-SV:
- localhost
NEL:
- '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}'
RateLimit-Limit:
- '2000'
RateLimit-Observed:
- '2'
RateLimit-Remaining:
- '1998'
RateLimit-Reset:
- '1693421144'
RateLimit-ResetTime:
- Wed, 30 Aug 2023 18:45:44 GMT
Referrer-Policy:
- strict-origin-when-cross-origin
Report-To:
- '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=lBgieih4yF%2BSFqCVeTidu8Y1w18hb7BV63ktECkxzQPrULx2APCFXvtqQDV6ZmRnfTxppDY%2F15MRyjs064ja6G4RylNKxJlsQ8C7GUpx67j3H%2BfnNW7ugAHn574%3D"}],"group":"cf-nel","max_age":604800}'
Server:
- cloudflare
Set-Cookie:
- _cfuvid=0RVizv.CnCUUI1sQDhOigxGHiJY1v6BbpkmTQn7RUNM-1693421084336-0-604800000;
path=/; domain=.gitlab.com; HttpOnly; Secure; SameSite=None
Strict-Transport-Security:
- max-age=31536000
Vary:
- Origin, Accept-Encoding
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- SAMEORIGIN
X-Gitlab-Meta:
- '{"correlation_id":"0a55ef3f31f3613df4edf90f82a78c20","version":"1"}'
X-Request-Id:
- 0a55ef3f31f3613df4edf90f82a78c20
X-Runtime:
- '0.034387'
http_version: HTTP/1.1
status_code: 401
version: 1
Loading
Loading