Skip to content

Commit 344f2de

Browse files
committed
#31 Clean up naming
1 parent da69bc7 commit 344f2de

9 files changed

+42
-50
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ For an organization project:
5555
5656
```yaml
5757
project_url: "https://github.com/orgs/my_username/projects/1/views/1"
58-
check_done_github_app_id: "1234567"
59-
check_done_github_app_private_key: "-----BEGIN RSA PRIVATE KEY-----
58+
github_app_id: "1234567"
59+
github_app_private_key: "-----BEGIN RSA PRIVATE KEY-----
6060
something_something
6161
-----END RSA PRIVATE KEY-----
6262
"

check_done/config.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class ConfigurationInfo:
3636
personal_access_token: str | None = None
3737

3838
# Required for organization owned project
39-
check_done_github_app_id: str | None = None
40-
check_done_github_app_private_key: str | None = None
39+
github_app_id: str | None = None
40+
github_app_private_key: str | None = None
4141

4242
# Optional
4343
project_status_name_to_check: str | None = None
@@ -51,8 +51,8 @@ class ConfigurationInfo:
5151
"project_url",
5252
"project_status_name_to_check",
5353
"personal_access_token",
54-
"check_done_github_app_id",
55-
"check_done_github_app_private_key",
54+
"github_app_id",
55+
"github_app_private_key",
5656
mode="before",
5757
)
5858
def value_from_env(cls, value: Any | None):
@@ -76,8 +76,8 @@ def validate_authentication_and_set_project_details(self):
7676
self.personal_access_token is not None and not self.is_project_owner_of_type_organization
7777
)
7878
has_organizational_authentication = (
79-
self.check_done_github_app_id is not None
80-
and self.check_done_github_app_private_key is not None
79+
self.github_app_id is not None
80+
and self.github_app_private_key is not None
8181
and self.is_project_owner_of_type_organization
8282
)
8383
if not has_user_authentication ^ has_organizational_authentication:
@@ -138,7 +138,7 @@ def default_config_path() -> Path:
138138
previous_config_folder = None
139139
result = None
140140
while result is None and config_folder != previous_config_folder:
141-
# TODO#32 Check yaml and yml.
141+
# TODO#32 Check yaml and yml, if both exist yaml is picked over yml.
142142
config_path_to_check = (config_folder / CONFIG_BASE_NAME).with_suffix(".yaml")
143143
if config_path_to_check.is_file():
144144
result = config_path_to_check

check_done/done_project_items_info.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ def done_project_items_info(configuration_info: ConfigurationInfo) -> list[Proje
2525

2626
is_project_owner_of_type_organization = configuration_info.is_project_owner_of_type_organization
2727
if is_project_owner_of_type_organization:
28-
check_done_github_app_id = configuration_info.check_done_github_app_id
29-
check_done_github_app_private_key = configuration_info.check_done_github_app_private_key
30-
access_token = resolve_organization_access_token(
31-
project_owner_name, check_done_github_app_id, check_done_github_app_private_key
32-
)
28+
github_app_id = configuration_info.github_app_id
29+
github_app_private_key = configuration_info.github_app_private_key
30+
access_token = resolve_organization_access_token(project_owner_name, github_app_id, github_app_private_key)
3331
else:
3432
access_token = configuration_info.personal_access_token
3533

check_done/organization_authentication.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,38 @@ class AuthenticationError(Exception):
1717
"""Error raised due to failed JWT authentication process."""
1818

1919

20-
def resolve_organization_access_token(
21-
organization_name: str, check_done_github_app_id: str, check_done_github_app_private_key: str
22-
) -> str:
20+
def resolve_organization_access_token(organization_name: str, github_app_id: str, github_app_private_key: str) -> str:
2321
"""
2422
Generates the necessary access token for an organization from the installed GitHub app instance in said organization
2523
"""
26-
jwt_token = generate_jwt_token(check_done_github_app_id, check_done_github_app_private_key)
24+
jwt_token = generate_jwt_token(github_app_id, github_app_private_key)
2725
session = requests.Session()
2826
session.headers = {"Accept": "application/vnd.github+json"}
2927
session.auth = HttpBearerAuth(jwt_token)
3028
try:
31-
check_done_github_app_installation_id = resolve_check_done_github_app_installation_id(
32-
session, organization_name
33-
)
34-
result = resolve_access_token_from_check_done_github_app_installation_id(
35-
session, check_done_github_app_installation_id
36-
)
29+
github_app_installation_id = resolve_github_app_installation_id(session, organization_name)
30+
result = resolve_access_token_from_github_app_installation_id(session, github_app_installation_id)
3731
except Exception as error:
3832
raise AuthenticationError(
3933
f"Cannot resolve organization access token from JWT authentication process: {error}"
4034
) from error
4135
return result
4236

4337

44-
def generate_jwt_token(check_done_github_app_id: str, check_done_github_app_private_key: str) -> str:
38+
def generate_jwt_token(github_app_id: str, github_app_private_key: str) -> str:
4539
"""Generates a JWT token for authentication with GitHub."""
4640
try:
4741
payload = {
4842
"exp": _EXPIRES_AT,
4943
"iat": _ISSUED_AT,
50-
"iss": check_done_github_app_id,
44+
"iss": github_app_id,
5145
}
52-
return jwt.encode(payload, check_done_github_app_private_key, algorithm="RS256")
46+
return jwt.encode(payload, github_app_private_key, algorithm="RS256")
5347
except Exception as error:
5448
raise AuthenticationError(f"Cannot generate JWT token: {error}") from error
5549

5650

57-
def resolve_check_done_github_app_installation_id(session: Session, organization_name: str) -> str:
51+
def resolve_github_app_installation_id(session: Session, organization_name: str) -> str:
5852
"""Fetches the installation ID for the organization."""
5953
response = session.get(f"https://api.github.com/orgs/{organization_name}/installation")
6054

@@ -65,7 +59,7 @@ def resolve_check_done_github_app_installation_id(session: Session, organization
6559
)
6660

6761

68-
def resolve_access_token_from_check_done_github_app_installation_id(session: Session, installation_id: str) -> str:
62+
def resolve_access_token_from_github_app_installation_id(session: Session, installation_id: str) -> str:
6963
"""Retrieves the access token using the installation ID."""
7064
response = session.post(f"https://api.github.com/app/installations/{installation_id}/access_tokens")
7165
if response.status_code == 201 and response.json().get("token") is not None:

tests/data/test_configuration.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
project_url: ${CHECK_DONE_GITHUB_PROJECT_URL}
22
project_status_name_to_check: ${CHECK_DONE_GITHUB_PROJECT_STATUS_NAME_TO_CHECK}
33
personal_access_token: ${CHECK_DONE_PERSONAL_ACCESS_TOKEN}
4-
check_done_github_app_id: ${CHECK_DONE_GITHUB_APP_ID}
5-
check_done_github_app_private_key: ${CHECK_DONE_GITHUB_APP_PRIVATE_KEY}
4+
github_app_id: ${CHECK_DONE_GITHUB_APP_ID}
5+
github_app_private_key: ${CHECK_DONE_GITHUB_APP_PRIVATE_KEY}

tests/test_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def test_can_set_config_argument():
4242
config_path = (current_folder / CONFIG_BASE_NAME).with_suffix(".yaml")
4343
config_path.write_text(
4444
"project_url: ${CHECK_DONE_GITHUB_PROJECT_URL}\n"
45-
"check_done_github_app_id: ${CHECK_DONE_GITHUB_APP_ID}\n"
46-
"check_done_github_app_private_key: ${CHECK_DONE_GITHUB_APP_PRIVATE_KEY}\n"
45+
"github_app_id: ${CHECK_DONE_GITHUB_APP_ID}\n"
46+
"github_app_private_key: ${CHECK_DONE_GITHUB_APP_PRIVATE_KEY}\n"
4747
)
4848
exit_code = check_done_command(["--config", str(config_path)])
4949
assert exit_code == 0

tests/test_config.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ def test_can_validate_at_least_one_type_of_authentication_is_properly_configured
111111
fake_organization_project_url = "https://github.com/orgs/fake-organization/projects/1"
112112
fake_configuration_info_with_organization_project = ConfigurationInfo(
113113
project_url="https://github.com/orgs/fake-organization/projects/1",
114-
check_done_github_app_id="fake_app_id",
115-
check_done_github_app_private_key="fake_private_key",
114+
github_app_id="fake_app_id",
115+
github_app_private_key="fake_private_key",
116116
)
117117
assert fake_configuration_info_with_organization_project.project_url == fake_organization_project_url
118-
assert fake_configuration_info_with_organization_project.check_done_github_app_id == "fake_app_id"
119-
assert fake_configuration_info_with_organization_project.check_done_github_app_private_key == "fake_private_key"
118+
assert fake_configuration_info_with_organization_project.github_app_id == "fake_app_id"
119+
assert fake_configuration_info_with_organization_project.github_app_private_key == "fake_private_key"
120120

121121

122122
def test_fails_on_no_authentication_method_configured():
@@ -130,15 +130,15 @@ def test_fails_on_organization_authentication_method_missing_private_key():
130130
with pytest.raises(ValueError, match="A user or an organization authentication method must be configured."):
131131
ConfigurationInfo(
132132
project_url="https://github.com/orgs/fake-organization/projects/1",
133-
check_done_github_app_id="fake_check_done_github_app_id",
133+
github_app_id="fake_github_app_id",
134134
)
135135

136136

137137
def test_fails_on_organization_authentication_method_missing_app_id():
138138
with pytest.raises(ValueError, match="A user or an organization authentication method must be configured."):
139139
ConfigurationInfo(
140140
project_url="https://github.com/orgs/fake-organization/projects/1",
141-
check_done_github_app_private_key="fake_check_done_github_app_private_key",
141+
github_app_private_key="fake_github_app_private_key",
142142
)
143143

144144

@@ -166,8 +166,8 @@ def test_can_resolve_project_details_from_user_project_url():
166166
def test_can_resolve_project_details_from_organization_project_url():
167167
configuration_info = ConfigurationInfo(
168168
project_url="https://github.com/orgs/fake-organization-name/projects/1/views/2",
169-
check_done_github_app_id="fake_check_done_github_app_id",
170-
check_done_github_app_private_key="fake_check_done_github_app_private_key",
169+
github_app_id="fake_github_app_id",
170+
github_app_private_key="fake_github_app_private_key",
171171
)
172172
assert configuration_info.is_project_owner_of_type_organization
173173
assert configuration_info.project_number == 1

tests/test_done_project_items_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
def test_can_resolve_done_project_items_info():
4949
fake_configuration_info = ConfigurationInfo(
5050
project_url=DEMO_CHECK_DONE_GITHUB_PROJECT_URL,
51-
check_done_github_app_id=DEMO_CHECK_DONE_GITHUB_APP_ID,
52-
check_done_github_app_private_key=DEMO_CHECK_DONE_GITHUB_APP_PRIVATE_KEY,
51+
github_app_id=DEMO_CHECK_DONE_GITHUB_APP_ID,
52+
github_app_private_key=DEMO_CHECK_DONE_GITHUB_APP_PRIVATE_KEY,
5353
)
5454
assert len(done_project_items_info(fake_configuration_info)) >= 1
5555

tests/test_organization_authentication.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from check_done.organization_authentication import (
1111
AuthenticationError,
1212
generate_jwt_token,
13-
resolve_check_done_github_app_installation_id,
13+
resolve_github_app_installation_id,
1414
resolve_organization_access_token,
1515
)
1616
from tests._common import (
@@ -73,30 +73,30 @@ def test_can_generate_jwt_token():
7373
not HAS_DEMO_CHECK_DONE_ORGANIZATION_PROJECT_CONFIGURED,
7474
reason=REASON_SHOULD_HAVE_DEMO_CHECK_DONE_ORGANIZATION_PROJECT_CONFIGURED,
7575
)
76-
def test_can_resolve_check_done_github_app_installation_id():
76+
def test_can_resolve_github_app_installation_id():
7777
session = _session()
78-
fake_installation_id = resolve_check_done_github_app_installation_id(session, DEMO_CHECK_DONE_PROJECT_OWNER_NAME)
78+
fake_installation_id = resolve_github_app_installation_id(session, DEMO_CHECK_DONE_PROJECT_OWNER_NAME)
7979
assert isinstance(fake_installation_id, int)
8080

8181

8282
@pytest.mark.skipif(
8383
not HAS_DEMO_CHECK_DONE_ORGANIZATION_PROJECT_CONFIGURED,
8484
reason=REASON_SHOULD_HAVE_DEMO_CHECK_DONE_ORGANIZATION_PROJECT_CONFIGURED,
8585
)
86-
def test_fails_to_resolve_check_done_github_app_installation_id():
86+
def test_fails_to_resolve_github_app_installation_id():
8787
session = _session()
8888
with pytest.raises(AuthenticationError, match="Could not retrieve installation ID: status=404 "):
89-
resolve_check_done_github_app_installation_id(session, _DUMMY_ORGANIZATION_NAME)
89+
resolve_github_app_installation_id(session, _DUMMY_ORGANIZATION_NAME)
9090

9191

92-
def test_fails_to_resolve_check_done_github_app_installation_id_from_bad_request():
92+
def test_fails_to_resolve_github_app_installation_id_from_bad_request():
9393
with requests_mock.Mocker() as mock:
9494
mock.get(f"https://api.github.com/orgs/{_DUMMY_ORGANIZATION_NAME}/installation", status_code=400)
9595
with pytest.raises(AuthenticationError, match="Could not retrieve installation ID: status=400 "):
9696
resolve_organization_access_token(_DUMMY_ORGANIZATION_NAME, _DUMMY_GITHUB_APP_ID, _FAKE_PEM_PRIVATE_KEY)
9797

9898

99-
def test_fails_to_resolve_access_token_from_check_done_github_app_installation_id():
99+
def test_fails_to_resolve_access_token_from_github_app_installation_id():
100100
with requests_mock.Mocker() as mock:
101101
mock.get(
102102
f"https://api.github.com/orgs/{_DUMMY_ORGANIZATION_NAME}/installation",

0 commit comments

Comments
 (0)