gitlab_management.base module

class gitlab_management.base.GitlabManagement(GitLab_URL: str, GitLab_PrivateToken: str, Authenticate: bool = True)[source]

Bases: object

No Fuss Computing’s Gitlab Config Management python module.

Config[source]
CreateGroupLabel(Group: gitlab.v4.objects.Group, Name: str, Description: str, Color: str) → bool[source]

Create a group label within the specified group

Parameters:
  • Group (gitlab.v4.objects.Group) – A gitlab group Object
  • Name (str) – The name of the label to create
  • Description (str) – The description for the label. the description will be prefixed with [Managed Label] to denote this script created the label.
  • Color (str) – the colour that the label shoud be in format ‘#RRGGBB’
Raises:
  • Exception – Generic catch all Exception is returned, however the exception will be printed to the console

  • gitlab.GitlabHttpError – A http error occured, the output should denote what the issue is

  • gitlab.GitlabCreateError – a check for ‘409: label exists’, as no attempt should be made to create a label when the check has already been done.

    Warning

    if any other status is returned, then an issue should be raised.

Returns:

if the string was successfully created, true is returned. false will be returned when there was an exception

Return type:

bool

See also

Dependent Methods:
GetLabelByName Output
DesiredOutputLevel[source]
GetConfig() → bool[source]

Read all of the config.yml config file to an object in this class.

Raises:
  • yaml.YAMLError – any error with the yml, will return the text output
  • Exception – Generic catch all exception. if this exception occurs, please log an issue ticket.
Returns:

returns success/failure on reading the config and adding to the class object self.Config

Return type:

bool

See also

Dependent Methods:
Output
Help
config.yml
GetGroupByName(GroupName: str) → gitlab.v4.objects.Group[source]

Find and return a group by name.

Workflow 1. Find all groups that the current user (the one authorized in this module) has maintainer access to 2. check if the group has been cached, if not cach the groups for subsequent use so that additional API calls don’t have to be made. 3. create an empty Labels group in the group object so that if a request for group labels is made, this can be checked for None if they haven’t been fetched before. 4. iterate through all returned groups until the group is found that matches the string.

Parameters:

GroupName (str) – description

Raises:

Exception – Generic catch all exception. if this method returns an exception please log an issue.

# ToDo: add proper error checking and exception checking.

Returns:

  • gitlab.v4.objects.Group – The Group that matches the search string will be returned.
  • None – Returned if nothing found

See also

Dependent Methods:
Output
issue #8
Feature: Groups now cached
GetLabelByName(Group: gitlab.v4.objects.Group, LabelName: str) → gitlab.v4.objects.GroupLabel[source]

Finds a label by human readable name and returns a gitlab.v4.objects.GroupLabel object.

Workflow: 1. Check if the labels for the group have been cached, if not cache them. 1. iterate through each label in the group until the LabelName matches. 2. return the label as a gitlab.v4.objects.GroupLabel

Parameters:
  • Group (gitlab.v4.objects.Group) – The group that is being searched.
  • LabelName (str) – The group name to search for.
Raises:

Exception – Generic catch all exception. if this method returns an exception please log an issue.

Returns:

  • gitlab.v4.objects.GroupLabel – returns the object that has a name that matches what was searched for.
  • None – Only returned if no group is found.

See also

Dependent Methods:
ProcessConfigLabels Output
Help
Labels
issue #8
Feature: Labels now cached
GitlabLoginAuthenticate(URL: str, PrivateToken: str, Authenticate: bool = True) → bool[source]

Establish the Gitlab instance to connect to and authenticate.

Parameters:
  • URL (str) – The url of the gitlab instance to connect to.
  • PrivateToken (str) – The private token of the user that will be used to authenticate against the gitlab instance.
Raises:
  • gitlab.GitlabAuthenticationError – Returns text output of the failed authentication issue that occured when attemping to authenticate.
  • Exception – Generic catch all exception.
Returns:

Returns bool to denote success/failure of the connection and authentication.

Return type:

bool

See also

Dependent Methods:
Output
GitlabObjectCache[source]

Cache the objects fetched via the GitLab API

See also

Dependent Methods:
Nil
issue #8
Feature: Groups now cached
GitlabSession[source]
Output(OutputLevel: gitlab_management.base.GitlabManagement.OutputSeverity, OutputMessage: str) → None[source]

Method to output commands to the console.

Parameters:
Raises:

Exception – None raised. # ToDo: do proper error and exception handling.

Returns:

This method does not require output as it is part of the error handling of the application.

Return type:

None

See also

Dependent Methods:
Nil
class OutputSeverity[source]

Bases: enum.Enum

An enumeration.

Alert = 1[source]
Critical = 2[source]
Debug = 7[source]
Emergency = 0[source]
Error = 3[source]
Informational = 6[source]
Notice = 5[source]
Warning = 4[source]
ProcessConfigLabels(ConfigGroups: list) → bool[source]

Process the provided configuration labels.

load the labels from the config file and create for each group that has been specified for the label.

The array that is passed to the function is processed as follows.

  1. iterates through list of labels
  2. finds the group id that the label is for
  3. confirms that label attributes are in the config file Group, Name, Description and color.
  4. creates the label in each group that the label is intended for. CreateGroupLabel() does the check to see if it exists before creating it.
Parameters:ConfigGroups (list) – The labels array from the config.yml file
Raises:Exception – currently is a catch all exception. if this function returns an exception, an issue needs to be raised.
Returns:returns bool denoting success/failure for the processing of the labels provided.
Return type:bool

See also

Dependent Methods:
GetGroupByName GetLabelByName Output
Help
configuration Labels
issue #8
Feature: Labels now cached
_Config = None[source]
_DesiredOutputLevel = None[source]
_GitlabObjectCache = None[source]

Cache the objects fetched via the GitLab API

_GitlabSession = None[source]
get_detail(ItemName: str)[source]
gitlab = <module 'gitlab' from '/home/docs/checkouts/readthedocs.org/user_builds/python-gitlab-management/envs/stable/lib/python3.7/site-packages/gitlab/__init__.py'>[source]
logging = <module 'logging' from '/home/docs/.pyenv/versions/3.7.3/lib/python3.7/logging/__init__.py'>[source]
traceback = <module 'traceback' from '/home/docs/.pyenv/versions/3.7.3/lib/python3.7/traceback.py'>[source]