github-org-manager 0.5.5__tar.gz → 0.5.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,7 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: github-org-manager
3
- Version: 0.5.5
3
+ Version: 0.5.7
4
4
  Summary: Manage a GitHub Organization, its teams, repository permissions, and more
5
- Home-page: https://github.com/OpenRailAssociation/github-org-manager
6
5
  License: Apache-2.0
7
6
  Keywords: github,github-management,permissions,access-control
8
7
  Author: Max Mehl
@@ -15,10 +15,12 @@ from github import (
15
15
  GithubIntegration,
16
16
  UnknownObjectException,
17
17
  )
18
+ from github.GithubException import BadCredentialsException
18
19
  from github.NamedUser import NamedUser
19
20
  from github.Organization import Organization
20
21
  from github.Repository import Repository
21
22
  from github.Team import Team
23
+ from jwt.exceptions import InvalidKeyError
22
24
 
23
25
  from ._gh_api import get_github_secrets_from_env, run_graphql_query
24
26
 
@@ -65,6 +67,7 @@ class GHorg: # pylint: disable=too-many-instance-attributes, too-many-lines
65
67
  # supported, or multiple spaces etc.
66
68
  return team.replace(" ", "-")
67
69
 
70
+ # amazonq-ignore-next-line
68
71
  def login(
69
72
  self, orgname: str, token: str = "", app_id: str | int = "", app_private_key: str = ""
70
73
  ) -> None:
@@ -81,7 +84,11 @@ class GHorg: # pylint: disable=too-many-instance-attributes, too-many-lines
81
84
  logging.debug("Logging in via app %s", self.gh_app_id)
82
85
  auth = Auth.AppAuth(app_id=self.gh_app_id, private_key=self.gh_app_private_key)
83
86
  app = GithubIntegration(auth=auth)
84
- installation = app.get_org_installation(org=orgname)
87
+ try:
88
+ installation = app.get_org_installation(org=orgname)
89
+ except InvalidKeyError:
90
+ logging.critical("Invalid private key provided for GitHub App")
91
+ sys.exit(1)
85
92
  self.gh = installation.get_github_for_installation()
86
93
  logging.debug("Logged in via app installation %s", installation.id)
87
94
 
@@ -90,7 +97,11 @@ class GHorg: # pylint: disable=too-many-instance-attributes, too-many-lines
90
97
  elif self.gh_token:
91
98
  logging.debug("Logging in as user with PAT")
92
99
  self.gh = Github(auth=Auth.Token(self.gh_token))
93
- logging.debug("Logged in as %s", self.gh.get_user().login)
100
+ try:
101
+ logging.debug("Logged in as %s", self.gh.get_user().login)
102
+ except BadCredentialsException:
103
+ logging.critical("Invalid GitHub token provided")
104
+ sys.exit(1)
94
105
  else:
95
106
  logging.error("No GitHub token or App ID+private key provided")
96
107
  sys.exit(1)
@@ -708,7 +719,25 @@ class GHorg: # pylint: disable=too-many-instance-attributes, too-many-lines
708
719
  continue
709
720
 
710
721
  # Convert team name to Team object
711
- team = self.org.get_team_by_slug(self._sluggify_teamname(team_name))
722
+ try:
723
+ team = self.org.get_team_by_slug(self._sluggify_teamname(team_name))
724
+ # Team not found, probably because a new team should be created, but it's a dry-run
725
+ except UnknownObjectException:
726
+ logging.debug(
727
+ "Team %s not found, probably because it should be created but it's a dry-run",
728
+ team_name,
729
+ )
730
+ # Initialise a new Team() object with the name, manually
731
+ team = Team(
732
+ requester=None, # type: ignore
733
+ headers={}, # No headers required
734
+ attributes={
735
+ "id": 0,
736
+ "name": team_name,
737
+ "slug": self._sluggify_teamname(team_name),
738
+ },
739
+ completed=True, # Mark as fully initialized
740
+ )
712
741
 
713
742
  # Get configured repo permissions
714
743
  for repo, perm in team_attrs.get("repos", {}).items():
@@ -4,7 +4,7 @@
4
4
 
5
5
  [tool.poetry]
6
6
  name = "github-org-manager"
7
- version = "0.5.5"
7
+ version = "0.5.7"
8
8
  description = "Manage a GitHub Organization, its teams, repository permissions, and more"
9
9
  authors = ["Max Mehl <max.mehl@deutschebahn.com>"]
10
10
  readme = "README.md"
@@ -33,13 +33,13 @@ requests = "^2.32.3"
33
33
  python-slugify = "^8.0.4"
34
34
 
35
35
  [tool.poetry.group.dev.dependencies]
36
- black = "^24.3.0"
37
- isort = "^5.13.2"
36
+ black = "^25.1.0"
37
+ isort = ">=5.13.2,<7.0.0"
38
38
  mypy = "^1.9.0"
39
39
  pylint = "^3.1.0"
40
40
  types-pyyaml = "^6.0.12.20240311"
41
41
  types-requests = "^2.32.0.20240712"
42
- bump-my-version = "^0.26.0"
42
+ bump-my-version = "^0.30.0"
43
43
 
44
44
  [build-system]
45
45
  requires = ["poetry-core"]