How to use gitlabform - 10 common examples

To help you get started, we’ve selected a few gitlabform examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github egnyte / gitlabform / gitlabform / gitlab / commits.py View on Github external
from gitlabform.gitlab.core import GitLabCore


class GitLabCommits(GitLabCore):

    def get_commit(self, project_and_group_name, sha):
        return self._make_requests_to_api("projects/%s/repository/commits/%s", (project_and_group_name, sha))

    def get_ahead_and_behind(self, project_and_group_name, protected_branch, feature_branch):
        ahead = 0
        behind = 0

        response = self._make_requests_to_api("projects/%s/repository/compare?from=%s&to=%s",
                                              (project_and_group_name, protected_branch, feature_branch))
        if len(response) > 0:
            ahead = len(response['commits'])

        response = self._make_requests_to_api("projects/%s/repository/compare?from=%s&to=%s",
                                              (project_and_group_name, feature_branch, protected_branch))
        if len(response) > 0:
github egnyte / gitlabform / gitlabform / gitlabform / core.py View on Github external
for tag in sorted(configuration['tags']):
            try:
                if configuration['tags'][tag]['protected']:
                    create_access_level = configuration['tags'][tag]['create_access_level'] if \
                        'create_access_level' in configuration['tags'][tag] else None
                    logging.debug("Setting tag '%s' as *protected*", tag)
                    try:
                        # try to unprotect first
                        self.gl.unprotect_tag(project_and_group, tag)
                    except NotFoundException:
                        pass
                    self.gl.protect_tag(project_and_group, tag, create_access_level)
                else:
                    logging.debug("Setting tag '%s' as *unprotected*", tag)
                    self.gl.unprotect_tag(project_and_group, tag)
            except NotFoundException:
                logging.warning("! Tag '%s' not found when trying to set it as protected/unprotected", tag)
                if self.args.strict:
                    exit(3)
github egnyte / gitlabform / gitlabform / gitlab / core.py View on Github external
self.session.mount('http://', HTTPAdapter(max_retries=retries))
        self.session.mount('https://', HTTPAdapter(max_retries=retries))
        self.session.verify = self.ssl_verify

        try:
            version = self._make_requests_to_api("version")
            logging.info("Connected to GitLab version: %s (%s)" % (version['version'], version['revision']))
        except Exception as e:
            raise TestRequestFailedException(e)
        try:
            api_version = configuration.get("gitlab|api_version")
            if api_version != 4:
                raise ApiVersionIncorrectException(e)
            logging.info("Config file is declared to be compatible with GitLab API v4")
        except KeyNotFoundException:
            logging.fatal("Aborting. GitLabForm 1.0.0 has switched from GitLab API v3 to v4 in which some parameter "
                          "names have changed. By its design GitLabForm reads some parameter names directly from "
                          "config.yml so you need to update those names by yourself. See changes in config.yml "
                          "in this diff to see what had to be changed there: "
                          "https://github.com/egnyte/gitlabform/pull/28/files . "
                          "After updating your config.yml please add 'api_version' key to 'gitlab' section and set it "
                          "to 4 to indicate that your config is v4-compatible.")
            sys.exit(3)
github egnyte / gitlabform / gitlabform / configuration / core.py View on Github external
To get the dict under it use: get("group_settings|sddc|deploy_keys")

        :return: element from YAML file (dict, array, string...)
        """
        tokens = path.split('|')
        current = self.config_from_file

        try:
            for token in tokens:
                current = current[token]
        except:
            if default is not None:
                return default
            else:
                raise KeyNotFoundException

        return current
github egnyte / gitlabform / gitlabform / gitlabform / core.py View on Github external
def initialize_configuration_and_gitlab(self):

        try:
            gl = GitLab(self.args.config.strip())
            c = Configuration(self.args.config.strip())
            return gl, c
        except ConfigFileNotFoundException as e:
            logging.fatal('Aborting - config file not found at: %s', e)
            sys.exit(1)
        except TestRequestFailedException as e:
            logging.fatal("Aborting - GitLab test request failed, details: '%s'", e)
            sys.exit(2)
github egnyte / gitlabform / gitlabform / gitlabform / core.py View on Github external
def initialize_configuration_and_gitlab(self):

        try:
            gl = GitLab(self.args.config.strip())
            c = Configuration(self.args.config.strip())
            return gl, c
        except ConfigFileNotFoundException as e:
            logging.fatal('Aborting - config file not found at: %s', e)
            sys.exit(1)
        except TestRequestFailedException as e:
            logging.fatal("Aborting - GitLab test request failed, details: '%s'", e)
            sys.exit(2)
github egnyte / gitlabform / gitlabform / gitlabform / core.py View on Github external
def initialize_configuration_and_gitlab(self):

        try:
            gl = GitLab(self.args.config.strip())
            c = Configuration(self.args.config.strip())
            return gl, c
        except ConfigFileNotFoundException as e:
            logging.fatal('Aborting - config file not found at: %s', e)
            sys.exit(1)
        except TestRequestFailedException as e:
            logging.fatal("Aborting - GitLab test request failed, details: '%s'", e)
            sys.exit(2)
github egnyte / gitlabform / gitlabform / gitlabform / core.py View on Github external
def initialize_configuration_and_gitlab(self):

        try:
            gl = GitLab(self.args.config.strip())
            c = Configuration(self.args.config.strip())
            return gl, c
        except ConfigFileNotFoundException as e:
            logging.fatal('Aborting - config file not found at: %s', e)
            sys.exit(1)
        except TestRequestFailedException as e:
            logging.fatal("Aborting - GitLab test request failed, details: '%s'", e)
            sys.exit(2)
github egnyte / gitlabform / gitlabform / gitlab / core.py View on Github external
self.session = requests.Session()

        retries = Retry(total=3,
                        backoff_factor=0.25,
                        status_forcelist=[500, 502, 503, 504])

        self.session.mount('http://', HTTPAdapter(max_retries=retries))
        self.session.mount('https://', HTTPAdapter(max_retries=retries))
        self.session.verify = self.ssl_verify

        try:
            version = self._make_requests_to_api("version")
            logging.info("Connected to GitLab version: %s (%s)" % (version['version'], version['revision']))
        except Exception as e:
            raise TestRequestFailedException(e)
        try:
            api_version = configuration.get("gitlab|api_version")
            if api_version != 4:
                raise ApiVersionIncorrectException(e)
            logging.info("Config file is declared to be compatible with GitLab API v4")
        except KeyNotFoundException:
            logging.fatal("Aborting. GitLabForm 1.0.0 has switched from GitLab API v3 to v4 in which some parameter "
                          "names have changed. By its design GitLabForm reads some parameter names directly from "
                          "config.yml so you need to update those names by yourself. See changes in config.yml "
                          "in this diff to see what had to be changed there: "
                          "https://github.com/egnyte/gitlabform/pull/28/files . "
                          "After updating your config.yml please add 'api_version' key to 'gitlab' section and set it "
                          "to 4 to indicate that your config is v4-compatible.")
            sys.exit(3)
github egnyte / gitlabform / gitlabform / gitlab / core.py View on Github external
backoff_factor=0.25,
                        status_forcelist=[500, 502, 503, 504])

        self.session.mount('http://', HTTPAdapter(max_retries=retries))
        self.session.mount('https://', HTTPAdapter(max_retries=retries))
        self.session.verify = self.ssl_verify

        try:
            version = self._make_requests_to_api("version")
            logging.info("Connected to GitLab version: %s (%s)" % (version['version'], version['revision']))
        except Exception as e:
            raise TestRequestFailedException(e)
        try:
            api_version = configuration.get("gitlab|api_version")
            if api_version != 4:
                raise ApiVersionIncorrectException(e)
            logging.info("Config file is declared to be compatible with GitLab API v4")
        except KeyNotFoundException:
            logging.fatal("Aborting. GitLabForm 1.0.0 has switched from GitLab API v3 to v4 in which some parameter "
                          "names have changed. By its design GitLabForm reads some parameter names directly from "
                          "config.yml so you need to update those names by yourself. See changes in config.yml "
                          "in this diff to see what had to be changed there: "
                          "https://github.com/egnyte/gitlabform/pull/28/files . "
                          "After updating your config.yml please add 'api_version' key to 'gitlab' section and set it "
                          "to 4 to indicate that your config is v4-compatible.")
            sys.exit(3)