Skip to content

Commit

Permalink
feat: support gh refresh tokens
Browse files Browse the repository at this point in the history
Depends on codecov/shared#27
TODO: after that is merged update the sha reference in requirements.in

Adds support for github app refresh tokens

codecov/engineering-team#162
  • Loading branch information
giovanni-guidini committed Aug 17, 2023
1 parent 5df32f9 commit 93ea61a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
git+ssh://[email protected]/codecov/shared.git@6a8a33248804a9c101d34f417efda7c11e4bbe63#egg=shared
git+ssh://[email protected]/codecov/shared.git@680951c4849074db131353b251581ee03029a72a#egg=shared
git+ssh://[email protected]/codecov/[email protected]#egg=codecovopentelem
boto3
celery
Expand Down
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@680951c4849074db131353b251581ee03029a72a
# via -r requirements.in
six==1.15.0
# via
Expand Down
2 changes: 1 addition & 1 deletion services/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_token_refresh_callback(owner: Owner) -> Callable[[Dict], None]:
return None

service = owner.service
if service != "gitlab" and service != "gitlab_enterprise":
if service == "bitbucket" or service == "bitbucket_server":
return None

async def callback(new_token: Dict) -> None:
Expand Down
36 changes: 34 additions & 2 deletions services/tests/test_repository_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@


class TestRepositoryServiceTestCase(object):
def test_get_repo_provider_service(self, dbsession):
def test_get_repo_provider_service_github(self, dbsession):
repo = RepositoryFactory.create(
owner__unencrypted_oauth_token="testyftq3ovzkb3zmt823u3t04lkrt9w",
owner__service="github",
Expand All @@ -55,7 +55,39 @@ def test_get_repo_provider_service(self, dbsession):
}
assert res.data == expected_data
assert repo.owner.service == "github"
assert res._on_token_refresh is None # GH doesn't have callback implemented
assert res._on_token_refresh is not None
assert inspect.isawaitable(res._on_token_refresh(None))
assert res.token == {
"username": repo.owner.username,
"key": "testyftq3ovzkb3zmt823u3t04lkrt9w",
"secret": None,
}

def test_get_repo_provider_service_bitbucket(self, dbsession):
repo = RepositoryFactory.create(
owner__unencrypted_oauth_token="testyftq3ovzkb3zmt823u3t04lkrt9w",
owner__service="bitbucket",
name="example-python",
)
dbsession.add(repo)
dbsession.flush()
res = get_repo_provider_service(repo)
expected_data = {
"owner": {
"ownerid": repo.owner.ownerid,
"service_id": repo.owner.service_id,
"username": repo.owner.username,
},
"repo": {
"name": "example-python",
"using_integration": False,
"service_id": repo.service_id,
"repoid": repo.repoid,
},
}
assert res.data == expected_data
assert repo.owner.service == "bitbucket"
assert res._on_token_refresh is None
assert res.token == {
"username": repo.owner.username,
"key": "testyftq3ovzkb3zmt823u3t04lkrt9w",
Expand Down

0 comments on commit 93ea61a

Please sign in to comment.