fake-api-server.ci.surveillance.component.github¶
This module provides functionality to interact with GitHub repositories using the PyGithub library. It facilitates operations such as connecting to a repository, retrieving labels, and creating pull requests, while also utilizing Python context management for ease of use.
GitHubOperation()
¶
Handles operations related to GitHub repositories including connecting to a repository, managing labels, and creating pull requests.
This class is designed to interact with GitHub repositories using the official
PyGithub
library. It provides utility methods to facilitate repository
connectivity and certain operations like fetching labels and creating pull
requests. It also implements context manager protocol for clean resource
handling and initialization of repositories.
ATTRIBUTE | DESCRIPTION |
---|---|
_github |
An instance of the
|
_github_repo |
An optional reference to the connected GitHub repository.
TYPE:
|
_repo_init_params |
Stores repository initialization parameters during the repository connection process.
TYPE:
|
_repo_all_labels |
A list of all labels available in the connected repository.
TYPE:
|
Source code in fake_api_server_plugin/ci/surveillance/component/github_opt.py
_get_all_labels()
¶
Retrieves all labels associated with the connected GitHub repository.
This method fetches all the labels available in the currently connected GitHub repository. If the repository connection is not established prior to calling this method, it raises a runtime error.
RETURNS | DESCRIPTION |
---|---|
List[Label]
|
A list of all labels from the GitHub repository. |
RAISES | DESCRIPTION |
---|---|
RuntimeError
|
If the GitHub repository is not connected. |
Source code in fake_api_server_plugin/ci/surveillance/component/github_opt.py
connect_repo(repo_owner, repo_name)
¶
Connects to a GitHub repository and initializes its labels.
This function takes the owner and name of a GitHub repository, connects to the repository using the GitHub API client, and retrieves all existing labels for later processing.
PARAMETER | DESCRIPTION |
---|---|
repo_owner
|
The username or organization name of the repository owner.
TYPE:
|
repo_name
|
The name of the repository to connect to.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None |
Source code in fake_api_server_plugin/ci/surveillance/component/github_opt.py
create_pull_request(title, body, base_branch, head_branch, draft=False, labels=[])
¶
Creates a pull request in the connected GitHub repository. This method initializes and creates a new pull request with the specified details, including title, description, base and head branches, draft status, and labels. If successful, the new pull request is returned; otherwise, logs the failure and returns None.
PARAMETER | DESCRIPTION |
---|---|
title
|
The title of the pull request.
TYPE:
|
body
|
The description or body of the pull request.
TYPE:
|
base_branch
|
The name of the branch to merge into (base branch).
TYPE:
|
head_branch
|
The name of the branch to merge from (head branch).
TYPE:
|
draft
|
Indicates whether the pull request is to be created as a draft. Default is False.
TYPE:
|
labels
|
A list of label names to attach to the pull request. Default is an empty list.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Optional[PullRequest]
|
The created pull request object if successful, otherwise None. |
RAISES | DESCRIPTION |
---|---|
RuntimeError
|
If a connection to the target GitHub repository has not been established. |