feat(api): jira integration handle errors
This commit is contained in:
parent
70ef8af0cb
commit
c9f7b6e980
3 changed files with 20 additions and 11 deletions
|
|
@ -15,10 +15,17 @@ class JIRAIntegration(integration_base.BaseIntegration):
|
|||
# TODO: enable super-constructor when OAuth is done
|
||||
# super(JIRAIntegration, self).__init__(jwt, user_id, JIRACloudIntegrationProxy)
|
||||
self._user_id = user_id
|
||||
i = self.get()
|
||||
if i is None:
|
||||
self.integration = self.get()
|
||||
if self.integration is None:
|
||||
return
|
||||
self.issue_handler = JIRACloudIntegrationIssue(token=i["token"], username=i["username"], url=i["url"])
|
||||
self.integration["valid"] = True
|
||||
try:
|
||||
self.issue_handler = JIRACloudIntegrationIssue(token=self.integration["token"],
|
||||
username=self.integration["username"],
|
||||
url=self.integration["url"])
|
||||
except Exception as e:
|
||||
self.issue_handler = None
|
||||
self.integration["valid"] = False
|
||||
|
||||
@property
|
||||
def provider(self):
|
||||
|
|
@ -37,10 +44,10 @@ class JIRAIntegration(integration_base.BaseIntegration):
|
|||
return helper.dict_to_camel_case(cur.fetchone())
|
||||
|
||||
def get_obfuscated(self):
|
||||
integration = self.get()
|
||||
if integration is None:
|
||||
if self.integration is None:
|
||||
return None
|
||||
integration["token"] = obfuscate_string(integration["token"])
|
||||
integration = dict(self.integration)
|
||||
integration["token"] = obfuscate_string(self.integration["token"])
|
||||
integration["provider"] = self.provider.lower()
|
||||
return integration
|
||||
|
||||
|
|
@ -90,14 +97,13 @@ class JIRAIntegration(integration_base.BaseIntegration):
|
|||
return {"state": "success"}
|
||||
|
||||
def add_edit(self, data):
|
||||
s = self.get()
|
||||
if s is not None:
|
||||
if self.integration is not None:
|
||||
return self.update(
|
||||
changes={
|
||||
"username": data["username"],
|
||||
"token": data["token"] \
|
||||
if data.get("token") and len(data["token"]) > 0 and data["token"].find("***") == -1 \
|
||||
else s["token"],
|
||||
else self.integration["token"],
|
||||
"url": data["url"]
|
||||
},
|
||||
obfuscate=True
|
||||
|
|
|
|||
|
|
@ -36,7 +36,10 @@ def get_integration(tenant_id, user_id, tool=None):
|
|||
if tool not in SUPPORTED_TOOLS:
|
||||
return {"errors": [f"issue tracking tool not supported yet, available: {SUPPORTED_TOOLS}"]}, None
|
||||
if tool == integration_jira_cloud.PROVIDER:
|
||||
return None, integration_jira_cloud.JIRAIntegration(tenant_id=tenant_id, user_id=user_id)
|
||||
integration = integration_jira_cloud.JIRAIntegration(tenant_id=tenant_id, user_id=user_id)
|
||||
if integration.integration is not None and not integration.integration.get("valid", True):
|
||||
return {"errors": ["JIRA: connexion issue/unauthorized"]}, integration
|
||||
return None, integration
|
||||
elif tool == integration_github.PROVIDER:
|
||||
return None, integration_github.GitHubIntegration(tenant_id=tenant_id, user_id=user_id)
|
||||
return {"errors": ["lost integration"]}, None
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class JiraManager:
|
|||
except Exception as e:
|
||||
print("!!! JIRA AUTH ERROR")
|
||||
print(e)
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=f"JIRA: Authentication error")
|
||||
raise e
|
||||
|
||||
def set_jira_project_id(self, project_id):
|
||||
self._config["JIRA_PROJECT_ID"] = project_id
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue