Skip to content

Git

ado_connect(workspace, *, organization_name, project_name, repository_name, branch_name='main', directory_name='/', credential_type='user')

Connects a Fabric workspace to an Azure DevOps repository.

Parameters:

Name Type Description Default
workspace str

The name of the Fabric workspace.

required
organization_name str

The name of the Azure DevOps organization.

required
project_name str

The name of the Azure DevOps project.

required
repository_name str

The name of the Azure DevOps repository.

required
branch_name str

The name of the branch to connect to.

'main'
directory_name str

The path to the folder where the repository is located. Defaults to "/".

'/'
credential_type Literal['spn', 'user']

The type of credentials to use for the Git connection. Defaults to "user".

'user'

Returns:

Name Type Description
bool bool

True if the connection was successful, False otherwise.

Raises:

Type Description
ValueError

If the workspace cannot be resolved.

Examples:

ado_connect(
    workspace='my_workspace',
    organization_name='my_organization',
    project_name='my_project',
    repository_name='my_repository',
    branch_name='main',
    directory_name='/'
)
Source code in src/pyfabricops/core/git.py
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
def ado_connect(
    workspace: str,
    *,
    organization_name: str,
    project_name: str,
    repository_name: str,
    branch_name: str = 'main',
    directory_name: str = '/',
    credential_type: Literal['spn', 'user'] = 'user',
) -> bool:
    """
    Connects a Fabric workspace to an Azure DevOps repository.

    Args:
        workspace (str): The name of the Fabric workspace.
        organization_name (str): The name of the Azure DevOps organization.
        project_name (str): The name of the Azure DevOps project.
        repository_name (str): The name of the Azure DevOps repository.
        branch_name (str): The name of the branch to connect to.
        directory_name (str, optional): The path to the folder where the repository is located. Defaults to "/".
        credential_type (Literal["spn", "user"], optional):
            The type of credentials to use for the Git connection. Defaults to "user".

    Returns:
        bool: True if the connection was successful, False otherwise.

    Raises:
        ValueError: If the workspace cannot be resolved.

    Examples:
        ```python
        ado_connect(
            workspace='my_workspace',
            organization_name='my_organization',
            project_name='my_project',
            repository_name='my_repository',
            branch_name='main',
            directory_name='/'
        )
        ```
    """
    payload = {
        'gitProviderDetails': {
            'gitProviderType': 'AzureDevOps',
            'organizationName': organization_name,
            'projectName': project_name,
            'repositoryName': repository_name,
            'branchName': branch_name,
            'directoryName': directory_name,
        }
    }
    return api_request(
        endpoint='/workspaces/'
        + resolve_workspace(workspace)
        + '/git/connect',
        method='post',
        payload=payload,
        credential_type=credential_type,
    )

commit_to_git(workspace, *, mode='All', comment=None, selective_payload=None, credential_type='spn', df=False)

Commits all changes from a Fabric/Power BI workspace to Git.

Parameters:

Name Type Description Default
workspace str

The name or ID of the Fabric workspace.

required
mode Literal['All', 'Selective']

The mode of the commit. "All" commits all changes, "Selective" commits only selected changes. Defaults to "All".

'All'
selective_payload dict

The payload containing the specific changes to commit when in "Selective" mode. See Microsoft documentation for details on the structure of this payload. https://learn.microsoft.com/en-us/rest/api/fabric/core/git/commit-to-git?tabs=HTTP#itemidentifier

None
comment str

A comment for the commit. Defaults to None.

None
credential_type Literal['spn', 'user']

The type of credentials to use for the Git connection. Defaults to "spn".

'spn'
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

False

Returns:

Type Description
Union[DataFrame, Dict[str, Any], None]

The response data from the API if successful, or None if the workspace cannot be resolved.

Raises:

Type Description
ValueError

If the workspace cannot be resolved.

Examples:

commit_to_git(
    workspace='my_workspace',
    mode='Selective'
)
Source code in src/pyfabricops/core/git.py
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
def commit_to_git(
    workspace: str,
    *,
    mode: Literal['All', 'Selective'] = 'All',
    comment: str = None,
    selective_payload: dict = None,
    credential_type: Literal['spn', 'user'] = 'spn',
    df: Optional[bool] = False,
) -> Union[DataFrame, Dict[str, Any], None]:
    """
    Commits all changes from a Fabric/Power BI workspace to Git.

    Args:
        workspace (str): The name or ID of the Fabric workspace.
        mode (Literal["All", "Selective"], optional):
            The mode of the commit. "All" commits all changes, "Selective" commits only selected changes. Defaults to "All".
        selective_payload (dict, optional):
            The payload containing the specific changes to commit when in "Selective" mode.
            See Microsoft documentation for details on the structure of this payload.
            https://learn.microsoft.com/en-us/rest/api/fabric/core/git/commit-to-git?tabs=HTTP#itemidentifier
        comment (str, optional): A comment for the commit. Defaults to None.
        credential_type (Literal["spn", "user"], optional):
            The type of credentials to use for the Git connection. Defaults to "spn".
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.

    Returns:
        (Union[DataFrame, Dict[str, Any], None]): The response data from the API if successful, or None if the workspace cannot be resolved.

    Raises:
        ValueError: If the workspace cannot be resolved.

    Examples:
        ```python
        commit_to_git(
            workspace='my_workspace',
            mode='Selective'
        )
        ```
    """
    workspace_id = resolve_workspace(workspace)
    if not workspace_id:
        return None

    payload = {'mode': mode}

    if comment:
        payload['comment'] = comment

    if mode == 'Selective' and selective_payload:
        # If in selective mode, include the specific changes to commit
        payload.update(selective_payload)

    return api_request(
        endpoint=f'/workspaces/{workspace_id}/git/commitToGit',
        method='post',
        payload=payload,
        credential_type=credential_type,
        support_lro=True,
    )

get_git_connection(workspace, *, credential_type='spn', df=False)

Retrieves the Git connections for a Fabric workspace.

Parameters:

Name Type Description Default
workspace str

The name or ID of the Fabric workspace.

required
credential_type Literal['spn', 'user']

The type of credentials to use for the Git connection. Defaults to "user".

'spn'
df bool

Keyword-only. If True, returns a DataFrame with flattened keys. Defaults to False.

False

Returns:

Name Type Description
dict dict

The Git connections for the workspace if successful, or None if the workspace cannot be resolved.

Raises:

Type Description
ValueError

If the workspace cannot be resolved.

Examples:

get_git_connection(
    workspace='my_workspace'
)
Source code in src/pyfabricops/core/git.py
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
@df
def get_git_connection(
    workspace: str,
    *,
    credential_type: Literal['spn', 'user'] = 'spn',
    df: bool = False,
) -> dict:
    """
    Retrieves the Git connections for a Fabric workspace.

    Args:
        workspace (str): The name or ID of the Fabric workspace.
        credential_type (Literal["spn", "user"], optional):
            The type of credentials to use for the Git connection. Defaults to "user".
        df (bool, optional): Keyword-only. If True, returns a DataFrame with flattened keys. Defaults to False.

    Returns:
        dict: The Git connections for the workspace if successful, or None if the workspace cannot be resolved.

    Raises:
        ValueError: If the workspace cannot be resolved.

    Examples:
        ```python
        get_git_connection(
            workspace='my_workspace'
        )
        ```
    """
    return api_request(
        endpoint='/workspaces/'
        + resolve_workspace(workspace)
        + '/git/connection',
        credential_type=credential_type,
    )

get_my_git_credentials(workspace, *, credential_type='spn', df=False)

Retrieves the Git credentials for a Fabric workspace.

Parameters:

Name Type Description Default
workspace str

The name or ID of the Fabric workspace.

required
credential_type Literal['spn', 'user']

The type of credentials to use for the Git connection. Defaults to "spn".

'spn'
df bool

Keyword-only. If True, returns a DataFrame with flattened keys. Defaults to False.

False

Returns:

Name Type Description
dict dict

The Git credentials for the workspace if successful, or None if the workspace cannot be resolved.

Raises:

Type Description
ValueError

If the workspace cannot be resolved.

Examples:

get_my_git_credentials(
    workspace='my_workspace'
)
Source code in src/pyfabricops/core/git.py
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
@df
def get_my_git_credentials(
    workspace: str,
    *,
    credential_type: Literal['spn', 'user'] = 'spn',
    df: bool = False,
) -> dict:
    """
    Retrieves the Git credentials for a Fabric workspace.

    Args:
        workspace (str): The name or ID of the Fabric workspace.
        credential_type (Literal["spn", "user"], optional):
            The type of credentials to use for the Git connection. Defaults to "spn".
        df (bool, optional): Keyword-only. If True, returns a DataFrame with flattened keys. Defaults to False.

    Returns:
        dict: The Git credentials for the workspace if successful, or None if the workspace cannot be resolved.

    Raises:
        ValueError: If the workspace cannot be resolved.

    Examples:
        ```python
        get_my_git_credentials(
            workspace='my_workspace'
        )
        ```
    """
    return api_request(
        endpoint='/workspaces/'
        + resolve_workspace(workspace)
        + '/git/myGitCredentials',
        credential_type=credential_type,
    )

git_disconnect(workspace, *, credential_type='spn')

Disconnects the workspace from Git.

Parameters:

Name Type Description Default
workspace str

The name or ID of the Fabric workspace.

required
credential_type Literal['spn', 'user']

The type of credentials to use for the Git connection. Defaults to "spn".

'spn'

Returns:

Name Type Description
bool None

True if the disconnection was successful, False otherwise.

Raises:

Type Description
ValueError

If the workspace cannot be resolved.

Examples:

git_disconnect(
    workspace='my_workspace'
)
Source code in src/pyfabricops/core/git.py
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
def git_disconnect(
    workspace: str, *, credential_type: Literal['spn', 'user'] = 'spn'
) -> None:
    """
    Disconnects the workspace from Git.

    Args:
        workspace (str): The name or ID of the Fabric workspace.
        credential_type (Literal["spn", "user"], optional):
            The type of credentials to use for the Git connection. Defaults to "spn".

    Returns:
        bool: True if the disconnection was successful, False otherwise.

    Raises:
        ValueError: If the workspace cannot be resolved.

    Examples:
        ```python
        git_disconnect(
            workspace='my_workspace'
        )
        ```
    """
    response = api_request(
        '/workspaces/' + resolve_workspace(workspace) + '/git/disconnect',
        method='post',
        credential_type=credential_type,
        return_raw=True,
    )
    if response.status_code == 200:
        logger.success('Successfully disconnected from Git.')
        return None
    else:
        logger.error('Failed to disconnect from Git.')
        return None

git_init(workspace, *, initialize_strategy='PreferWorkspace', credential_type='spn', df=False)

Initializes a Fabric workspace to use Git for version control.

Parameters:

Name Type Description Default
workspace str

The name or ID of the Fabric workspace.

required
initialize_strategy Literal['PreferWorkspace', 'PreferRemote', 'None']

The strategy to use for initialization. Defaults to "PreferWorkspace".

'PreferWorkspace'
credential_type Literal['spn', 'user']

The type of credentials to use for the Git connection. Defaults to "spn".

'spn'
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

False

Returns:

Type Description
Union[DataFrame, Dict[str, Any], None]

The response data from the API if successful, or None if the workspace cannot be resolved.

Raises:

Type Description
ValueError

If the workspace cannot be resolved.

Examples:

git_init(
    workspace='my_workspace',
    initialize_strategy='PreferWorkspace',
    provider='GitHub'
)
Source code in src/pyfabricops/core/git.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
@df
def git_init(
    workspace: str,
    *,
    initialize_strategy: Literal[
        'PreferWorkspace', 'PreferRemote', 'None'
    ] = 'PreferWorkspace',
    credential_type: Literal['spn', 'user'] = 'spn',
    df: Optional[bool] = False,
) -> Union[DataFrame, Dict[str, Any], None]:
    """
    Initializes a Fabric workspace to use Git for version control.

    Args:
        workspace (str): The name or ID of the Fabric workspace.
        initialize_strategy (Literal["PreferWorkspace", "PreferRemote", "None"], optional):
            The strategy to use for initialization. Defaults to "PreferWorkspace".
        credential_type (Literal["spn", "user"], optional):
            The type of credentials to use for the Git connection. Defaults to "spn".
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.


    Returns:
        (Union[DataFrame, Dict[str, Any], None]): The response data from the API if successful, or None if the workspace cannot be resolved.

    Raises:
        ValueError: If the workspace cannot be resolved.

    Examples:
        ```python
        git_init(
            workspace='my_workspace',
            initialize_strategy='PreferWorkspace',
            provider='GitHub'
        )
        ```
    """
    workspace_id = resolve_workspace(workspace)
    if not workspace_id:
        return None

    payload = {'initializationStrategy': initialize_strategy}

    return api_request(
        method='post',
        endpoint=f'/workspaces/{workspace_id}/git/initializeConnection',
        payload=payload,
        credential_type=credential_type,
        support_lro=True,
    )

git_status(workspace, *, credential_type='spn', df=True)

Retrieve the Git status of the workspace.

Parameters:

Name Type Description Default
workspace str

The name or ID of the Fabric workspace.

required
credential_type Literal['spn', 'user']

The type of credentials to use for the Git connection. Defaults to "spn".

'spn'
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

True

Returns:

Type Description
Union[DataFrame, Dict[str, Any], None]

The Git status of the workspace if successful, or None if the workspace cannot be resolved.

Raises:

Type Description
ValueError

If the workspace cannot be resolved.

Examples:

git_status(
    workspace='my_workspace',
    provider='GitHub'
)
Source code in src/pyfabricops/core/git.py
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
@df
def git_status(
    workspace: str,
    *,
    credential_type: Literal['spn', 'user'] = 'spn',
    df: Optional[bool] = True,
) -> Union[DataFrame, Dict[str, Any], None]:
    """
    Retrieve the Git status of the workspace.

    Args:
        workspace (str): The name or ID of the Fabric workspace.
        credential_type (Literal["spn", "user"], optional):
            The type of credentials to use for the Git connection. Defaults to "spn".
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.

    Returns:
        (Union[DataFrame, Dict[str, Any], None]): The Git status of the workspace if successful, or None if the workspace cannot be resolved.

    Raises:
        ValueError: If the workspace cannot be resolved.

    Examples:
        ```python
        git_status(
            workspace='my_workspace',
            provider='GitHub'
        )
        ```
    """
    workspace_id = resolve_workspace(workspace)
    if not workspace_id:
        return None

    return api_request(
        endpoint=f'/workspaces/{workspace_id}/git/status',
        credential_type=credential_type,
        support_lro=True,
    )

github_connect(workspace, connection, owner_name, repository_name, *, branch_name='main', directory_name='/', credential_type='spn')

Connects a Fabric workspace to a Git repository.

Parameters:

Name Type Description Default
workspace str

The name or ID of the Fabric workspace.

required
connection str

The name or ID of the Git connection.

required
owner_name str

The name of the owner of the Git repository.

required
repository_name str

The name of the repository of the Git repository.

required
branch_name str

The name of the branch to connect to.

'main'
directory_name str

The path to the folder where the repository is located. Defaults to "/".

'/'
credential_type Literal['spn', 'user']

The type of credentials to use for the Git connection. Defaults to "spn".

'spn'

Returns:

Name Type Description
bool bool

True if the connection was successful, False otherwise.

Raises:

Type Description
ValueError

If the workspace or connection cannot be resolved.

Examples:

github_connect(
    workspace='my_workspace',
    connection='my_connection',
    owner_name='my_owner',
    repository_name='my_repository',
    branch_name='main',
    directory_name='/'
)
Source code in src/pyfabricops/core/git.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def github_connect(
    workspace: str,
    connection: str,
    owner_name: str,
    repository_name: str,
    *,
    branch_name: str = 'main',
    directory_name: str = '/',
    credential_type: Literal['spn', 'user'] = 'spn',
) -> bool:
    """
    Connects a Fabric workspace to a Git repository.

    Args:
        workspace (str): The name or ID of the Fabric workspace.
        connection (str): The name or ID of the Git connection.
        owner_name (str): The name of the owner of the Git repository.
        repository_name (str): The name of the repository of the Git repository.
        branch_name (str): The name of the branch to connect to.
        directory_name (str, optional): The path to the folder where the repository is located. Defaults to "/".
        credential_type (Literal["spn", "user"], optional):
            The type of credentials to use for the Git connection. Defaults to "spn".

    Returns:
        bool: True if the connection was successful, False otherwise.

    Raises:
        ValueError: If the workspace or connection cannot be resolved.

    Examples:
        ```python
        github_connect(
            workspace='my_workspace',
            connection='my_connection',
            owner_name='my_owner',
            repository_name='my_repository',
            branch_name='main',
            directory_name='/'
        )
        ```
    """
    workspace_id = resolve_workspace(workspace)
    if not workspace_id:
        return None

    connection_id = resolve_connection(connection)
    if not connection_id:
        return None

    # Prepare the payload for the Git connection
    payload = {
        'gitProviderDetails': {
            'ownerName': owner_name,
            'gitProviderType': 'GitHub',
            'repositoryName': repository_name,
            'branchName': branch_name,
            'directoryName': directory_name,
        },
        'myGitCredentials': {
            'source': 'ConfiguredConnection',
            'connectionId': connection_id,
        },
    }
    response = api_request(
        endpoint=f'/workspaces/{workspace_id}/git/connect',
        method='post',
        payload=payload,
        return_raw=True,
        credential_type=credential_type,
    )
    if not response.status_code == 200:
        logger.error(
            f"Failed to connect GitHub repository: {response.json().get('errorCode')} - {response.json().get('message')}"
        )
        return False
    else:
        logger.success(
            f"Successfully connected GitHub repository '{repository_name}' to workspace '{workspace_id}'."
        )
        return True

update_from_git(workspace, *, conflict_resolution_policy='PreferWorkspace', allow_override_items=True, credential_type='spn')

Poll the workspace"s Git status and update from Git if not up to date. Repeats until remoteCommitHash == workspaceHead or max retries reached.

Parameters:

Name Type Description Default
workspace str

The target workspace name or Id.

required
conflict_resolution_policy Literal['PreferRemote', 'PreferWorkspace']

The conflict resolution policy to use. Defaults to "PreferWorkspace".

'PreferWorkspace'
allow_override_items bool

Whether to allow overriding items. Defaults to True.

True
credential_type Literal['spn', 'user']

The type of credentials to use for the Git connection. Defaults to "spn".

'spn'

Raises:

Type Description
SystemExit

Exits with code 1 if max retries are reached without success.

Returns:

Name Type Description
bool bool

True if the workspace is up to date, False if it is still updating or an error occurred.

Examples:

update_from_git(
    workspace='my_workspace',
    conflict_resolution_policy='PreferRemote',
    allow_override_items=False
)
Source code in src/pyfabricops/core/git.py
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
def update_from_git(
    workspace: str,
    *,
    conflict_resolution_policy: Literal[
        'PreferRemote', 'PreferWorkspace'
    ] = 'PreferWorkspace',
    allow_override_items: bool = True,
    credential_type: Literal['spn', 'user'] = 'spn',
) -> bool:
    """
    Poll the workspace"s Git status and update from Git if not up to date.
    Repeats until remoteCommitHash == workspaceHead or max retries reached.

    Args:
        workspace (str): The target workspace name or Id.
        conflict_resolution_policy (Literal["PreferRemote", "PreferWorkspace"], optional):
            The conflict resolution policy to use. Defaults to "PreferWorkspace".
        allow_override_items (bool, optional): Whether to allow overriding items. Defaults to True.
        credential_type (Literal["spn", "user"], optional):
            The type of credentials to use for the Git connection. Defaults to "spn".

    Raises:
        SystemExit: Exits with code 1 if max retries are reached without success.

    Returns:
        bool: True if the workspace is up to date, False if it is still updating or an error occurred.

    Examples:
        ```python
        update_from_git(
            workspace='my_workspace',
            conflict_resolution_policy='PreferRemote',
            allow_override_items=False
        )
        ```
    """
    workspace_id = resolve_workspace(workspace)
    if not workspace_id:
        return None

    # Maximum number of attempts to poll/update the workspace
    MAX_RETRIES = 10

    # Time (in seconds) to wait between retry attempts
    RETRY_INTERVAL = 20

    for attempt in range(1, MAX_RETRIES + 1):
        logger.info(f'Attempt {attempt}/{MAX_RETRIES}: Checking Git status...')
        status = git_status(workspace_id, df=False)

        if not status:
            logger.info('No status retrieved; retrying after delay...')
            time.sleep(RETRY_INTERVAL)
            continue

        remote_commit = status.get('remoteCommitHash') or None
        workspace_head = status.get('workspaceHead') or None
        logger.info(
            f'Remote Commit: {remote_commit} | Workspace Head: {workspace_head}'
        )

        # If already up to date
        if (
            remote_commit
            and workspace_head
            and remote_commit == workspace_head
        ):
            logger.success('Workspace is already up to date.')
            return True

        # Not up to date—prepare updateFromGit request
        logger.info('Workspace out of sync. Issuing updateFromGit request...')
        payload = {
            'remoteCommitHash': remote_commit,
            'workspaceHead': workspace_head,
            'conflictResolution': {
                'conflictResolutionPolicy': conflict_resolution_policy,
                'conflictResolutionType': 'Workspace',
            },
            'options': {'allowOverrideItems': allow_override_items},
        }
        resp = api_request(
            method='post',
            endpoint=f'/workspaces/{workspace_id}/git/updateFromGit',
            payload=payload,
            return_raw=True,
        )

        if resp.status_code in [200, 202]:
            logger.info('Update request sent successfully.')
        else:
            logger.error(
                f'Failed to send update request: {resp.json().get("errorCode")} - {resp.json().get("message")}'
            )
            time.sleep(RETRY_INTERVAL)
            continue

        # Wait before re-checking status
        logger.info(
            f'Waiting {RETRY_INTERVAL} seconds before rechecking status...'
        )
        time.sleep(RETRY_INTERVAL)

        # Re-check status after sending update
        status_after = git_status(workspace_id, df=False)
        if status_after:
            remote_after = status_after.get('remoteCommitHash') or None
            head_after = status_after.get('workspaceHead') or None
            logger.warning(
                f'Post-update | Remote: {remote_after} | Head: {head_after}'
            )
            if remote_after and head_after and remote_after == head_after:
                logger.success(
                    'Update successful. Workspace is now up to date.'
                )
                return True
            else:
                logger.warning('Workspace still not up to date; retrying...')
        else:
            logger.error(
                'Failed to retrieve status after update attempt; retrying...'
            )
            return False
    logger.error('Max retries reached. The workspace may still be updating.')
    return False

update_my_git_connection(workspace, *, request_body_type='UpdateGitCredentialsToAutomaticRequest', connection_id=None, credential_type='spn')

Updates the Git connection for a Fabric workspace.

Parameters:

Name Type Description Default
workspace str

The name or ID of the Fabric workspace.

required
request_body_type Literal['UpdateGitCredentialsToAutomaticRequest', 'UpdateGitCredentialsToConfiguredConnectionRequest', 'UpdateGitCredentialsToNoneRequest']

The type of request body to use for the update. Defaults to "UpdateGitCredentialsToAutomaticRequest".

'UpdateGitCredentialsToAutomaticRequest'
connection_id str

The ID of the configured connection to use if request_body_type is "UpdateGitCredentialsToConfiguredConnectionRequest".

None
credential_type Literal['spn', 'user']

The type of credentials to use for the Git connection. Defaults to "spn".

'spn'

Returns:

Name Type Description
dict dict

The response data from the API if successful, or None if the workspace cannot be resolved.

Raises:

Type Description
ValueError

If the workspace cannot be resolved or if the request body type is invalid.

Examples:

update_my_git_connection(
    workspace='my_workspace',
    request_body_type='UpdateGitCredentialsToAutomaticRequest'
)
Source code in src/pyfabricops/core/git.py
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
def update_my_git_connection(
    workspace: str,
    *,
    request_body_type: Literal[
        'UpdateGitCredentialsToAutomaticRequest',
        'UpdateGitCredentialsToConfiguredConnectionRequest',
        'UpdateGitCredentialsToNoneRequest',
    ] = 'UpdateGitCredentialsToAutomaticRequest',
    connection_id: str = None,
    credential_type: Literal['spn', 'user'] = 'spn',
) -> dict:
    """
    Updates the Git connection for a Fabric workspace.

    Args:
        workspace (str): The name or ID of the Fabric workspace.
        request_body_type (Literal["UpdateGitCredentialsToAutomaticRequest", "UpdateGitCredentialsToConfiguredConnectionRequest", "UpdateGitCredentialsToNoneRequest"], optional):
            The type of request body to use for the update. Defaults to "UpdateGitCredentialsToAutomaticRequest".
        connection_id (str, optional): The ID of the configured connection to use if request_body_type is "UpdateGitCredentialsToConfiguredConnectionRequest".
        credential_type (Literal["spn", "user"], optional):
            The type of credentials to use for the Git connection. Defaults to "spn".

    Returns:
        dict: The response data from the API if successful, or None if the workspace cannot be resolved.

    Raises:
        ValueError: If the workspace cannot be resolved or if the request body type is invalid.

    Examples:
        ```python
        update_my_git_connection(
            workspace='my_workspace',
            request_body_type='UpdateGitCredentialsToAutomaticRequest'
        )
        ```
    """
    payload_automatic = {'source': 'Automatic'}
    payload_configured = {
        'source': 'ConfiguredConnection',
        'connectionId': connection_id,
    }
    payload_none = {'source': 'None'}
    if request_body_type == 'UpdateGitCredentialsToAutomaticRequest':
        payload = payload_automatic
    elif (
        request_body_type
        == 'UpdateGitCredentialsToConfiguredConnectionRequest'
    ):
        payload = payload_configured
    elif request_body_type == 'UpdateGitCredentialsToNoneRequest':
        payload = payload_none

    return api_request(
        endpoint=f'/workspaces/'
        + resolve_workspace(workspace)
        + '/git/myGitCredentials',
        method='patch',
        payload=payload,
        credential_type=credential_type,
    )