1313import  git_portfolio .request_objects .issue_list  as  il 
1414
1515
16+ class  GithubServiceError (Exception ):
17+     """Generic error for GithubService.""" 
18+ 
19+     pass 
20+ 
21+ 
1622class  GithubService :
1723    """Github service class.""" 
1824
@@ -46,11 +52,11 @@ def _test_connection(
4652        try :
4753            return  connection .me ()
4854        except  github3 .exceptions .AuthenticationFailed :
49-             raise  AttributeError ("Invalid token." ) from  None 
55+             raise  GithubServiceError ("Invalid token." ) from  None 
5056        except  github3 .exceptions .ConnectionError  as  github_error :
5157            raise  ConnectionError () from  github_error 
5258        except  github3 .exceptions .IncompleteResponse :
53-             raise  AttributeError (
59+             raise  GithubServiceError (
5460                "Invalid response. Your token might not be properly scoped." 
5561            ) from  None 
5662
@@ -94,7 +100,7 @@ def create_issue_from_repo(self, github_repo: str, issue: i.Issue) -> str:
94100            else :
95101                return  f"{ github_repo }  : { client_error .msg }  .\n " 
96102        except  github3 .exceptions .GitHubError  as  github_error :
97-             raise  AttributeError (
103+             raise  GithubServiceError (
98104                f"{ github_repo }  : { github_error .msg } \n " 
99105            ) from  github_error 
100106
@@ -202,7 +208,7 @@ def create_pull_request_from_repo(
202208                    extra  +=  f" Invalid field { error ['field' ]}  ." 
203209            return  f"{ github_repo }  : { github_exception .msg }  .{ extra } \n " 
204210        except  github3 .exceptions .GitHubError  as  github_error :
205-             raise  AttributeError (
211+             raise  GithubServiceError (
206212                f"{ github_repo }  : { github_error .msg } \n " 
207213            ) from  github_error 
208214
@@ -233,7 +239,7 @@ def delete_branch_from_repo(self, github_repo: str, branch: str) -> str:
233239        except  github3 .exceptions .NotFoundError  as  github_exception :
234240            return  f"{ github_repo }  : { github_exception .msg }  .\n " 
235241        except  github3 .exceptions .GitHubError  as  github_error :
236-             raise  AttributeError (
242+             raise  GithubServiceError (
237243                f"{ github_repo }  : { github_error .msg } \n " 
238244            ) from  github_error 
239245
@@ -256,9 +262,14 @@ def merge_pull_request_from_repo(
256262        elif  len (pulls ) ==  1 :
257263            pull  =  pulls [0 ]
258264            output  =  "" 
259-             pull .merge ()
260-             output  +=  f"{ github_repo }  : merge PR successful.\n " 
261-             return  output 
265+             try :
266+                 pull .merge ()
267+                 output  +=  f"{ github_repo }  : merge PR successful.\n " 
268+                 return  output 
269+             except  github3 .exceptions .MethodNotAllowed  as  github_exception :
270+                 raise  GithubServiceError (
271+                     f"{ github_repo }  : { github_exception .msg } \n " 
272+                 ) from  github_exception 
262273        else :
263274            return  (
264275                f"{ github_repo }  : unexpected number of PRs for " 
0 commit comments