Skip to content

Commit f3f0530

Browse files
authored
fix: data model adjustment (#2)
* fix: do not normalize keys * fix: correct data model * fix: tests and lint * fix: more data model cleaning * fix: lint/test
1 parent e0acccd commit f3f0530

File tree

15 files changed

+63
-43
lines changed

15 files changed

+63
-43
lines changed

nodestream_github/github_organizations.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
interpretations:
99
- type: source_node
1010
node_type: GithubOrg
11+
key_normalization:
12+
do_lowercase_strings: false
1113
key:
1214
node_id: !jmespath 'node_id'
1315
additional_indexes:
@@ -69,17 +71,18 @@
6971
relationship_type: IS_MEMBER
7072
iterate_on: !jmespath 'members[*]'
7173
outbound: false
74+
key_normalization:
75+
do_lowercase_strings: false
7276
relationship_properties:
7377
role: !jmespath 'role'
7478

7579
- type: github-repo-relationship
7680
relationship_type: IN_ORGANIZATION
7781
iterate_on: !jmespath 'repositories[*]'
7882
outbound: false
83+
key_normalization:
84+
do_lowercase_strings: false
7985
relationship_properties:
80-
triage: !jmespath 'permissions.triage'
81-
maintain: !jmespath 'permissions.maintain'
82-
admin: !jmespath 'permissions.admin'
83-
push: !jmespath 'permissions.push'
84-
pull: !jmespath 'permissions.pull'
86+
permission: !jmespath 'permission'
87+
8588

nodestream_github/github_repos.yaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
additional_indexes:
1313
- full_name
1414
- html_url
15+
key_normalization:
16+
do_lowercase_strings: false
1517
key:
1618
node_id: !jmespath 'node_id'
1719
- type: properties
@@ -53,6 +55,8 @@
5355
- type: relationship
5456
node_type: GithubOrg
5557
relationship_type: IN_ORGANIZATION
58+
key_normalization:
59+
do_lowercase_strings: false
5660
node_key:
5761
node_id: !jmespath 'org_owner.node_id'
5862
node_properties:
@@ -65,6 +69,8 @@
6569
node_type: GithubUser
6670
relationship_type: IS_OWNER
6771
outbound: false
72+
key_normalization:
73+
do_lowercase_strings: false
6874
node_key:
6975
node_id: !jmespath 'user_owner.node_id'
7076
node_properties:
@@ -75,16 +81,16 @@
7581
relationship_type: IS_COLLABORATOR
7682
iterate_on: !jmespath 'collaborators[*]'
7783
outbound: false
84+
key_normalization:
85+
do_lowercase_strings: false
7886
relationship_properties:
79-
triage: !jmespath 'permissions.triage'
80-
maintain: !jmespath 'permissions.maintain'
81-
admin: !jmespath 'permissions.admin'
82-
push: !jmespath 'permissions.push'
83-
pull: !jmespath 'permissions.pull'
87+
"permission": !jmespath "role_name"
8488

8589
- type: relationship
8690
node_type: ProgrammingLanguage
8791
relationship_type: HAS_LANGUAGE
92+
key_normalization:
93+
do_lowercase_strings: true
8894
node_key:
8995
name: !jmespath 'name'
9096
relationship_properties:
@@ -96,6 +102,8 @@
96102
iterate_on: !jmespath 'webhooks[*]'
97103
relationship_type: WEBHOOK_ON
98104
outbound: false
105+
key_normalization:
106+
do_lowercase_strings: false
99107
relationship_properties:
100108
events: !jmespath "events"
101109
node_key:

nodestream_github/github_teams.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
interpretations:
99
- type: source_node
1010
node_type: GithubTeam
11+
key_normalization:
12+
do_lowercase_strings: false
1113
key:
1214
node_id: !jmespath 'node_id'
1315
additional_indexes:
@@ -34,24 +36,26 @@
3436
- type: relationship
3537
node_type: GithubOrg
3638
relationship_type: IN_ORGANIZATION
39+
key_normalization:
40+
do_lowercase_strings: false
3741
node_key:
3842
node_id: !jmespath 'organization.node_id'
3943
outbound: true
4044

4145
- type: github-user-relationship
4246
relationship_type: IS_MEMBER
4347
iterate_on: !jmespath 'members[*]'
48+
key_normalization:
49+
do_lowercase_strings: false
4450
outbound: false
4551
relationship_properties:
4652
role: !jmespath 'role'
4753

4854
- type: github-repo-relationship
4955
relationship_type: IN_TEAM
5056
iterate_on: !jmespath 'repos[*]'
51-
outbound: false
57+
key_normalization:
58+
do_lowercase_strings: false
5259
relationship_properties:
53-
triage: !jmespath 'permissions.triage'
54-
maintain: !jmespath 'permissions.maintain'
55-
admin: !jmespath 'permissions.admin'
56-
push: !jmespath 'permissions.push'
57-
pull: !jmespath 'permissions.pull'
60+
permission: !jmespath 'permission'
61+
outbound: false

nodestream_github/github_users.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
interpretations:
99
- type: source_node
1010
node_type: GithubUser
11+
key_normalization:
12+
do_lowercase_strings: false
1113
key:
1214
node_id: !jmespath 'node_id'
1315
additional_indexes:
@@ -46,9 +48,5 @@
4648
iterate_on: !jmespath 'repositories[*]'
4749
relationship_type: IS_COLLABORATOR
4850
outbound: true
49-
relationship_properties:
50-
triage: !jmespath 'permissions.triage'
51-
maintain: !jmespath 'permissions.maintain'
52-
admin: !jmespath 'permissions.admin'
53-
push: !jmespath 'permissions.push'
54-
pull: !jmespath 'permissions.pull'
51+
key_normalization:
52+
do_lowercase_strings: false

nodestream_github/interpretations/relationship/repository.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@
1010

1111
from nodestream_github.types import GithubRepo, SimplifiedRepo
1212

13-
_REPO_KEYS_TO_PRESERVE = ["id", "node_id", "name", "full_name", "url", "permissions"]
13+
_REPO_KEYS_TO_PRESERVE = ["id", "node_id", "name", "full_name", "url", "permission"]
1414

1515

16-
def simplify_repo(repo: GithubRepo) -> SimplifiedRepo:
16+
def simplify_repo(repo: GithubRepo, *, permission: str | None = None) -> SimplifiedRepo:
1717
"""Simplify repo data.
1818
1919
Allows us to only keep a consistent minimum for relationship data."""
20-
return {k: repo[k] for k in _REPO_KEYS_TO_PRESERVE if k in repo}
20+
output = {k: repo[k] for k in _REPO_KEYS_TO_PRESERVE if k in repo}
21+
22+
if permission:
23+
output["permission"] = permission
24+
return output
2125

2226

2327
class RepositoryRelationshipInterpretation(

nodestream_github/interpretations/relationship/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from nodestream_github.types import GithubUser, SimplifiedUser
1212

13-
_USER_KEYS_TO_PRESERVE = ["id", "login", "node_id", "role", "permissions"]
13+
_USER_KEYS_TO_PRESERVE = ["id", "login", "node_id", "role", "role_name"]
1414

1515

1616
def simplify_user(user: GithubUser) -> SimplifiedUser:

nodestream_github/orgs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ async def _extract_organization(self, login: str) -> OrgRecord | None:
3737
full_org["members"] = [user async for user in self._fetch_all_members(login)]
3838

3939
full_org["repositories"] = [
40-
simplify_repo(repo) async for repo in self.client.fetch_repos_for_org(login)
40+
simplify_repo(
41+
repo, permission=full_org.get("default_repository_permission")
42+
)
43+
async for repo in self.client.fetch_repos_for_org(login)
4144
]
4245
return full_org
4346

nodestream_github/teams.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async def _fetch_team(
5959
simplify_user(member) async for member in self._fetch_members(team)
6060
]
6161
team["repos"] = [
62-
simplify_repo(repo)
62+
simplify_repo(repo, permission=team.get("permission"))
6363
async for repo in self.client.fetch_repos_for_team(login, team["slug"])
6464
]
6565
return team

tests/data/repos.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ def repo(
132132
"pushed_at": "2011-01-26T19:06:43Z",
133133
"created_at": "2011-01-26T19:01:12Z",
134134
"updated_at": "2011-01-26T19:14:43Z",
135-
"permissions": {"admin": False, "push": False, "pull": True},
136135
"security_and_analysis": {
137136
"advanced_security": {"status": "enabled"},
138137
"secret_scanning": {"status": "enabled"},

tests/interpretations/relationship/test_repository.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def test_simplify_repo():
3131
assert simplify_repo(additional_keys) == _TEST_EXPECTATION
3232

3333

34-
def test_simplify_repo_keep_perms():
35-
test_input = _TEST_EXPECTATION | {"permissions": {"admin": True}}
36-
assert simplify_repo(test_input) == test_input
34+
def test_simplify_repo_set_perm():
35+
expected = _TEST_EXPECTATION | {"permission": "test"}
36+
assert simplify_repo(_TEST_EXPECTATION, permission="test") == expected
3737

3838

3939
def test_repo_relationship(context: ProviderContext):

0 commit comments

Comments
 (0)