104
.gitlab-ci.yml
104
.gitlab-ci.yml
@ -1,5 +1,5 @@
|
||||
#variables:
|
||||
# Release_TAG: Publish-$CI_COMMIT_SHORT_SHA
|
||||
variables:
|
||||
CI_BRANCH: $CI_COMMIT_BRANCH
|
||||
|
||||
|
||||
stages:
|
||||
@ -196,8 +196,11 @@ gitlab-management_package:
|
||||
before_script:
|
||||
- *PythonImageBuildModuleBefore_Script
|
||||
- git --version
|
||||
- python3 -m pip install --user --upgrade twine
|
||||
script:
|
||||
- python3 setup.py egg_info sdist bdist_wheel
|
||||
after_script:
|
||||
- python3 -m twine upload --verbose --repository-url https://gitlab.com/api/v4/projects/19099644/packages/pypi --username $LOCAL_PYPI_USER --password $LOCAL_PYPI_PASSWORD dist/*
|
||||
rules:
|
||||
- if: $CI_COMMIT_TAG
|
||||
when: never
|
||||
@ -276,8 +279,6 @@ pages:
|
||||
changes:
|
||||
- gitlab_management/*.py
|
||||
- setup.py
|
||||
- README.md
|
||||
- CONTRIBUTING.md
|
||||
when: on_success
|
||||
|
||||
|
||||
@ -345,7 +346,6 @@ gemnasium-python-dependency_scanning:
|
||||
when: never
|
||||
- if: $CI_COMMIT_BRANCH
|
||||
changes:
|
||||
- gitlab_management/*.py
|
||||
- setup.py
|
||||
- requirements.txt
|
||||
- requirements.pip
|
||||
@ -372,11 +372,11 @@ license_scanning:
|
||||
when: never
|
||||
- if: $CI_COMMIT_BRANCH
|
||||
changes:
|
||||
- gitlab_management/*.py
|
||||
- setup.py
|
||||
when: on_success
|
||||
allow_failure: false
|
||||
|
||||
|
||||
Documentation:
|
||||
stage: validate
|
||||
image: readthedocs/build:latest
|
||||
@ -412,7 +412,8 @@ Documentation:
|
||||
**Build Pipeline:** [Pipeline-$CI_PIPELINE_ID]($CI_PIPELINE_URL)
|
||||
**Commit:** $CI_COMMIT_SHA
|
||||
**Module Version:** $Release_TAG
|
||||
**PyPi Module Link (pip)** https://pypi.org/project/gitlab-management/$Release_TAG/
|
||||
**PyPi Module Link (pip)** https://pypi.org/project/gitlab-management/$Release_TAG/
|
||||
**Docker Hub:** https://hub.docker.com/r/nofusscomputing/gitlab-management
|
||||
|
||||
This release supercedes previous versions" --tag-name $Release_TAG
|
||||
|
||||
@ -425,6 +426,8 @@ GitLab-Release:
|
||||
script:
|
||||
- Release_TAG=$(cat $CI_PROJECT_DIR/dist/version)
|
||||
- *ReleaseScript
|
||||
after_script:
|
||||
- export
|
||||
dependencies:
|
||||
- gitlab-management_package
|
||||
- Docker_Build-Alpine
|
||||
@ -435,63 +438,76 @@ GitLab-Release:
|
||||
when: never
|
||||
- if: '$CI_COMMIT_BRANCH == "master"'
|
||||
when: on_success
|
||||
allow_failure: false
|
||||
- if: '$CI_COMMIT_BRANCH == "development"'
|
||||
when: on_success
|
||||
allow_failure: false
|
||||
- if: '$CI_COMMIT_BRANCH != "master"'
|
||||
when: never
|
||||
|
||||
|
||||
Test_Publish:
|
||||
stage: publish
|
||||
image: python:3.6.9-slim
|
||||
variables:
|
||||
GIT_STRATEGY: none
|
||||
before_script:
|
||||
- python3 -m pip install --user --upgrade twine
|
||||
script:
|
||||
- rm $CI_PROJECT_DIR/dist/version
|
||||
- python3 -m twine upload --verbose --username __token__ --password $NFC_TOKEN_TESTPYPI --repository testpypi dist/*
|
||||
dependencies:
|
||||
- gitlab-management_package
|
||||
- Docker_Build-Alpine
|
||||
rules:
|
||||
- if: $CI_COMMIT_TAG
|
||||
when: never
|
||||
- if: $CI_MERGE_REQUEST_IID
|
||||
when: never
|
||||
- if: '$CI_COMMIT_BRANCH == "development"'
|
||||
when: never
|
||||
- if: '$CI_COMMIT_BRANCH != "master"'
|
||||
changes:
|
||||
- gitlab_management/*.py
|
||||
- setup.py
|
||||
- README.md
|
||||
- CONTRIBUTING.md
|
||||
- if: '$CI_COMMIT_BRANCH != "master" && $CI_COMMIT_BRANCH != "development"'
|
||||
when: manual
|
||||
allow_failure: true
|
||||
environment:
|
||||
name: Release-PyPi
|
||||
|
||||
|
||||
Publish:
|
||||
PyPi:
|
||||
stage: publish
|
||||
image: python:3.6.9-slim
|
||||
variables:
|
||||
GIT_STRATEGY: none
|
||||
before_script:
|
||||
- python3 -m pip install --user --upgrade twine
|
||||
- pip3 download gitlab_management==$CI_COMMIT_TAG -f --pre --no-deps --index-url https://$LOCAL_PYPI_USER:$LOCAL_PYPI_PASSWORD@gitlab.com/api/v4/projects/19099644/packages/pypi/simple/ -d dist/
|
||||
- pip3 download gitlab_management==$CI_COMMIT_TAG --no-binary ":all:" -f --pre --no-deps --index-url https://$LOCAL_PYPI_USER:$LOCAL_PYPI_PASSWORD@gitlab.com/api/v4/projects/19099644/packages/pypi/simple/ -d dist/ --isolated || true
|
||||
script:
|
||||
- rm $CI_PROJECT_DIR/dist/version
|
||||
- python3 -m twine upload --verbose --username __token__ --password $NFC_TOKEN_PYPI dist/*
|
||||
dependencies:
|
||||
- gitlab-management_package
|
||||
- Docker_Build-Alpine
|
||||
- GitLab-Release
|
||||
rules:
|
||||
- if: $CI_COMMIT_TAG
|
||||
when: never
|
||||
when: on_success
|
||||
- if: $CI_MERGE_REQUEST_IID
|
||||
when: never
|
||||
- if: '$CI_COMMIT_BRANCH == "master"'
|
||||
- if: '$CI_COMMIT_BRANCH'
|
||||
when: never
|
||||
environment:
|
||||
name: Release-PyPi
|
||||
|
||||
|
||||
Docker Hub:
|
||||
stage: publish
|
||||
image: docker:latest
|
||||
services:
|
||||
- docker:19.03.11-dind
|
||||
before_script:
|
||||
- export
|
||||
- docker login $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
|
||||
- docker pull $CI_REGISTRY_IMAGE/gitlab-management:$CI_COMMIT_SHA
|
||||
- docker logout $CI_REGISTRY
|
||||
script:
|
||||
# - Release_TAG=$(cat $CI_PROJECT_DIR/dist/version)
|
||||
- docker login docker.io -u nofusscomputing -p $NFC_DOCKERHUB_TOKEN
|
||||
- if [ "m$(echo $CI_BUILD_REF_NAME | grep rc)" == "m$CI_BUILD_REF_NAME" ]; then Branch_TAG=dev; else Branch_TAG=stable; fi
|
||||
- echo Branch tag is $Branch_TAG
|
||||
- docker image ls
|
||||
- docker image tag $CI_REGISTRY_IMAGE/gitlab-management:$CI_COMMIT_SHA nofusscomputing/gitlab-management:$CI_BUILD_TAG
|
||||
- docker image tag $CI_REGISTRY_IMAGE/gitlab-management:$CI_COMMIT_SHA nofusscomputing/gitlab-management:$Branch_TAG
|
||||
- docker image ls
|
||||
- docker push nofusscomputing/gitlab-management:$Branch_TAG
|
||||
- docker push nofusscomputing/gitlab-management:$CI_BUILD_TAG
|
||||
rules:
|
||||
- if: $CI_COMMIT_TAG
|
||||
when: on_success
|
||||
- if: '$CI_COMMIT_BRANCH == "development"'
|
||||
when: manual
|
||||
allow_failure: true
|
||||
- if: $CI_MERGE_REQUEST_IID
|
||||
when: never
|
||||
- if: '$CI_COMMIT_BRANCH'
|
||||
when: never
|
||||
dependencies:
|
||||
- gitlab-management_package
|
||||
- Docker_Build-Alpine
|
||||
- GitLab-Release
|
||||
tags:
|
||||
- docker
|
||||
environment:
|
||||
name: Release-DockerHub
|
||||
|
||||
@ -34,5 +34,5 @@ logs, and code as it's tough to read otherwise.) -->
|
||||
|
||||
* [ ] ~Documentation, documentation changes completed *(if applicable)*
|
||||
|
||||
/label ~Bug ~"Documentation::Not Started"
|
||||
/label ~Bug ~"documentation::not started" ~"workflow::not started"
|
||||
/cc @jon_nfc
|
||||
|
||||
@ -23,4 +23,4 @@ Add all known Documentation Requirements in this section.
|
||||
* [ ] ~Documentation, documentation changes completed *(if applicable)*
|
||||
|
||||
|
||||
/label ~Feature ~"Documentation::Not Started"
|
||||
/label ~Feature ~"documentation::not started" ~"workflow::not started"
|
||||
|
||||
@ -4,9 +4,13 @@
|
||||
|
||||
## Merge Request Tasks
|
||||
|
||||
* [ ] ~Documentation for all related issues completed as *applicable*
|
||||
* [ ] ~"Code Review::Complete" and covering all versions
|
||||
* [ ] ~"documentation::complete" for all related issues completed as *applicable*
|
||||
* [ ] ~"code review::complete" and covering all versions
|
||||
* [ ] Package version incremented
|
||||
* [ ] Issue close in commit tag (*if applicable*) i.e. `fixes #{Issue Number}`
|
||||
* [ ] Squash commit flag checked
|
||||
* [ ] close or fixes #issuenumber added to squash commit message
|
||||
|
||||
|
||||
|
||||
/label ~"Code Review::Not Started" ~"Documentation::Not Started"
|
||||
/label ~"code review::not started" ~"documentation::not started"
|
||||
13
README.md
13
README.md
@ -61,6 +61,19 @@ Group:
|
||||
`Group.Labels.#.Group` can be a single string which is the name of an existing group that the user has access to as maintainer. `Group.Labels.#.Group` can also be a `list` of group names that the label will be added to.
|
||||
|
||||
|
||||
### Docker container
|
||||
further help can be found in the [documentation](https://python-gitlab-management.readthedocs.io/en/development/pages/docker.html).
|
||||
|
||||
The docker images have been desigend to run the module directly as a command, where you only have to specify the `CLI` arguments.
|
||||
|
||||
images are tagged for ease of idententification in accordance with the table below:
|
||||
|
||||
| Tag | repo branch | When created |
|
||||
|--------------------|:---------------:|:------:|
|
||||
| `{Version number}` | Git Tag | every git tag will create it's version |
|
||||
| `dev` | development | when a merge to development branch occurs or a git tag is created on a branch not master. |
|
||||
| `stable` | master | when a merge to master branch occurs |
|
||||
|
||||
## Issues, Feature Requests and Bugs
|
||||
If an issue or bug is found within the package (i.e. exception), please [create an issue ticket](https://gitlab.com/nofusscomputing/projects/python-gitlab-management/-/issues) using the applicable issue template available at the time of ticket creation. If you would like to request a feature and are unable to contribute, [please create an issue](https://gitlab.com/nofusscomputing/projects/python-gitlab-management/-/issues) using the feature issue template.
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ __license__ = "GNU LGPLv3"
|
||||
__copyright__ = "(C) All Rights reserved"
|
||||
__source__ = ''
|
||||
__title__ = "gitlab-management"
|
||||
__version__ = "0.1.5"
|
||||
__version__ = "0.2.0"
|
||||
__doc__ = "https://gitlab.com/nofusscomputing/projects/python-gitlab-management"
|
||||
|
||||
CurrentDirectory = './'
|
||||
@ -47,7 +47,7 @@ def init() -> bool:
|
||||
__source__ = 'https://gitlab.com/nofusscomputing/projects/python-gitlab-management/-/tree/' + GIT_COMMIT
|
||||
|
||||
if GIT_BRANCH != 'master':
|
||||
__version__ = __version__ + '.rc' + datetime.utcnow().strftime('%y%m%d%H%M%S')
|
||||
__version__ = __version__ + 'rc' + datetime.utcnow().strftime('%y%m%d%H%M%S')
|
||||
|
||||
|
||||
if not os.path.isdir(CurrentDirectory + DistributionDirectory):
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
# Docker
|
||||
The module has been built into a docker container that can be found on docker hub. by design the container does not need a command to be specified at runtime, as the `ENTRYPOINT` has been set to `gitlab-management`. Therefore you only need to specify the arguments for `gitlab-management`. If you fail to specify any arguments in the `docker run` command, gitlab-management help will be displayed
|
||||
The module has been built into a docker container that can be found on [docker hub](https://hub.docker.com/r/nofusscomputing/gitlab-management). by design the container does not need a command to be specified at runtime, as the `ENTRYPOINT` has been set to `gitlab-management`. Therefore you only need to specify the arguments for `gitlab-management`. If you fail to specify any arguments in the `docker run` command, gitlab-management help will be displayed
|
||||
|
||||
## Building
|
||||
**To Build, execute the following:**
|
||||
|
||||
@ -15,9 +15,9 @@ class GitlabManagement:
|
||||
import logging
|
||||
from enum import Enum
|
||||
|
||||
|
||||
|
||||
_GitlabSession:gitlab.Gitlab = None
|
||||
|
||||
|
||||
@property
|
||||
def GitlabSession(self) -> gitlab.Gitlab:
|
||||
|
||||
@ -34,12 +34,12 @@ class GitlabManagement:
|
||||
def GitlabSession(self, oSession):
|
||||
|
||||
if type(oSession) is self.gitlab.Gitlab or type(oSession) is None:
|
||||
|
||||
|
||||
self._GitlabSession = oSession
|
||||
|
||||
else:
|
||||
raise TypeError("GitlabSession can only be type 'None' or 'gitlab.Gitlab' [{}] is neither".format(str(oSession)))
|
||||
|
||||
|
||||
|
||||
|
||||
_DesiredOutputLevel:int = None
|
||||
@ -72,7 +72,7 @@ class GitlabManagement:
|
||||
return self._Config
|
||||
|
||||
class OutputSeverity(Enum):
|
||||
|
||||
|
||||
Emergency:int = 0
|
||||
Alert:int = 1
|
||||
Critical:int = 2
|
||||
@ -98,11 +98,11 @@ class GitlabManagement:
|
||||
Feature: Groups now cached
|
||||
|
||||
"""
|
||||
|
||||
|
||||
return self._GitlabObjectCache
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def __init__(self, GitLab_URL:str, GitLab_PrivateToken:str, Authenticate:bool = True):
|
||||
|
||||
@ -164,9 +164,9 @@ class GitlabManagement:
|
||||
|
||||
try:
|
||||
GitlabLogin = self.gitlab.Gitlab(URL, private_token=PrivateToken)
|
||||
|
||||
|
||||
GitlabLogin.headers['User-Agent'] = "%s/%s %s" % (self.get_detail('title'), self.get_detail('version'), self.get_detail('doc'))
|
||||
|
||||
|
||||
if Authenticate:
|
||||
GitlabLogin.auth()
|
||||
|
||||
@ -220,7 +220,7 @@ class GitlabManagement:
|
||||
if OutputLevel.value <= self.DesiredOutputLevel.value:
|
||||
print(str(OutputLevel.name) + ': ' + OutputMessage)
|
||||
|
||||
|
||||
|
||||
def GetConfig(self) -> bool:
|
||||
"""
|
||||
Read all of the `config.yml` config file to an object in this class.
|
||||
@ -250,7 +250,7 @@ class GitlabManagement:
|
||||
|
||||
"""
|
||||
import yaml
|
||||
|
||||
|
||||
GetConfig = False
|
||||
|
||||
with open("config.yml", 'r') as stream:
|
||||
@ -266,7 +266,7 @@ class GitlabManagement:
|
||||
|
||||
except Exception as e:
|
||||
self.Output(self.OutputSeverity.Critical, logging.error(traceback.format_exc()))
|
||||
|
||||
|
||||
return GetConfig
|
||||
|
||||
|
||||
@ -320,11 +320,11 @@ class GitlabManagement:
|
||||
CreateGroupLabel = False
|
||||
|
||||
if type(Group) == self.gitlab.v4.objects.Group:
|
||||
|
||||
|
||||
try:
|
||||
|
||||
if self.GetLabelByName(Group, Name) is None:
|
||||
|
||||
|
||||
NewLabelString['name'] = Name
|
||||
NewLabelString['description'] = '[Managed Label] ' + Description
|
||||
NewLabelString['color'] = Color
|
||||
@ -332,7 +332,7 @@ class GitlabManagement:
|
||||
Group.labels.create(NewLabelString)
|
||||
|
||||
self.Output(self.OutputSeverity.Notice, 'Created label {} in group {}'.format(NewLabelString['name'], Group.attributes['name']))
|
||||
|
||||
|
||||
else:
|
||||
|
||||
self.Output(self.OutputSeverity.Debug, 'Label {} exists in group {}'.format(Name, Group.attributes['name']))
|
||||
@ -406,7 +406,7 @@ class GitlabManagement:
|
||||
try:
|
||||
|
||||
if self.GitlabObjectCache['Groups'] is None:
|
||||
|
||||
|
||||
Groups = self.GitlabSession.groups.list(min_access_level = self.gitlab.MAINTAINER_ACCESS)
|
||||
|
||||
self.GitlabObjectCache['Groups'] = {}
|
||||
@ -431,13 +431,13 @@ class GitlabManagement:
|
||||
for GroupID in Groups:
|
||||
|
||||
if Groups[GroupID]['GroupObject'].attributes['name'] == GroupName:
|
||||
|
||||
|
||||
GetGroupByName = Groups[GroupID]['GroupObject']
|
||||
|
||||
|
||||
except Exception as e:
|
||||
|
||||
self.Output(self.OutputSeverity.Critical, logging.error(traceback.format_exc()))
|
||||
|
||||
|
||||
return GetGroupByName
|
||||
|
||||
|
||||
@ -497,7 +497,7 @@ class GitlabManagement:
|
||||
CachedGroupLabels = self.GitlabObjectCache['Groups'][str(Group.attributes['id'])]['Labels']
|
||||
|
||||
if CachedGroupLabels is None:
|
||||
|
||||
|
||||
Labels = Group.labels.list(all=True)
|
||||
|
||||
LabelCount:int = 0
|
||||
@ -505,7 +505,7 @@ class GitlabManagement:
|
||||
for LabletoCount in Labels:
|
||||
LabelCount += 1
|
||||
self.Output(self.OutputSeverity.Debug, 'Caching label "{}", id "{}" from group {}'.format(LabletoCount.attributes['name'], LabletoCount.attributes['id'], Group.attributes['name']))
|
||||
|
||||
|
||||
self.GitlabObjectCache['Groups'][str(Group.attributes['id'])]['Labels'] = Labels
|
||||
|
||||
self.Output(self.OutputSeverity.Informational, 'caching "{}" labels for group "{}"'.format(str(LabelCount), str(Group.attributes['name'])))
|
||||
@ -517,7 +517,7 @@ class GitlabManagement:
|
||||
GetLabelByName = Label
|
||||
|
||||
exit
|
||||
|
||||
|
||||
except Exception as e:
|
||||
|
||||
self.Output(self.OutputSeverity.Critical, logging.error(traceback.format_exc()))
|
||||
@ -582,7 +582,6 @@ class GitlabManagement:
|
||||
|
||||
if 'Group' in Label and 'Name' in Label and 'Description' in Label and 'Color' in Label:
|
||||
|
||||
|
||||
if type(Label['Group']) is list:
|
||||
|
||||
for Group in Label['Group']:
|
||||
@ -594,7 +593,6 @@ class GitlabManagement:
|
||||
else:
|
||||
|
||||
self.CreateGroupLabel(self.GetGroupByName(Label['Group']), Label['Name'], Label['Description'], Label['Color'])
|
||||
|
||||
|
||||
else:
|
||||
self.Output(self.OutputSeverity.Error, 'missing the Group for the label')
|
||||
|
||||
Reference in New Issue
Block a user