Updating Content Git Repository Settings
Problem
You need to change the Git repository settings for a Git-backed content item.
You might need to do this in situations where the git repository has migrated from one location or host to another, or if the branch of the repository has been renamed, deleted, or otherwise changed.
Solution
Use the PUT /v1/content/{content_guid}/repository
endpoint to modify Git settings. The endpoint lets you modify:
- the respository URL.
- the branch the content is deployed from.
- the path within the repository where the content is located.
- whether Connect should periodically check the repository for updates.
This recipe requires the following inputs:
- The
content_guid
for the content item that you want to modify. - The git repository settings to modify from the existing settings. You may change any or all of the following:
repository
: The URL of the git repository.branch
: The branch of the git repository.directory
: The directory path within the repository.polling
: A boolean TRUE/FALSE indicating whether the repository should be periodically polled for updates.
from posit import connect
= connect.Client()
client
#### User-defined inputs ####
# 1. Specify the guid for the content item you want to modify
= "INSERT_CONTENT_GUID"
content_guid # 2. Below in the code, find the section titled "Update data to reflect new settings."
# Modify any lines you wish to modify. Comment out any lines you do not wish to modify.
###########################
# Retrieve current git settings for content
= client.content.get(content_guid)
content = content.repository
repository
# Update data to reflect new settings.
# Update the lines below for the settings you want to change and specify the values.
# Comment out any lines you do not wish to modify.
repository.update(="https://example.gitrepository.com/my-repo.git",
repository="branch-name",
branch=".",
directory=True
polling
)
# View updated git settings for content
= content.repository updated_settings
>>> updated_settings
'repository': 'https://gitlab.com/my-new-organization/my-relocated-repo.git',
{'branch': 'main',
'directory': '.',
'polling': True}
library(connectapi)
library(glue)
library(tibble)
<- connect()
client
#### User-defined inputs ####
# 1. specify the guid for the content item you want to modify
<- "INSERT_CONTENT_GUID"
content_guid # 2. Below in the code, find the section titled "Update data to reflect new settings."
# Modify any lines you wish to modify. Comment out any lines you do not wish to modify.
###########################
# Retrieve current git settings for content
<- client$GET(glue::glue("/v1/content/{content_guid}/repository"))
data
# Update data to reflect new settings.
# Update the lines below for the settings you want to change and specify the values.
# Comment out any lines you do not wish to modify.
$repository <- "https://example.gitrepository.com/my-repo.git"
data$branch <- "branch-name"
data$directory <- "."
data$polling <- TRUE
data
# Update and view the git settings for the content.
$PUT(glue::glue("/v1/content/{content_guid}/repository"), body=data)
client
# View updated git settings for content
<- client$GET(glue::glue("/v1/content/{content_guid}/repository")) |>
updated_settings as_tibble()
> updated_settings
# A tibble: 1 × 4
repository branch directory polling<chr> <chr> <chr> <lgl>
1 https://gitlab.com/my-new-organization/my-relocated-repo.git main . TRUE