{"id":13478893,"url":"https://github.com/cClaude/gitlab-bash-api","last_synced_at":"2025-03-27T08:31:06.628Z","repository":{"id":29174454,"uuid":"98087988","full_name":"cClaude/gitlab-bash-api","owner":"cClaude","description":"  Configure GitLab using bash scripts","archived":false,"fork":false,"pushed_at":"2021-11-20T11:05:13.000Z","size":186,"stargazers_count":46,"open_issues_count":4,"forks_count":18,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-30T12:48:21.565Z","etag":null,"topics":["bash","gitlab","json"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cClaude.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-23T09:37:01.000Z","updated_at":"2024-06-03T18:09:27.000Z","dependencies_parsed_at":"2022-07-27T17:48:34.746Z","dependency_job_id":null,"html_url":"https://github.com/cClaude/gitlab-bash-api","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cClaude%2Fgitlab-bash-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cClaude%2Fgitlab-bash-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cClaude%2Fgitlab-bash-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cClaude%2Fgitlab-bash-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cClaude","download_url":"https://codeload.github.com/cClaude/gitlab-bash-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245809769,"owners_count":20676048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","gitlab","json"],"created_at":"2024-07-31T16:02:05.348Z","updated_at":"2025-03-27T08:31:06.113Z","avatar_url":"https://github.com/cClaude.png","language":"Shell","funding_links":[],"categories":["Shell"],"sub_categories":[],"readme":"**Table of Contents**\n\n* [GitLab bash API](#gitlab-bash-api)\n  * [Installation](#installation)\n  * [Configuration](#configuration)\n  * [Usage](#usage)\n    * [Generic GET](#generic-get)\n    * [Generic PUT](#generic-put)\n    * [About users](#about-users)\n    * [About groups](#about-groups)\n    * [About projects (repositories)](#about-projects-repositories)\n    * [About branches](#about-branches)\n  * [Audit and backups](#audit-and-backups)\n    * [Backups repositories](#backups-repositories)\n    * [Audit groups and repositories](#audit-groups-and-repositories)\n  * [Samples](#samples)\n  * [About GitLab and gitlab\\-bash\\-api](#about-gitlab-and-gitlab-bash-api)\n  * [Related documentations](#related-documentations)\n\nCreated by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc.go)\n\nGitLab bash API\n===============\n\nAccess [GitLab CE API](https://docs.gitlab.com/ce/api/) or [GitLab EE API](https://docs.gitlab.com/ee/api/) from bash.\n\nLast version is available on GitHub: https://github.com/cClaude/gitlab-bash-api\n\nCurrent version is based on [GitLab V4 API](https://docs.gitlab.com/ce/api/v3_to_v4.html) but some features work on V3.\nV3 is no more supported except by glGet and glPut commands.\n\n\nInstallation\n------------\n\nThis tool require `bash`, `curl`, `jq` and `git`.\n\n```bash\nsudo apt update\nsudo apt upgrade\nsudo apt install jq git\n\ngit clone https://github.com/cClaude/gitlab-bash-api.git\n```\n\n\nConfiguration\n-------------\n\nYou can create a `my-config` folder (ignored by git) to configure/customize this application or just copy content of `custom-config-sample/`.\nThe `my-config` folder is taken in account by default by the API\n\n\u003e You can also use any custom folder for configuration, by setting `GITLAB_BASH_API_CONFIG`\n\u003e variable with the full path of your custom folder.\n\nIn you configuration files:\n\n* You can create any custom file to declare variables (bash format), all theses files will be sourced.\n* You can override default values define in `config/` folder,\n* You need **at least** define values for `GITLAB_PRIVATE_TOKEN` and `GITLAB_URL_PREFIX`.\n\n```bash\nGITLAB_PRIVATE_TOKEN=__YOUR_GITLAB_TOKEN_HERE__\nGITLAB_URL_PREFIX=__YOUR_GITLAB_USER_HERE__\n```\n\nConfiguration algorithms :\n\n1. source files in `${GITLAB_BASH_API_PATH}/config`\n2. source files in `${GITLAB_BASH_API_PATH}/my-config` (if folder exists)\n3. source files in `${GITLAB_BASH_API_CONFIG}` (if variable is define and if folder exists)\n\n**Facultative configuration:**\n\nYou can also configure in you ~/.bashrc file\n\n```bash\nexport GITLAB_BASH_API_PATH='__YOUR_PATH_TO__/gitlab-bash-api'\nexport GITLAB_BASH_API_CONFIG=\"__YOUR_PATH_TO__/your-custom-config-folder\"\n\nPATH=$PATH:${GITLAB_BASH_API_PATH}/\n```\n\n**Hacking**\n\nIf for any reason you need to customize how curl access to GitLab server you can add some\ncustom configuration in `${GITLAB_BASH_API_PATH}/my-config` or in `${GITLAB_BASH_API_CONFIG}`\nfolders.\n\nA sample is available in `custom-config-sample/customize-curl.sh`.\n\n\nUsage\n-----\n\nYou can call comment using the full path\n\n```bash\n${GITLAB_BASH_API_PATH}/listUsers.sh --all\n```\n\nor simply (if **${GITLAB_BASH_API_PATH}** is in your path):\n\n```bash\nlistUsers.sh --all\n```\n\n### Generic GET\n\nSyntax:\n\u003e glGet.sh --uri GL_URI [--params 'PARAM1=VALUE1\u0026PARAM2=VALUE2]\n\n```bash\nglGet.sh --uri /projects | jq .\n```\n\n### Generic PUT\n\nSyntax:\n\u003e glPut.sh --uri GL_URI [--params 'PARAM1=VALUE1\u0026PARAM2=VALUE2]\n\n```bash\nTODO NEED SAMPLE\n```\n\n### About users\n\n* How to create a new user ?\n\nSyntax:\n\u003e glCreateUser.sh USER_NAME 'USER_FULLNAME' 'USER_EMAIL'\n\n```bash\nglCreateUser.sh testuser \"test user\" test-user@example.org\n```\n\n* How to display all users ?\n\n```bash\nlistUsers.sh --all\n```\n\n* How to display a specific user ?\n\n```bash\nlistUsers.sh testuser\n```\n\n\n### About groups\n\nHow to manage groups using **glGroups** command ?\n\n* **Usage**: Get groups configuration\n\n```bash\n    glGroups.sh --config --path GROUP_PATH\n    glGroups.sh --config --id GROUP_ID\n    glGroups.sh --config --all\n```\n\n* **Usage**: List groups paths\n\n```bash\n    glGroups.sh --list-path --path GROUP_PATH\n    glGroups.sh --list-path --id GROUP_ID\n    glGroups.sh --list-path --all\n```\n\n* **Usage**: List groups ids\n\n```bash\n    glGroups.sh --list-id --path GROUP_PATH\n    glGroups.sh --list-id --id GROUP_ID\n    glGroups.sh --list-id --all\n```\n\n* **Usage**: Create group\n\n```bash\n    glGroups.sh --create --path GROUP_PATH\n        [--name GROUP_NAME] \\\n        [--description GROUP_DESCRIPTION] \\\n        [--lfs_enabled true|false] \\\n        [--membership_lock true|false]\n        [--request_access_enabled true|false] \\\n        [--share_with_group_lock true|false]]\n        [--visibility  private|internal|public] \\\n```\n\n* **Usage**: Edit group configuration\n\n```bash\n    glGroups.sh --edit --id GROUP_ID --name GROUP_NAME --path GROUP_PATH \\\n        [--description GROUP_DESCRIPTION] \\\n        [--visibility  private|internal|public] \\\n        [--lfs_enabled true|false] \\\n        [--request_access_enabled true|false]\n```\n\n* **Usage**: Delete a group\n\n```bash\n    glGroups.sh --delete --id GROUP_ID\n```\n\n* **Sample**: Retrieve main configuration on all groups:\n\n```bash\nglGroups.sh --config --all\n```\n\n* **Sample**: create a group\n\n```bash\nglGroups.sh --create --path my_test_group\n```\n\n\n### About projects (repositories)\n\nHow to manage groups using `glProjects` command ?\n\n* **Usage**: Get projects configuration\n\n```bash\n    glProjects.sh --config [--compact] --id PROJECT_ID\n    glProjects.sh --config [--compact] --group-path GROUP_PATH\n    glProjects.sh --config [--compact] --all\n    glProjects.sh --config [--compact] --path PROJECT_PATH\n```\n\n* **Usage**: List projects paths\n\n```bash\n    glProjects.sh --list-path --id PROJECT_ID\n    glProjects.sh --list-path --group-path GROUP_PATH (could return more than one entry)\n    glProjects.sh --list-path --all\n    glProjects.sh --list-path --path PROJECT_PATH (could return more than one entry)\n```\n\n* **Usage**: List projects ids\n\n```bash\n    glProjects.sh --list-id --id PROJECT_ID\n    glProjects.sh --list-id --group-path GROUP_PATH (could return more than one entry)\n    glProjects.sh --list-id --all\n    glProjects.sh --list-id --path PROJECT_PATH\n```\n\n* **Usage**: Create project\n\n```bash\n    glProjects.sh --create --group-id GROUP_ID --path PROJECT_PATH \\\n      [--project-name PROJECT_NAME] \\\n      [--default-branch DEFAULT_BRANCH] \\\n      [--project-description PROJECT_DESCRIPTION] \\\n      [--container-registry-enabled true|false] \\\n      [--issues-enabled true|false] \\\n      [--jobs-enabled true|false] \\\n      [--lfs-enabled true|false] \\\n      [--merge-requests-enabled true|false] \\\n      [--only-allow-merge-if-all-discussions-are-resolved true|false] \\\n      [--only-allow-merge-if-pipeline-succeed true|false] \\\n      [--printing-merge-request-link-enabled true|false] \\\n      [--public-jobs true|false] \\\n      [--request-access-enabled true|false] \\\n      [--snippets-enabled true|false] \\\n      [--visibility private|internal|public] \\\n      [--wiki-enabled true|false]\n```\n\n* **Usage**: Edit project\n\n```bash\n    glProjects.sh --edit --id PROJECT_ID --project-name PROJECT_NAME \\\n      [--path PROJECT_PATH] \\\n      [--default-branch DEFAULT_BRANCH] \\\n      [--project-description PROJECT_DESCRIPTION] \\\n      [--issues-enabled true|false] \\\n      [--merge-requests-enabled true|false] \\\n      [--jobs-enabled true|false] \\\n      [--wiki-enabled true|false] \\\n      [--snippets-enabled true|false] \\\n      [--container-registry-enabled true|false] \\\n      [--visibility private|internal|public] \\\n      [--public-jobs true|false] \\\n      [--only-allow-merge-if-pipeline-succeed true|false] \\\n      [--only-allow-merge-if-all-discussions-are-resolved true|false] \\\n      [--lfs-enabled true|false] \\\n      [--request-access-enabled true|false]\n```\n\n* **Usage**: Delete a project\n\n```bash\n    glProjects.sh --delete --group-path GROUP_PATH --path PROJECT_PATH\n    glProjects.sh --delete --id PROJECT_ID\n```\n\n* **Sample**: Retrieve main configuration on all projects:\n\n```bash\nglProjects.sh --config --all\n```\n\n* **Sample**: Retrieve only path with name space:\n\n```bash\nglProjects.sh --config --all | jq -r ' .[] | .path_with_namespace'\n```\n\n* **Sample**: List of all projects id of a group\n\n```bash\nglProjects.sh --list-id --group-path GROUP_PATH\n```\n\n* **Sample**: To delete a project\n\n```bash\nglProjects.sh --delete --id PROJECT_ID\n```\n\n### About branches\n\n* List remote branch\n\nSyntax:\n\u003e listBranches.sh PROJECT_ID\n\n* To have all information about existing branches:\n\n```bash\nlistBranches.sh 82\n```\n\n* To have just branches name list of project with id=10:\n\n```bash\nlistBranches.sh 10 | jq -r ' .[] | .name'\n```\n\n(glBranches.sh command is still in alpha version)\n\n\nAudit and backups\n-----------------\n\n### Backups repositories\n\n`glCloneAllProjects` allow you to backup all repositories (GitLab projects only)\nusing **gitlab-bash-api**.\n\nIt is not a backup for everything, backup of users, groups, merge-requests, snippets,\njobs, ... are not covered by `glCloneAllProjects`. But it keep full history of\nyour projects, this a good practice to keep a such copy before a GitLab migration.\n\n* To clone **all projects** you have access\n\nSyntax:\n\u003e glCloneAllProjects.sh --http|--ssh [--bare] --destination OUTPUT_FOLDER\n\n* Complete example cloning throw ssh\n\n```bash\nmkdir -p tests-result\n\nglCloneAllProjects.sh --ssh --bare --destination \"tests-result/$(date +'%Y-%m-%d.%H-%M').clones\"\n```\n\nIf you need a custom key to handle this, create the key using\n\n```bash\nssh-keygen -t rsa -C \"clone-process\" -b 4096 -f ~/.ssh/gitlab_root_id_rsa\n```\n\nAdd this key on GitLab `root` account. `root` should be at least **developper** of\nall repositories but for other action you probably need that this account is **owner**\nof all repositories.\n\nThen you can run `glCloneAllProjects` using\n\n```bash\nGIT_SSH_COMMAND=\"ssh -i ${HOME}/.ssh/gitlab_root_id_rsa\" ./glCloneAllProjects.sh --ssh --bare --destination tests-result/$(date +'%Y-%m-%d.%H-%M').clones\n```\n\n\n### Audit groups and repositories\n\n```bash\n./glAudit.sh --directory tests-result/$(date +'%Y-%m-%d.%H-%M').audit\n```\n\nThis will generate a folder `YYYY-MM-DD.HH-MM.audit` with these sub-folders\n* `groups_by_id` : for all groups configuration (file `1.json` contain configuration of group id=1)\n* `groups_by_path` : contain links (links name are based on group path)\n* `projects_by_id` :for all repositories configuration (file `1.json` contain configuration of project id=1)\n* `projects_by_path` : contain links (links name are based on project path name)\n* `projects_by_path_with_namespace` : contain folder (based on group path) then link based on project path.\n\n\nSamples\n-------\n\nRetrieve id of all projects into a group.\n\n```bash\n./glProjects.sh --config --group-path puppet | jq '[.[] | {\nid: .id,\npath_with_namespace: .path_with_namespace\n}]'\n```\n\nRetrieve id of all projects into a group but format output\n\n```bash\n./glProjects.sh --config --group-path puppet |\n  jq -r '.[] | (.id|tostring) + \":\" + (.path_with_namespace)'\n```\n\nRetrieve id of all projects do something with this id\n\n```bash\n./glProjects.sh --config --group-path puppet |\n  jq -r '.[] | (.id|tostring) + \":\" + (.path_with_namespace)' |\n  while read line; do\n    echo \"Handle ${line}\"\n    PROJECT_ID=$(echo \"${line}\" | cut -d ':' -f 1)\n\n    echo \"do something with ${PROJECT_ID}\"\n\n  done\n```\n\nFull sample\n\n```bash\nfunction enable_key_for_group {\n  local group_name=$1\n  local deploy_key_id=$2\n\n  \"${GITLAB_BASH_API_PATH}/glProjects.sh\" --config --group-path \"${group_name}\" \\\n  | jq -r '.[] | (.id|tostring) + \":\" + (.path_with_namespace)' \\\n  | while read line; do\n      echo \"Handle ${line}\"\n      local project_id=$(echo \"${line}\" | cut -d ':' -f 1)\n\n      \"${GITLAB_BASH_API_PATH}/glDeployKeys.sh\" --enable --project-id \"${project_id}\" --key-id \"${deploy_key_id}\" || exit 1\n  done\n}\n\n # let say you have a deploy code id define in\n # You can use 'glDeployKeys.sh' to have this\n DEPLOY_KEY_ID=56\n GROUP_NAME=puppet\n\n # Then you want to enable this key on all project of a group\n # Basically it will use\n #   glDeployKeys.sh --enable --project-id PROJECT_ID --key-id DEPLOY_KEY_ID\n\n enable_key_for_group \"${GROUP_NAME}\" \"${DEPLOY_KEY_ID}\"\n```\n\n\nAbout GitLab and gitlab-bash-api\n--------------------------------\n\nIf you really need this API you probably need to consider moving to another\ngit server.\n\n\u003e GitLab is the best SVN server ever...\n\u003e but for git needs consider to move to something else.\n\n* [gitea](https://github.com/go-gitea/gitea) is complete, it is free and a true OpenSource solution.\n* [bitbucket](https://www.atlassian.com/software/bitbucket/server) from Atlassian is proprietary software but probably the most mature solution.\n\n\nRelated documentations\n----------------------\n\n* How to [get your GitLab API key](how-to-get-your-gitlab-api-key.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FcClaude%2Fgitlab-bash-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FcClaude%2Fgitlab-bash-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FcClaude%2Fgitlab-bash-api/lists"}