diff --git a/src/sempy_labs/__init__.py b/src/sempy_labs/__init__.py index e1e3897..da57e48 100644 --- a/src/sempy_labs/__init__.py +++ b/src/sempy_labs/__init__.py @@ -1,6 +1,4 @@ -from sempy_labs._job_scheduler import ( - list_item_job_instances -) +from sempy_labs._job_scheduler import list_item_job_instances from sempy_labs._gateways import ( list_gateway_members, list_gateway_role_assigments, @@ -163,7 +161,8 @@ commit_to_git, initialize_git_connection, update_from_git, - connect_workspace_to_git, + connect_workspace_to_azure_dev_ops, + connect_workspace_to_github, disconnect_workspace_from_git, ) from sempy_labs._dataflows import ( @@ -371,7 +370,8 @@ "commit_to_git", "initialize_git_connection", "update_from_git", - "connect_workspace_to_git", + "connect_workspace_to_azure_dev_ops", + "connect_workspace_to_github", "disconnect_workspace_from_git", "create_environment", "delete_environment", diff --git a/src/sempy_labs/_git.py b/src/sempy_labs/_git.py index 584bc8b..5da7621 100644 --- a/src/sempy_labs/_git.py +++ b/src/sempy_labs/_git.py @@ -10,17 +10,16 @@ from uuid import UUID -def connect_workspace_to_git( +def connect_workspace_to_azure_dev_ops( organization_name: str, project_name: str, repository_name: str, branch_name: str, directory_name: str, - git_provider_type: str = "AzureDevOps", workspace: Optional[str | UUID] = None, ): """ - Connects a workspace to a git repository. + Connects a workspace to an Azure DevOps git repository. This is a wrapper function for the following API: `Git - Connect `_. @@ -36,8 +35,6 @@ def connect_workspace_to_git( The branch name. directory_name : str The directory name. - git_provider_type : str, default="AzureDevOps" - A `Git provider type `_. workspace : str | uuid.UUID, default=None The Fabric workspace name or ID. Defaults to None which resolves to the workspace of the attached lakehouse @@ -50,7 +47,7 @@ def connect_workspace_to_git( "gitProviderDetails": { "organizationName": organization_name, "projectName": project_name, - "gitProviderType": git_provider_type, + "gitProviderType": "AzureDevOps", "repositoryName": repository_name, "branchName": branch_name, "directoryName": directory_name, @@ -65,7 +62,69 @@ def connect_workspace_to_git( raise FabricHTTPException(response) print( - f"{icons.green_dot} The '{workspace_name}' workspace has been connected to the '{project_name}' Git project within the '{repository_name}' repository." + f"{icons.green_dot} The '{workspace_name}' workspace has been connected to the '{project_name}' Git project in Azure DevOps within the '{repository_name}' repository." + ) + + +def connect_workspace_to_github( + owner_name: str, + repository_name: str, + branch_name: str, + directory_name: str, + connection_id: UUID, + source: str = "ConfiguredConnection", + workspace: Optional[str | UUID] = None, +): + """ + Connects a workspace to a GitHub git repository. + + This is a wrapper function for the following API: `Git - Connect `_. + + Parameters + ---------- + owner_name : str + The owner name. + repository_name : str + The repository name. + branch_name : str + The branch name. + directory_name : str + The directory name. + source : str, default="ConfiguredConnection" + The Git credentials source. + connection_id : uuid.UUID + The object ID of the connection. + workspace : str | uuid.UUID, default=None + The Fabric workspace name or ID. + Defaults to None which resolves to the workspace of the attached lakehouse + or if no lakehouse attached, resolves to the workspace of the notebook. + """ + + (workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace) + + request_body = { + "gitProviderDetails": { + "ownerName": owner_name, + "gitProviderType": "GitHub", + "repositoryName": repository_name, + "branchName": branch_name, + "directoryName": directory_name, + }, + "myGitCredentials": { + "source": source, + "connectionId": connection_id, + }, + } + + client = fabric.FabricRestClient() + response = client.post( + f"/v1/workspaces/{workspace_id}/git/connect", json=request_body + ) + if response.status_code != 200: + raise FabricHTTPException(response) + + print( + f"{icons.green_dot} The '{workspace_name}' workspace has been connected to the '{repository_name}' GitHub repository." ) diff --git a/src/sempy_labs/_job_scheduler.py b/src/sempy_labs/_job_scheduler.py index 5f57642..8643638 100644 --- a/src/sempy_labs/_job_scheduler.py +++ b/src/sempy_labs/_job_scheduler.py @@ -51,7 +51,9 @@ def list_item_job_instances( df = pd.DataFrame( columns=[ "Job Instance Id", + "Item Name", "Item Id", + "Item Type", "Job Type", "Invoke Type", "Status", @@ -71,7 +73,9 @@ def list_item_job_instances( for v in r.get("value", []): new_data = { "Job Instance Id": v.get("id"), + "Item Name": item_name, "Item Id": v.get("itemId"), + "Item Type": type, "Job Type": v.get("jobType"), "Invoke Type": v.get("invokeType"), "Status": v.get("status"),