Skip to content

Commit 7a879fc

Browse files
committed
split git file
1 parent 5bf11c7 commit 7a879fc

File tree

3 files changed

+72
-63
lines changed

3 files changed

+72
-63
lines changed

src/sempy_labs/admin/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
list_workspace_access_details,
1111
list_activity_events,
1212
list_modified_workspaces,
13-
list_git_connections,
1413
list_reports,
1514
)
1615
from sempy_labs.admin._domains import (
@@ -33,6 +32,9 @@
3332
list_external_data_shares,
3433
revoke_external_data_share,
3534
)
35+
from sempy_labs.admin._git import (
36+
list_git_connections,
37+
)
3638

3739
__all__ = [
3840
"list_items",

src/sempy_labs/admin/_basic_functions.py

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -927,68 +927,6 @@ def _resolve_workspace_name_and_id(
927927
return workspace_name, workspace_id
928928

929929

930-
def list_git_connections() -> pd.DataFrame:
931-
"""
932-
Shows a list of Git connections.
933-
934-
This is a wrapper function for the following API: `Workspaces - List Git Connections <https://learn.microsoft.com/rest/api/fabric/admin/workspaces/list-git-connections>`_.
935-
936-
Returns
937-
-------
938-
pandas.DataFrame
939-
A pandas dataframe showing a list of Git connections.
940-
"""
941-
942-
client = fabric.FabricRestClient()
943-
response = client.get("/v1/admin/workspaces/discoverGitConnections")
944-
945-
df = pd.DataFrame(
946-
columns=[
947-
"Workspace Id",
948-
"Organization Name",
949-
"Owner Name",
950-
"Project Name",
951-
"Git Provider Type",
952-
"Repository Name",
953-
"Branch Name",
954-
"Directory Name",
955-
]
956-
)
957-
958-
if response.status_code != 200:
959-
raise FabricHTTPException(response)
960-
961-
responses = pagination(client, response)
962-
963-
for r in responses:
964-
for v in r.get("value", []):
965-
git = v.get("gitProviderDetails", {})
966-
new_data = {
967-
"Workspace Id": v.get("workspaceId"),
968-
"Organization Name": git.get("organizationName"),
969-
"Owner Name": git.get("ownerName"),
970-
"Project Name": git.get("projectName"),
971-
"Git Provider Type": git.get("gitProviderType"),
972-
"Repository Name": git.get("repositoryName"),
973-
"Branch Name": git.get("branchName"),
974-
"Directory Name": git.get("directoryName"),
975-
}
976-
977-
df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True)
978-
979-
dfW = list_workspaces()
980-
df = pd.merge(
981-
df, dfW[["Id", "Name"]], left_on="Workspace Id", right_on="Id", how="left"
982-
)
983-
new_col_name = "Workspace Name"
984-
df = df.rename(columns={"Name": new_col_name})
985-
df.insert(1, new_col_name, df.pop(new_col_name))
986-
987-
df = df.drop(columns=["Id"])
988-
989-
return df
990-
991-
992930
def list_reports(
993931
top: Optional[int] = None, skip: Optional[int] = None, filter: Optional[str] = None
994932
) -> pd.DataFrame:

src/sempy_labs/admin/_git.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import sempy.fabric as fabric
2+
from sempy.fabric.exceptions import FabricHTTPException
3+
from sempy_labs._helper_functions import (
4+
pagination,
5+
)
6+
import pandas as pd
7+
from sempy_labs.admin._basic_functions import list_workspaces
8+
9+
10+
def list_git_connections() -> pd.DataFrame:
11+
"""
12+
Shows a list of Git connections.
13+
14+
This is a wrapper function for the following API: `Workspaces - List Git Connections <https://learn.microsoft.com/rest/api/fabric/admin/workspaces/list-git-connections>`_.
15+
16+
Returns
17+
-------
18+
pandas.DataFrame
19+
A pandas dataframe showing a list of Git connections.
20+
"""
21+
22+
client = fabric.FabricRestClient()
23+
response = client.get("/v1/admin/workspaces/discoverGitConnections")
24+
25+
df = pd.DataFrame(
26+
columns=[
27+
"Workspace Id",
28+
"Organization Name",
29+
"Owner Name",
30+
"Project Name",
31+
"Git Provider Type",
32+
"Repository Name",
33+
"Branch Name",
34+
"Directory Name",
35+
]
36+
)
37+
38+
if response.status_code != 200:
39+
raise FabricHTTPException(response)
40+
41+
responses = pagination(client, response)
42+
43+
for r in responses:
44+
for v in r.get("value", []):
45+
git = v.get("gitProviderDetails", {})
46+
new_data = {
47+
"Workspace Id": v.get("workspaceId"),
48+
"Organization Name": git.get("organizationName"),
49+
"Owner Name": git.get("ownerName"),
50+
"Project Name": git.get("projectName"),
51+
"Git Provider Type": git.get("gitProviderType"),
52+
"Repository Name": git.get("repositoryName"),
53+
"Branch Name": git.get("branchName"),
54+
"Directory Name": git.get("directoryName"),
55+
}
56+
57+
df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True)
58+
59+
dfW = list_workspaces()
60+
df = pd.merge(
61+
df, dfW[["Id", "Name"]], left_on="Workspace Id", right_on="Id", how="left"
62+
)
63+
new_col_name = "Workspace Name"
64+
df = df.rename(columns={"Name": new_col_name})
65+
df.insert(1, new_col_name, df.pop(new_col_name))
66+
67+
df = df.drop(columns=["Id"])
68+
69+
return df

0 commit comments

Comments
 (0)