Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GITHUB handler update #8721

Merged
merged 10 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions mindsdb/api/executor/command_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def __init__(self, session, context=None):
self.datahub = session.datahub

@profiler.profile()
def execute_command(self, statement):
def execute_command(self, statement) -> ExecuteAnswer:
sql = None
if isinstance(statement, ASTNode):
sql = statement.to_string()
Expand Down Expand Up @@ -706,16 +706,15 @@ def answer_drop_trigger(self, statement):

return ExecuteAnswer(ANSWER_TYPE.OK)

def answer_create_job(self, statement):
def answer_create_job(self, statement: CreateJob):
jobs_controller = JobsController()

name = statement.name
job_name = name.parts[-1]
project_name = name.parts[-2] if len(name.parts) > 1 else self.session.database

try:
jobs_controller.add(job_name, project_name, statement.query_str,
statement.start_str, statement.end_str, statement.repeat_str)
jobs_controller.add(job_name, project_name, statement)
except EntityExistsError:
if getattr(statement, "if_not_exists", False) is False:
raise
Expand Down Expand Up @@ -1483,13 +1482,14 @@ def answer_update_agent(self, statement):
return ExecuteAnswer(answer_type=ANSWER_TYPE.OK)

@mark_process("learn")
def answer_create_predictor(self, statement):
def answer_create_predictor(self, statement: CreatePredictor):
integration_name = self.session.database

# allow creation in non-active projects, e.g. 'create mode proj.model' works whether `proj` is active or not
if len(statement.name.parts) > 1:
integration_name = statement.name.parts[0]
statement.name.parts = [integration_name.lower(), statement.name.parts[-1]]
model_name = statement.name.parts[-1]
statement.name.parts = [integration_name.lower(), model_name]

ml_integration_name = "lightwood" # default
if statement.using is not None:
Expand All @@ -1502,6 +1502,16 @@ def answer_create_predictor(self, statement):
ml_integration_name
)

if getattr(statement, "is_replace", False) is True:
# try to delete
try:
self.session.model_controller.delete_model(
model_name,
project_name=integration_name
)
except EntityNotExistsError:
pass

try:
df = self.session.model_controller.create_model(statement, ml_handler)
resp_dict = df.to_dict(orient='split')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ class InformationSchemaDataNode(DataNode):
"NEXT_RUN_AT",
"SCHEDULE_STR",
"QUERY",
"IF_QUERY",
"VARIABLES",
],
"MDB_TRIGGERS": ["NAME", "PROJECT", "DATABASE", "TABLE", "QUERY", "LAST_ERROR"],
Expand Down
31 changes: 13 additions & 18 deletions mindsdb/integrations/handlers/github_handler/github_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
GithubBranchesTable,
GithubContributorsTable,
GithubMilestonesTable,
GithubProjectsTable
GithubProjectsTable, GithubFilesTable
)

from mindsdb.integrations.libs.api_handler import APIHandler
Expand Down Expand Up @@ -45,23 +45,15 @@ def __init__(self, name: str, **kwargs):
self.connection = None
self.is_connected = False

github_issues_data = GithubIssuesTable(self)
github_pull_requests_data = GithubPullRequestsTable(self)
github_commits_data = GithubCommitsTable(self)
github_releases_data = GithubReleasesTable(self)
github_branches_data = GithubBranchesTable(self)
github_contributors_data = GithubContributorsTable(self)
github_milestones_data = GithubMilestonesTable(self)
github_projects_data = GithubProjectsTable(self)

self._register_table("issues", github_issues_data)
self._register_table("pull_requests", github_pull_requests_data)
self._register_table("commits", github_commits_data)
self._register_table("releases", github_releases_data)
self._register_table("branches", github_branches_data)
self._register_table("contributors", github_contributors_data)
self._register_table("milestones", github_milestones_data)
self._register_table("projects", github_projects_data)
self._register_table("issues", GithubIssuesTable(self))
self._register_table("pull_requests", GithubPullRequestsTable(self))
self._register_table("commits", GithubCommitsTable(self))
self._register_table("releases", GithubReleasesTable(self))
self._register_table("branches", GithubBranchesTable(self))
self._register_table("contributors", GithubContributorsTable(self))
self._register_table("milestones", GithubMilestonesTable(self))
self._register_table("projects", GithubProjectsTable(self))
self._register_table("files", GithubFilesTable(self))

def connect(self) -> StatusResponse:
"""Set up the connection required by the handler.
Expand All @@ -72,6 +64,9 @@ def connect(self) -> StatusResponse:
connection object
"""

if self.is_connected is True:
return self.connection

connection_kwargs = {}

if self.connection_data.get("api_key", None):
Expand Down
Loading
Loading