Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit ff7cbca

Browse files
authored
gitlab oauth scope setting (#613)
1 parent 7bed118 commit ff7cbca

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

codecov/settings_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@
451451
GITLAB_REDIRECT_URI = get_config(
452452
"gitlab", "redirect_uri", default="https://codecov.io/login/gitlab"
453453
)
454-
454+
GITLAB_SCOPE = get_config("gitlab", "scope", default="api")
455455
GITLAB_BOT_KEY = get_config("gitlab", "bot", "key")
456456
GITLAB_TOKENLESS_BOT_KEY = get_config(
457457
"gitlab", "bots", "tokenless", "key", default=GITLAB_BOT_KEY

codecov_auth/tests/unit/views/test_gitlab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_get_gitlab_redirect(client, settings, mock_redis, mocker):
3333
assert res.status_code == 302
3434
assert (
3535
res.url
36-
== f"https://gitlab.com/oauth/authorize?response_type=code&client_id=testfiuozujcfo5kxgigugr5x3xxx2ukgyandp16x6w566uits7f32crzl4yvmth&redirect_uri=http%3A%2F%2Flocalhost%2Flogin%2Fgitlab&state={state}"
36+
== f"https://gitlab.com/oauth/authorize?response_type=code&client_id=testfiuozujcfo5kxgigugr5x3xxx2ukgyandp16x6w566uits7f32crzl4yvmth&redirect_uri=http%3A%2F%2Flocalhost%2Flogin%2Fgitlab&state={state}&scope=api"
3737
)
3838

3939

codecov_auth/tests/unit/views/test_gitlab_enterprise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_get_gle_redirect(client, settings, mock_redis, mocker):
3737
assert res.status_code == 302
3838
assert (
3939
res.url
40-
== f"https://my.gitlabenterprise.com/oauth/authorize?response_type=code&client_id=testfiuozujcfo5kxgigugr5x3xxx2ukgyandp16x6w566uits7f32crzl4yvmth&redirect_uri=http%3A%2F%2Flocalhost%2Flogin%2Fgle&state={state}"
40+
== f"https://my.gitlabenterprise.com/oauth/authorize?response_type=code&client_id=testfiuozujcfo5kxgigugr5x3xxx2ukgyandp16x6w566uits7f32crzl4yvmth&redirect_uri=http%3A%2F%2Flocalhost%2Flogin%2Fgle&state={state}&scope=api"
4141
)
4242
mock_get_config.assert_called_with("gitlab_enterprise", "url")
4343

codecov_auth/views/gitlab.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from shared.torngit.exceptions import TorngitError
1313

1414
from codecov_auth.views.base import LoginMixin, StateMixin
15+
from utils.config import get_config
1516

1617
log = logging.getLogger(__name__)
1718

@@ -40,11 +41,16 @@ def get_url_to_redirect_to(self):
4041
redirect_info = self.redirect_info
4142
base_url = urljoin(redirect_info["repo_service"].service_url, "oauth/authorize")
4243
state = self.generate_state()
44+
45+
scope = settings.GITLAB_SCOPE
46+
log.info(f"Gitlab oauth with scope: '{scope}'")
47+
4348
query = dict(
4449
response_type="code",
4550
client_id=redirect_info["client_id"],
4651
redirect_uri=redirect_info["redirect_uri"],
4752
state=state,
53+
scope=scope,
4854
)
4955
query_str = urlencode(query)
5056
return f"{base_url}?{query_str}"

0 commit comments

Comments
 (0)