Skip to content

Commit

Permalink
Merge branch 'm-kovalsky/issue370'
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kovalsky committed Dec 19, 2024
2 parents 7b02333 + 2d9c20c commit 60b5858
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/sempy_labs/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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",
Expand Down
73 changes: 66 additions & 7 deletions src/sempy_labs/_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://learn.microsoft.com/rest/api/fabric/core/git/connect>`_.
Expand All @@ -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 <https://learn.microsoft.com/rest/api/fabric/core/git/connect?tabs=HTTP#gitprovidertype>`_.
workspace : str | uuid.UUID, default=None
The Fabric workspace name or ID.
Defaults to None which resolves to the workspace of the attached lakehouse
Expand All @@ -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,
Expand All @@ -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 <https://learn.microsoft.com/rest/api/fabric/core/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."
)


Expand Down
4 changes: 4 additions & 0 deletions src/sempy_labs/_job_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"),
Expand Down

0 comments on commit 60b5858

Please sign in to comment.