Reference
Functions
build_github_repo_url(service_account_name, service_account_token, repo_namespace, repo_name, domain_name='github.com')
Build github repo_url with the intention of providing as the repo_url
argument to get_updated_repo
.
This factory function is specific to github, and might not support url schemas of different git services.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service_account_name |
str |
Name of the Github service account used to clone repository. |
required |
service_account_token |
str |
Raw token associated with the provided Github service account name. |
required |
repo_namespace |
str |
The namespace of the target repository. |
required |
repo_name |
str |
The name of the target repository. |
required |
domain_name |
str |
Github domain, allows us to point to instances other than public Github. |
'github.com' |
get_updated_repo(repo_url, clone_dir, **kwargs)
Clone the default branch of the target repository, returning a repo object.
If repo is already present, we will pull in the latest changes to the default branch of the repo.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo_url |
str |
URL of the Github repository to be cloned. |
required |
clone_dir |
Union[pathlib.Path, str] |
The empty directory to clone repository content to. |
required |
Exceptions:
Type | Description |
---|---|
PyGitOpsError |
There was an error cloning the repository. |
get_default_branch(repo)
Get the default branch of the provided repository.
Although Git itself does not have a concept of default branches, a default branch on a GitHub repository maps directly to the HEAD symbolic ref. Pull in remote branches and update local head refs pointing to the remote repository. We expect the HEAD ref to match a particular pattern that we regex against.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo |
Repo |
git.Repo instance. |
required |
Returns:
Type | Description |
---|---|
str |
string representing name of default branch. |
feature_branch(repo, branch_name)
Checkout the desired feature branch.
Return to the default branch when context is exited.
The main responsibility of this context manager is to limit concurrent operations on the local filesystem via the FileLock.
Local git commit operations in particular should leverage this behavior.
Assumes default branch is checked out, otherwise raises PyGitOpsError
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo |
Repo |
Repository object |
required |
branch_name |
str |
str object indicating the branch we would like to checkout |
required |
Exceptions:
Type | Description |
---|---|
PyGitOpsError |
There was an error performing the feature branch operation. |
stage_commit_push_changes(repo, branch_name, actor, commit_message, items_to_stage=None)
Handles the logic of persisting filesystem changes to a local repository via a commit to a feature branch.
This includes staging, committing, and pushing the local changes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo |
Repo |
Repository object. |
required |
branch_name |
str |
Feature branch from which changes will be committed and pushed. |
required |
actor |
Actor |
The Github actor with which to perform the commit operation. |
required |
commit_message |
str |
Text to be used as the commit message. |
required |
items_to_stage |
Optional[List[pathlib.Path]] |
List of files and directories that will be staged for commit, if None will include all changes. |
None |
Exceptions:
Type | Description |
---|---|
PyGitOpsStagedItemsError |
There were no items to stage. |
PyGitOpsError |
There was an error staging, committing, or pushing code. |
Exceptions
PyGitOpsError
Parent exception class for all errors coming from pygitops
package.
PyGitOpsValueError
The provided argument is invalid.
PyGitOpsStagedItemsError
There were no items to stage for commit.