parent
c151d55c67
commit
c93df14f93
7 changed files with 59 additions and 59 deletions
|
|
@ -1,12 +1,12 @@
|
|||
import schemas
|
||||
from chalicelib.core.issue_tracking import integration_base
|
||||
from chalicelib.core.issue_tracking.integration_github_issue import GithubIntegrationIssue
|
||||
from chalicelib.core.issue_tracking import base
|
||||
from chalicelib.core.issue_tracking.github_issue import GithubIntegrationIssue
|
||||
from chalicelib.utils import pg_client, helper
|
||||
|
||||
PROVIDER = schemas.IntegrationType.GITHUB
|
||||
|
||||
|
||||
class GitHubIntegration(integration_base.BaseIntegration):
|
||||
class GitHubIntegration(base.BaseIntegration):
|
||||
|
||||
def __init__(self, tenant_id, user_id):
|
||||
self.__tenant_id = tenant_id
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
from chalicelib.core.issue_tracking.integration_base_issue import BaseIntegrationIssue
|
||||
from chalicelib.core.issue_tracking.base_issue import BaseIntegrationIssue
|
||||
from chalicelib.utils import github_client_v3
|
||||
from chalicelib.utils.github_client_v3 import github_formatters as formatter
|
||||
|
||||
|
||||
class GithubIntegrationIssue(BaseIntegrationIssue):
|
||||
def __init__(self, integration_token):
|
||||
self.__client = github_client_v3.githubV3Request(integration_token)
|
||||
super(GithubIntegrationIssue, self).__init__("GITHUB", integration_token)
|
||||
def __init__(self, token):
|
||||
self.__client = github_client_v3.githubV3Request(token)
|
||||
super(GithubIntegrationIssue, self).__init__("GITHUB", token)
|
||||
|
||||
def get_current_user(self):
|
||||
return formatter.user(self.__client.get("/user"))
|
||||
|
|
@ -28,9 +28,9 @@ class GithubIntegrationIssue(BaseIntegrationIssue):
|
|||
|
||||
return meta
|
||||
|
||||
def create_new_assignment(self, integration_project_id, title, description, assignee,
|
||||
def create_new_assignment(self, project_id, title, description, assignee,
|
||||
issue_type):
|
||||
repoId = integration_project_id
|
||||
repoId = project_id
|
||||
assignees = [assignee]
|
||||
labels = [str(issue_type)]
|
||||
|
||||
|
|
@ -59,11 +59,11 @@ class GithubIntegrationIssue(BaseIntegrationIssue):
|
|||
def get_by_ids(self, saved_issues):
|
||||
results = []
|
||||
for i in saved_issues:
|
||||
results.append(self.get(integration_project_id=i["integrationProjectId"], assignment_id=i["id"]))
|
||||
results.append(self.get(project_id=i["integrationProjectId"], assignment_id=i["id"]))
|
||||
return {"issues": results}
|
||||
|
||||
def get(self, integration_project_id, assignment_id):
|
||||
repoId = integration_project_id
|
||||
def get(self, project_id, assignment_id):
|
||||
repoId = project_id
|
||||
issueNumber = assignment_id
|
||||
issue = self.__client.get(f"/repositories/{repoId}/issues/{issueNumber}")
|
||||
issue = formatter.issue(issue)
|
||||
|
|
@ -72,17 +72,17 @@ class GithubIntegrationIssue(BaseIntegrationIssue):
|
|||
self.__client.get(f"/repositories/{repoId}/issues/{issueNumber}/comments")]
|
||||
return issue
|
||||
|
||||
def comment(self, integration_project_id, assignment_id, comment):
|
||||
repoId = integration_project_id
|
||||
def comment(self, project_id, assignment_id, comment):
|
||||
repoId = project_id
|
||||
issueNumber = assignment_id
|
||||
commentCreated = self.__client.post(f"/repositories/{repoId}/issues/{issueNumber}/comments",
|
||||
body={"body": comment})
|
||||
return formatter.comment(commentCreated)
|
||||
|
||||
def get_metas(self, integration_project_id):
|
||||
def get_metas(self, project_id):
|
||||
current_user = self.get_current_user()
|
||||
try:
|
||||
users = self.__client.get(f"/repositories/{integration_project_id}/collaborators")
|
||||
users = self.__client.get(f"/repositories/{project_id}/collaborators")
|
||||
except Exception as e:
|
||||
users = []
|
||||
users = [formatter.user(u) for u in users]
|
||||
|
|
@ -92,7 +92,7 @@ class GithubIntegrationIssue(BaseIntegrationIssue):
|
|||
return {"provider": self.provider.lower(),
|
||||
'users': users,
|
||||
'issueTypes': [formatter.label(l) for l in
|
||||
self.__client.get(f"/repositories/{integration_project_id}/labels")]
|
||||
self.__client.get(f"/repositories/{project_id}/labels")]
|
||||
}
|
||||
|
||||
def get_projects(self):
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from chalicelib.core.issue_tracking import integration_github, integration_jira_cloud
|
||||
from chalicelib.core.issue_tracking import github, jira_cloud
|
||||
from chalicelib.utils import pg_client
|
||||
|
||||
SUPPORTED_TOOLS = [integration_github.PROVIDER, integration_jira_cloud.PROVIDER]
|
||||
SUPPORTED_TOOLS = [github.PROVIDER, jira_cloud.PROVIDER]
|
||||
|
||||
|
||||
def get_available_integrations(user_id):
|
||||
|
|
@ -23,7 +23,7 @@ def get_available_integrations(user_id):
|
|||
|
||||
def __get_default_integration(user_id):
|
||||
current_integrations = get_available_integrations(user_id)
|
||||
return integration_github.PROVIDER if current_integrations["github"] else integration_jira_cloud.PROVIDER if \
|
||||
return github.PROVIDER if current_integrations["github"] else jira_cloud.PROVIDER if \
|
||||
current_integrations["jira"] else None
|
||||
|
||||
|
||||
|
|
@ -35,11 +35,11 @@ def get_integration(tenant_id, user_id, tool=None, for_delete=False):
|
|||
tool = tool.upper()
|
||||
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:
|
||||
integration = integration_jira_cloud.JIRAIntegration(tenant_id=tenant_id, user_id=user_id)
|
||||
if tool == jira_cloud.PROVIDER:
|
||||
integration = jira_cloud.JIRAIntegration(tenant_id=tenant_id, user_id=user_id)
|
||||
if not for_delete and 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)
|
||||
elif tool == github.PROVIDER:
|
||||
return None, github.GitHubIntegration(tenant_id=tenant_id, user_id=user_id)
|
||||
return {"errors": ["lost integration"]}, None
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import schemas
|
||||
from chalicelib.core.issue_tracking import integration_base
|
||||
from chalicelib.core.issue_tracking.integration_jira_cloud_issue import JIRACloudIntegrationIssue
|
||||
from chalicelib.core.issue_tracking import base
|
||||
from chalicelib.core.issue_tracking.jira_cloud_issue import JIRACloudIntegrationIssue
|
||||
from chalicelib.utils import pg_client, helper
|
||||
|
||||
PROVIDER = schemas.IntegrationType.JIRA
|
||||
|
|
@ -10,7 +10,7 @@ def obfuscate_string(string):
|
|||
return "*" * (len(string) - 4) + string[-4:]
|
||||
|
||||
|
||||
class JIRAIntegration(integration_base.BaseIntegration):
|
||||
class JIRAIntegration(base.BaseIntegration):
|
||||
def __init__(self, tenant_id, user_id):
|
||||
self.__tenant_id = tenant_id
|
||||
# TODO: enable super-constructor when OAuth is done
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from chalicelib.utils import jira_client
|
||||
from chalicelib.core.issue_tracking.integration_base_issue import BaseIntegrationIssue
|
||||
from chalicelib.core.issue_tracking.base_issue import BaseIntegrationIssue
|
||||
|
||||
|
||||
class JIRACloudIntegrationIssue(BaseIntegrationIssue):
|
||||
|
|
@ -9,8 +9,8 @@ class JIRACloudIntegrationIssue(BaseIntegrationIssue):
|
|||
self._client = jira_client.JiraManager(self.url, self.username, token, None)
|
||||
super(JIRACloudIntegrationIssue, self).__init__("JIRA", token)
|
||||
|
||||
def create_new_assignment(self, integration_project_id, title, description, assignee, issue_type):
|
||||
self._client.set_jira_project_id(integration_project_id)
|
||||
def create_new_assignment(self, project_id, title, description, assignee, issue_type):
|
||||
self._client.set_jira_project_id(project_id)
|
||||
data = {
|
||||
'summary': title,
|
||||
'description': description,
|
||||
|
|
@ -28,26 +28,26 @@ class JIRACloudIntegrationIssue(BaseIntegrationIssue):
|
|||
projects_map[i["integrationProjectId"]].append(i["id"])
|
||||
|
||||
results = []
|
||||
for integration_project_id in projects_map:
|
||||
self._client.set_jira_project_id(integration_project_id)
|
||||
for project_id in projects_map:
|
||||
self._client.set_jira_project_id(project_id)
|
||||
jql = 'labels = OpenReplay'
|
||||
if len(projects_map[integration_project_id]) > 0:
|
||||
jql += f" AND ID IN ({','.join(projects_map[integration_project_id])})"
|
||||
if len(projects_map[project_id]) > 0:
|
||||
jql += f" AND ID IN ({','.join(projects_map[project_id])})"
|
||||
issues = self._client.get_issues(jql, offset=0)
|
||||
results += issues
|
||||
return {"issues": results}
|
||||
|
||||
def get(self, integration_project_id, assignment_id):
|
||||
self._client.set_jira_project_id(integration_project_id)
|
||||
def get(self, project_id, assignment_id):
|
||||
self._client.set_jira_project_id(project_id)
|
||||
return self._client.get_issue_v3(assignment_id)
|
||||
|
||||
def comment(self, integration_project_id, assignment_id, comment):
|
||||
self._client.set_jira_project_id(integration_project_id)
|
||||
def comment(self, project_id, assignment_id, comment):
|
||||
self._client.set_jira_project_id(project_id)
|
||||
return self._client.add_comment_v3(assignment_id, comment)
|
||||
|
||||
def get_metas(self, integration_project_id):
|
||||
def get_metas(self, project_id):
|
||||
meta = {}
|
||||
self._client.set_jira_project_id(integration_project_id)
|
||||
self._client.set_jira_project_id(project_id)
|
||||
meta['issueTypes'] = self._client.get_issue_types()
|
||||
meta['users'] = self._client.get_assignable_users()
|
||||
return {"provider": self.provider.lower(), **meta}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from decouple import config
|
|||
from chalicelib.utils import helper
|
||||
from chalicelib.utils.TimeUTC import TimeUTC
|
||||
from chalicelib.utils import pg_client
|
||||
from chalicelib.core.issue_tracking import integrations_manager, integration_base_issue
|
||||
from chalicelib.core.issue_tracking import integrations_manager, base_issue
|
||||
import json
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ from chalicelib.core import sourcemaps, events, projects, alerts, issues, \
|
|||
log_tools, sessions, announcements, \
|
||||
weekly_report, assist, mobile, tenants, boarding, \
|
||||
notifications, webhook, users, custom_metrics, saved_search, tags, autocomplete
|
||||
from chalicelib.core.issue_tracking import integration_github, integrations_global, integrations_manager, \
|
||||
integration_jira_cloud
|
||||
from chalicelib.core.issue_tracking import github, integrations_global, integrations_manager, \
|
||||
jira_cloud
|
||||
from chalicelib.core.log_tools import datadog, newrelic, stackdriver, elasticsearch, \
|
||||
sentry, bugsnag, cloudwatch, sumologic, rollbar
|
||||
from chalicelib.core.sessions import sessions_assignments
|
||||
|
|
@ -70,16 +70,16 @@ def get_integrations_status(projectId: int, context: schemas.CurrentContext = De
|
|||
|
||||
|
||||
@app.post('/{projectId}/integrations/{integration}/notify/{webhookId}/{source}/{sourceId}', tags=["integrations"])
|
||||
def integration_notify(projectId: int, integration: str, webhookId: int, source: str, sourceId: str,
|
||||
data: schemas.IntegrationNotificationSchema = Body(...),
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
def notify(projectId: int, integration: str, webhookId: int, source: str, sourceId: str,
|
||||
data: schemas.IntegrationNotificationSchema = Body(...),
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
comment = None
|
||||
if data.comment:
|
||||
comment = data.comment
|
||||
|
||||
args = {"tenant_id": context.tenant_id,
|
||||
"user": context.email, "comment": comment, "project_id": projectId,
|
||||
"integration_id": webhookId,
|
||||
"id": webhookId,
|
||||
"project_name": context.project.name}
|
||||
if integration == schemas.WebhookType.SLACK:
|
||||
if source == "sessions":
|
||||
|
|
@ -310,7 +310,7 @@ def delete_sumologic(projectId: int, _=Body(None), context: schemas.CurrentConte
|
|||
|
||||
|
||||
@app.get('/integrations/issues', tags=["integrations"])
|
||||
def get_integration_status(context: schemas.CurrentContext = Depends(OR_context)):
|
||||
def get_status(context: schemas.CurrentContext = Depends(OR_context)):
|
||||
error, integration = integrations_manager.get_integration(tenant_id=context.tenant_id,
|
||||
user_id=context.user_id)
|
||||
if error is not None and integration is None:
|
||||
|
|
@ -319,20 +319,20 @@ def get_integration_status(context: schemas.CurrentContext = Depends(OR_context)
|
|||
|
||||
|
||||
@app.get('/integrations/jira', tags=["integrations"])
|
||||
def get_integration_status_jira(context: schemas.CurrentContext = Depends(OR_context)):
|
||||
def get_status_jira(context: schemas.CurrentContext = Depends(OR_context)):
|
||||
error, integration = integrations_manager.get_integration(tenant_id=context.tenant_id,
|
||||
user_id=context.user_id,
|
||||
tool=integration_jira_cloud.PROVIDER)
|
||||
tool=jira_cloud.PROVIDER)
|
||||
if error is not None and integration is None:
|
||||
return error
|
||||
return {"data": integration.get_obfuscated()}
|
||||
|
||||
|
||||
@app.get('/integrations/github', tags=["integrations"])
|
||||
def get_integration_status_github(context: schemas.CurrentContext = Depends(OR_context)):
|
||||
def get_status_github(context: schemas.CurrentContext = Depends(OR_context)):
|
||||
error, integration = integrations_manager.get_integration(tenant_id=context.tenant_id,
|
||||
user_id=context.user_id,
|
||||
tool=integration_github.PROVIDER)
|
||||
tool=github.PROVIDER)
|
||||
if error is not None and integration is None:
|
||||
return error
|
||||
return {"data": integration.get_obfuscated()}
|
||||
|
|
@ -343,7 +343,7 @@ def add_edit_jira_cloud(data: schemas.IssueTrackingJiraSchema = Body(...),
|
|||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
if not str(data.url).rstrip('/').endswith('atlassian.net'):
|
||||
return {"errors": ["url must be a valid JIRA URL (example.atlassian.net)"]}
|
||||
error, integration = integrations_manager.get_integration(tool=integration_jira_cloud.PROVIDER,
|
||||
error, integration = integrations_manager.get_integration(tool=jira_cloud.PROVIDER,
|
||||
tenant_id=context.tenant_id,
|
||||
user_id=context.user_id)
|
||||
if error is not None and integration is None:
|
||||
|
|
@ -354,7 +354,7 @@ def add_edit_jira_cloud(data: schemas.IssueTrackingJiraSchema = Body(...),
|
|||
@app.post('/integrations/github', tags=["integrations"])
|
||||
def add_edit_github(data: schemas.IssueTrackingGithubSchema = Body(...),
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
error, integration = integrations_manager.get_integration(tool=integration_github.PROVIDER,
|
||||
error, integration = integrations_manager.get_integration(tool=github.PROVIDER,
|
||||
tenant_id=context.tenant_id,
|
||||
user_id=context.user_id)
|
||||
if error is not None:
|
||||
|
|
@ -373,7 +373,7 @@ def delete_default_issue_tracking_tool(_=Body(None), context: schemas.CurrentCon
|
|||
|
||||
@app.delete('/integrations/jira', tags=["integrations"])
|
||||
def delete_jira_cloud(_=Body(None), context: schemas.CurrentContext = Depends(OR_context)):
|
||||
error, integration = integrations_manager.get_integration(tool=integration_jira_cloud.PROVIDER,
|
||||
error, integration = integrations_manager.get_integration(tool=jira_cloud.PROVIDER,
|
||||
tenant_id=context.tenant_id,
|
||||
user_id=context.user_id,
|
||||
for_delete=True)
|
||||
|
|
@ -384,7 +384,7 @@ def delete_jira_cloud(_=Body(None), context: schemas.CurrentContext = Depends(OR
|
|||
|
||||
@app.delete('/integrations/github', tags=["integrations"])
|
||||
def delete_github(_=Body(None), context: schemas.CurrentContext = Depends(OR_context)):
|
||||
error, integration = integrations_manager.get_integration(tool=integration_github.PROVIDER,
|
||||
error, integration = integrations_manager.get_integration(tool=github.PROVIDER,
|
||||
tenant_id=context.tenant_id,
|
||||
user_id=context.user_id,
|
||||
for_delete=True)
|
||||
|
|
@ -409,7 +409,7 @@ def get_all_issue_tracking_projects(context: schemas.CurrentContext = Depends(OR
|
|||
|
||||
|
||||
@app.get('/integrations/issues/{integrationProjectId}', tags=["integrations"])
|
||||
def get_integration_metadata(integrationProjectId: int, context: schemas.CurrentContext = Depends(OR_context)):
|
||||
def get_metadata(integrationProjectId: int, context: schemas.CurrentContext = Depends(OR_context)):
|
||||
error, integration = integrations_manager.get_integration(tenant_id=context.tenant_id,
|
||||
user_id=context.user_id)
|
||||
if error is not None:
|
||||
|
|
@ -731,7 +731,7 @@ def get_slack_channels(context: schemas.CurrentContext = Depends(OR_context)):
|
|||
|
||||
@app.get('/integrations/slack/{integrationId}', tags=["integrations"])
|
||||
def get_slack_webhook(integrationId: int, context: schemas.CurrentContext = Depends(OR_context)):
|
||||
return {"data": Slack.get_integration(tenant_id=context.tenant_id, integration_id=integrationId)}
|
||||
return {"data": Slack.get_integration(tenant_id=context.tenant_id, id=integrationId)}
|
||||
|
||||
|
||||
@app.delete('/integrations/slack/{integrationId}', tags=["integrations"])
|
||||
|
|
@ -834,7 +834,7 @@ def add_msteams_integration(data: schemas.AddCollaborationSchema,
|
|||
def edit_msteams_integration(webhookId: int, data: schemas.EditCollaborationSchema = Body(...),
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
if len(data.url.unicode_string()) > 0:
|
||||
old = MSTeams.get_integration(tenant_id=context.tenant_id, integration_id=webhookId)
|
||||
old = MSTeams.get_integration(tenant_id=context.tenant_id, id=webhookId)
|
||||
if not old:
|
||||
return {"errors": ["MsTeams integration not found."]}
|
||||
if old["endpoint"] != data.url.unicode_string():
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue