├── .gitignore ├── LICENSE ├── README.md ├── api ├── gitlab-bash-api-branch.sh ├── gitlab-bash-api-group.sh ├── gitlab-bash-api-project.sh └── gitlab-bash-api.sh ├── complete ├── _glGroups ├── _glProjects ├── _gl_common └── complete-init.sh ├── config ├── default-api-version ├── default-audit-config.sh ├── default-group-config.sh ├── default-project-config.sh └── default-user-config.sh ├── custom-config-sample ├── customize-curl.sh ├── my-api-version.sh ├── my-platform-configuration.sh └── my-secrets-configuration.sh ├── glAudit.sh ├── glBranches.sh ├── glCloneAllProjects.sh ├── glCreateUser.sh ├── glDeployKeys.sh ├── glGet.sh ├── glGroups.sh ├── glProjects.sh ├── glPut.sh ├── how-to-get-your-gitlab-api-key.md ├── listBranches.sh └── listUsers.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.backup 2 | *.log 3 | *.py 4 | *.sh! 5 | /*.json 6 | /.project 7 | /.settings/ 8 | /my-config 9 | /test-* 10 | /test/ 11 | /tests-result 12 | 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **Table of Contents** 2 | 3 | * [GitLab bash API](#gitlab-bash-api) 4 | * [Installation](#installation) 5 | * [Configuration](#configuration) 6 | * [Usage](#usage) 7 | * [Generic GET](#generic-get) 8 | * [Generic PUT](#generic-put) 9 | * [About users](#about-users) 10 | * [About groups](#about-groups) 11 | * [About projects (repositories)](#about-projects-repositories) 12 | * [About branches](#about-branches) 13 | * [Audit and backups](#audit-and-backups) 14 | * [Backups repositories](#backups-repositories) 15 | * [Audit groups and repositories](#audit-groups-and-repositories) 16 | * [Samples](#samples) 17 | * [About GitLab and gitlab\-bash\-api](#about-gitlab-and-gitlab-bash-api) 18 | * [Related documentations](#related-documentations) 19 | 20 | Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc.go) 21 | 22 | GitLab bash API 23 | =============== 24 | 25 | Access [GitLab CE API](https://docs.gitlab.com/ce/api/) or [GitLab EE API](https://docs.gitlab.com/ee/api/) from bash. 26 | 27 | Last version is available on GitHub: https://github.com/cClaude/gitlab-bash-api 28 | 29 | Current version is based on [GitLab V4 API](https://docs.gitlab.com/ce/api/v3_to_v4.html) but some features work on V3. 30 | V3 is no more supported except by glGet and glPut commands. 31 | 32 | 33 | Installation 34 | ------------ 35 | 36 | This tool require `bash`, `curl`, `jq` and `git`. 37 | 38 | ```bash 39 | sudo apt update 40 | sudo apt upgrade 41 | sudo apt install jq git 42 | 43 | git clone https://github.com/cClaude/gitlab-bash-api.git 44 | ``` 45 | 46 | 47 | Configuration 48 | ------------- 49 | 50 | You can create a `my-config` folder (ignored by git) to configure/customize this application or just copy content of `custom-config-sample/`. 51 | The `my-config` folder is taken in account by default by the API 52 | 53 | > You can also use any custom folder for configuration, by setting `GITLAB_BASH_API_CONFIG` 54 | > variable with the full path of your custom folder. 55 | 56 | In you configuration files: 57 | 58 | * You can create any custom file to declare variables (bash format), all theses files will be sourced. 59 | * You can override default values define in `config/` folder, 60 | * You need **at least** define values for `GITLAB_PRIVATE_TOKEN` and `GITLAB_URL_PREFIX`. 61 | 62 | ```bash 63 | GITLAB_PRIVATE_TOKEN=__YOUR_GITLAB_TOKEN_HERE__ 64 | GITLAB_URL_PREFIX=__YOUR_GITLAB_USER_HERE__ 65 | ``` 66 | 67 | Configuration algorithms : 68 | 69 | 1. source files in `${GITLAB_BASH_API_PATH}/config` 70 | 2. source files in `${GITLAB_BASH_API_PATH}/my-config` (if folder exists) 71 | 3. source files in `${GITLAB_BASH_API_CONFIG}` (if variable is define and if folder exists) 72 | 73 | **Facultative configuration:** 74 | 75 | You can also configure in you ~/.bashrc file 76 | 77 | ```bash 78 | export GITLAB_BASH_API_PATH='__YOUR_PATH_TO__/gitlab-bash-api' 79 | export GITLAB_BASH_API_CONFIG="__YOUR_PATH_TO__/your-custom-config-folder" 80 | 81 | PATH=$PATH:${GITLAB_BASH_API_PATH}/ 82 | ``` 83 | 84 | **Hacking** 85 | 86 | If for any reason you need to customize how curl access to GitLab server you can add some 87 | custom configuration in `${GITLAB_BASH_API_PATH}/my-config` or in `${GITLAB_BASH_API_CONFIG}` 88 | folders. 89 | 90 | A sample is available in `custom-config-sample/customize-curl.sh`. 91 | 92 | 93 | Usage 94 | ----- 95 | 96 | You can call comment using the full path 97 | 98 | ```bash 99 | ${GITLAB_BASH_API_PATH}/listUsers.sh --all 100 | ``` 101 | 102 | or simply (if **${GITLAB_BASH_API_PATH}** is in your path): 103 | 104 | ```bash 105 | listUsers.sh --all 106 | ``` 107 | 108 | ### Generic GET 109 | 110 | Syntax: 111 | > glGet.sh --uri GL_URI [--params 'PARAM1=VALUE1&PARAM2=VALUE2] 112 | 113 | ```bash 114 | glGet.sh --uri /projects | jq . 115 | ``` 116 | 117 | ### Generic PUT 118 | 119 | Syntax: 120 | > glPut.sh --uri GL_URI [--params 'PARAM1=VALUE1&PARAM2=VALUE2] 121 | 122 | ```bash 123 | TODO NEED SAMPLE 124 | ``` 125 | 126 | ### About users 127 | 128 | * How to create a new user ? 129 | 130 | Syntax: 131 | > glCreateUser.sh USER_NAME 'USER_FULLNAME' 'USER_EMAIL' 132 | 133 | ```bash 134 | glCreateUser.sh testuser "test user" test-user@example.org 135 | ``` 136 | 137 | * How to display all users ? 138 | 139 | ```bash 140 | listUsers.sh --all 141 | ``` 142 | 143 | * How to display a specific user ? 144 | 145 | ```bash 146 | listUsers.sh testuser 147 | ``` 148 | 149 | 150 | ### About groups 151 | 152 | How to manage groups using **glGroups** command ? 153 | 154 | * **Usage**: Get groups configuration 155 | 156 | ```bash 157 | glGroups.sh --config --path GROUP_PATH 158 | glGroups.sh --config --id GROUP_ID 159 | glGroups.sh --config --all 160 | ``` 161 | 162 | * **Usage**: List groups paths 163 | 164 | ```bash 165 | glGroups.sh --list-path --path GROUP_PATH 166 | glGroups.sh --list-path --id GROUP_ID 167 | glGroups.sh --list-path --all 168 | ``` 169 | 170 | * **Usage**: List groups ids 171 | 172 | ```bash 173 | glGroups.sh --list-id --path GROUP_PATH 174 | glGroups.sh --list-id --id GROUP_ID 175 | glGroups.sh --list-id --all 176 | ``` 177 | 178 | * **Usage**: Create group 179 | 180 | ```bash 181 | glGroups.sh --create --path GROUP_PATH 182 | [--name GROUP_NAME] \ 183 | [--description GROUP_DESCRIPTION] \ 184 | [--lfs_enabled true|false] \ 185 | [--membership_lock true|false] 186 | [--request_access_enabled true|false] \ 187 | [--share_with_group_lock true|false]] 188 | [--visibility private|internal|public] \ 189 | ``` 190 | 191 | * **Usage**: Edit group configuration 192 | 193 | ```bash 194 | glGroups.sh --edit --id GROUP_ID --name GROUP_NAME --path GROUP_PATH \ 195 | [--description GROUP_DESCRIPTION] \ 196 | [--visibility private|internal|public] \ 197 | [--lfs_enabled true|false] \ 198 | [--request_access_enabled true|false] 199 | ``` 200 | 201 | * **Usage**: Delete a group 202 | 203 | ```bash 204 | glGroups.sh --delete --id GROUP_ID 205 | ``` 206 | 207 | * **Sample**: Retrieve main configuration on all groups: 208 | 209 | ```bash 210 | glGroups.sh --config --all 211 | ``` 212 | 213 | * **Sample**: create a group 214 | 215 | ```bash 216 | glGroups.sh --create --path my_test_group 217 | ``` 218 | 219 | 220 | ### About projects (repositories) 221 | 222 | How to manage groups using `glProjects` command ? 223 | 224 | * **Usage**: Get projects configuration 225 | 226 | ```bash 227 | glProjects.sh --config [--compact] --id PROJECT_ID 228 | glProjects.sh --config [--compact] --group-path GROUP_PATH 229 | glProjects.sh --config [--compact] --all 230 | glProjects.sh --config [--compact] --path PROJECT_PATH 231 | ``` 232 | 233 | * **Usage**: List projects paths 234 | 235 | ```bash 236 | glProjects.sh --list-path --id PROJECT_ID 237 | glProjects.sh --list-path --group-path GROUP_PATH (could return more than one entry) 238 | glProjects.sh --list-path --all 239 | glProjects.sh --list-path --path PROJECT_PATH (could return more than one entry) 240 | ``` 241 | 242 | * **Usage**: List projects ids 243 | 244 | ```bash 245 | glProjects.sh --list-id --id PROJECT_ID 246 | glProjects.sh --list-id --group-path GROUP_PATH (could return more than one entry) 247 | glProjects.sh --list-id --all 248 | glProjects.sh --list-id --path PROJECT_PATH 249 | ``` 250 | 251 | * **Usage**: Create project 252 | 253 | ```bash 254 | glProjects.sh --create --group-id GROUP_ID --path PROJECT_PATH \ 255 | [--project-name PROJECT_NAME] \ 256 | [--default-branch DEFAULT_BRANCH] \ 257 | [--project-description PROJECT_DESCRIPTION] \ 258 | [--container-registry-enabled true|false] \ 259 | [--issues-enabled true|false] \ 260 | [--jobs-enabled true|false] \ 261 | [--lfs-enabled true|false] \ 262 | [--merge-requests-enabled true|false] \ 263 | [--only-allow-merge-if-all-discussions-are-resolved true|false] \ 264 | [--only-allow-merge-if-pipeline-succeed true|false] \ 265 | [--printing-merge-request-link-enabled true|false] \ 266 | [--public-jobs true|false] \ 267 | [--request-access-enabled true|false] \ 268 | [--snippets-enabled true|false] \ 269 | [--visibility private|internal|public] \ 270 | [--wiki-enabled true|false] 271 | ``` 272 | 273 | * **Usage**: Edit project 274 | 275 | ```bash 276 | glProjects.sh --edit --id PROJECT_ID --project-name PROJECT_NAME \ 277 | [--path PROJECT_PATH] \ 278 | [--default-branch DEFAULT_BRANCH] \ 279 | [--project-description PROJECT_DESCRIPTION] \ 280 | [--issues-enabled true|false] \ 281 | [--merge-requests-enabled true|false] \ 282 | [--jobs-enabled true|false] \ 283 | [--wiki-enabled true|false] \ 284 | [--snippets-enabled true|false] \ 285 | [--container-registry-enabled true|false] \ 286 | [--visibility private|internal|public] \ 287 | [--public-jobs true|false] \ 288 | [--only-allow-merge-if-pipeline-succeed true|false] \ 289 | [--only-allow-merge-if-all-discussions-are-resolved true|false] \ 290 | [--lfs-enabled true|false] \ 291 | [--request-access-enabled true|false] 292 | ``` 293 | 294 | * **Usage**: Delete a project 295 | 296 | ```bash 297 | glProjects.sh --delete --group-path GROUP_PATH --path PROJECT_PATH 298 | glProjects.sh --delete --id PROJECT_ID 299 | ``` 300 | 301 | * **Sample**: Retrieve main configuration on all projects: 302 | 303 | ```bash 304 | glProjects.sh --config --all 305 | ``` 306 | 307 | * **Sample**: Retrieve only path with name space: 308 | 309 | ```bash 310 | glProjects.sh --config --all | jq -r ' .[] | .path_with_namespace' 311 | ``` 312 | 313 | * **Sample**: List of all projects id of a group 314 | 315 | ```bash 316 | glProjects.sh --list-id --group-path GROUP_PATH 317 | ``` 318 | 319 | * **Sample**: To delete a project 320 | 321 | ```bash 322 | glProjects.sh --delete --id PROJECT_ID 323 | ``` 324 | 325 | ### About branches 326 | 327 | * List remote branch 328 | 329 | Syntax: 330 | > listBranches.sh PROJECT_ID 331 | 332 | * To have all information about existing branches: 333 | 334 | ```bash 335 | listBranches.sh 82 336 | ``` 337 | 338 | * To have just branches name list of project with id=10: 339 | 340 | ```bash 341 | listBranches.sh 10 | jq -r ' .[] | .name' 342 | ``` 343 | 344 | (glBranches.sh command is still in alpha version) 345 | 346 | 347 | Audit and backups 348 | ----------------- 349 | 350 | ### Backups repositories 351 | 352 | `glCloneAllProjects` allow you to backup all repositories (GitLab projects only) 353 | using **gitlab-bash-api**. 354 | 355 | It is not a backup for everything, backup of users, groups, merge-requests, snippets, 356 | jobs, ... are not covered by `glCloneAllProjects`. But it keep full history of 357 | your projects, this a good practice to keep a such copy before a GitLab migration. 358 | 359 | * To clone **all projects** you have access 360 | 361 | Syntax: 362 | > glCloneAllProjects.sh --http|--ssh [--bare] --destination OUTPUT_FOLDER 363 | 364 | * Complete example cloning throw ssh 365 | 366 | ```bash 367 | mkdir -p tests-result 368 | 369 | glCloneAllProjects.sh --ssh --bare --destination "tests-result/$(date +'%Y-%m-%d.%H-%M').clones" 370 | ``` 371 | 372 | If you need a custom key to handle this, create the key using 373 | 374 | ```bash 375 | ssh-keygen -t rsa -C "clone-process" -b 4096 -f ~/.ssh/gitlab_root_id_rsa 376 | ``` 377 | 378 | Add this key on GitLab `root` account. `root` should be at least **developper** of 379 | all repositories but for other action you probably need that this account is **owner** 380 | of all repositories. 381 | 382 | Then you can run `glCloneAllProjects` using 383 | 384 | ```bash 385 | GIT_SSH_COMMAND="ssh -i ${HOME}/.ssh/gitlab_root_id_rsa" ./glCloneAllProjects.sh --ssh --bare --destination tests-result/$(date +'%Y-%m-%d.%H-%M').clones 386 | ``` 387 | 388 | 389 | ### Audit groups and repositories 390 | 391 | ```bash 392 | ./glAudit.sh --directory tests-result/$(date +'%Y-%m-%d.%H-%M').audit 393 | ``` 394 | 395 | This will generate a folder `YYYY-MM-DD.HH-MM.audit` with these sub-folders 396 | * `groups_by_id` : for all groups configuration (file `1.json` contain configuration of group id=1) 397 | * `groups_by_path` : contain links (links name are based on group path) 398 | * `projects_by_id` :for all repositories configuration (file `1.json` contain configuration of project id=1) 399 | * `projects_by_path` : contain links (links name are based on project path name) 400 | * `projects_by_path_with_namespace` : contain folder (based on group path) then link based on project path. 401 | 402 | 403 | Samples 404 | ------- 405 | 406 | Retrieve id of all projects into a group. 407 | 408 | ```bash 409 | ./glProjects.sh --config --group-path puppet | jq '[.[] | { 410 | id: .id, 411 | path_with_namespace: .path_with_namespace 412 | }]' 413 | ``` 414 | 415 | Retrieve id of all projects into a group but format output 416 | 417 | ```bash 418 | ./glProjects.sh --config --group-path puppet | 419 | jq -r '.[] | (.id|tostring) + ":" + (.path_with_namespace)' 420 | ``` 421 | 422 | Retrieve id of all projects do something with this id 423 | 424 | ```bash 425 | ./glProjects.sh --config --group-path puppet | 426 | jq -r '.[] | (.id|tostring) + ":" + (.path_with_namespace)' | 427 | while read line; do 428 | echo "Handle ${line}" 429 | PROJECT_ID=$(echo "${line}" | cut -d ':' -f 1) 430 | 431 | echo "do something with ${PROJECT_ID}" 432 | 433 | done 434 | ``` 435 | 436 | Full sample 437 | 438 | ```bash 439 | function enable_key_for_group { 440 | local group_name=$1 441 | local deploy_key_id=$2 442 | 443 | "${GITLAB_BASH_API_PATH}/glProjects.sh" --config --group-path "${group_name}" \ 444 | | jq -r '.[] | (.id|tostring) + ":" + (.path_with_namespace)' \ 445 | | while read line; do 446 | echo "Handle ${line}" 447 | local project_id=$(echo "${line}" | cut -d ':' -f 1) 448 | 449 | "${GITLAB_BASH_API_PATH}/glDeployKeys.sh" --enable --project-id "${project_id}" --key-id "${deploy_key_id}" || exit 1 450 | done 451 | } 452 | 453 | # let say you have a deploy code id define in 454 | # You can use 'glDeployKeys.sh' to have this 455 | DEPLOY_KEY_ID=56 456 | GROUP_NAME=puppet 457 | 458 | # Then you want to enable this key on all project of a group 459 | # Basically it will use 460 | # glDeployKeys.sh --enable --project-id PROJECT_ID --key-id DEPLOY_KEY_ID 461 | 462 | enable_key_for_group "${GROUP_NAME}" "${DEPLOY_KEY_ID}" 463 | ``` 464 | 465 | 466 | About GitLab and gitlab-bash-api 467 | -------------------------------- 468 | 469 | If you really need this API you probably need to consider moving to another 470 | git server. 471 | 472 | > GitLab is the best SVN server ever... 473 | > but for git needs consider to move to something else. 474 | 475 | * [gitea](https://github.com/go-gitea/gitea) is complete, it is free and a true OpenSource solution. 476 | * [bitbucket](https://www.atlassian.com/software/bitbucket/server) from Atlassian is proprietary software but probably the most mature solution. 477 | 478 | 479 | Related documentations 480 | ---------------------- 481 | 482 | * How to [get your GitLab API key](how-to-get-your-gitlab-api-key.md) 483 | -------------------------------------------------------------------------------- /api/gitlab-bash-api-branch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # API: list_branches 4 | 5 | function list_branches { 6 | local project_id=$1 7 | local branch_name=$2 8 | 9 | local answer 10 | local error_message 11 | 12 | answer=$(gitlab_get "/projects/${project_id}/repository/branches/${branch_name}") 13 | error_message=$(getErrorMessage "${answer}") 14 | 15 | if [ ! -z "${error_message}" ]; then 16 | echo "${answer}" # This is an error (not format) 17 | exit 0 18 | fi 19 | 20 | echo "${answer}" 21 | } 22 | 23 | # API: create_project 24 | 25 | function create_project { 26 | local params= 27 | local first=true 28 | 29 | # optional parameters 30 | while [[ $# -gt 0 ]]; do 31 | if [ ! $# -gt 1 ]; then 32 | echo "*** create_project error: odd number of remind parameters. $#" >&2 33 | exit 1 34 | fi 35 | 36 | local param_name="$1" 37 | shift 38 | local param_value="$1" 39 | shift 40 | 41 | if [ "${first}" = true ]; then 42 | first=false 43 | else 44 | params+='&' 45 | fi 46 | 47 | case "${param_name}" in 48 | printing_merge_request_link_enabled|container_registry_enabled) 49 | ensure_boolean "${param_value}" "${param_name}" 50 | 51 | params+="${param_name}=${param_value}" 52 | ;; 53 | *) 54 | params+="${param_name}=$(urlencode "${param_value}")" 55 | ;; 56 | esac 57 | 58 | done 59 | 60 | # DEBUG echo "POST params create_project: ${params}" >&2 61 | gitlab_post 'projects' "${params}" 62 | } 63 | 64 | # API: create_project_params 65 | 66 | function create_project_params { 67 | echo ' 68 | path 69 | name 70 | namespace_id 71 | description 72 | container_registry_enabled 73 | issues_enabled 74 | jobs_enabled 75 | lfs_enabled 76 | merge_requests_enabled 77 | only_allow_merge_if_all_discussions_are_resolved 78 | only_allow_merge_if_pipeline_succeeds 79 | printing_merge_request_link_enabled 80 | public_jobs 81 | request_access_enabled 82 | snippets_enabled 83 | visibility 84 | wiki_enabled 85 | ' 86 | } 87 | 88 | # API: edit_project 89 | 90 | function edit_project { 91 | local project_id= 92 | local first=true 93 | 94 | # optional parameters 95 | while [[ $# -gt 0 ]]; do 96 | if [ ! $# -gt 1 ]; then 97 | echo "*** edit_project error: odd number of remind parameters. $# ($1) : Current parameters ${params}" >&2 98 | exit 1 99 | fi 100 | 101 | local param_name="$1" 102 | shift 103 | local param_value="$1" 104 | shift 105 | 106 | if [ "${param_name}" = 'id' ]; then 107 | # handle id 108 | project_id=${param_value} 109 | else 110 | if [ "${first}" = true ]; then 111 | first=false 112 | else 113 | params+='&' 114 | fi 115 | 116 | params+="${param_name}=$(urlencode "${param_value}")" 117 | fi 118 | 119 | done 120 | 121 | if [ -z "${project_id}" ]; then 122 | echo '* edit_project project id is missing.' >&2 123 | exit 1 124 | fi 125 | 126 | # DEBUG echo "POST params edit_project: ${params}" >&2 127 | gitlab_put "projects/${project_id}" "${params}" 128 | } 129 | 130 | # API: edit_project_parameters 131 | 132 | function edit_project_parameters { 133 | echo ' 134 | id 135 | name 136 | path 137 | default_branch 138 | description 139 | issues_enabled 140 | merge_requests_enabled 141 | jobs_enabled 142 | wiki_enabled 143 | snippets_enabled 144 | resolve_outdated_diff_discussions 145 | container_registry_enabled 146 | shared_runners_enabled 147 | visibility 148 | import_url 149 | public_jobs 150 | only_allow_merge_if_pipeline_succeeds 151 | only_allow_merge_if_all_discussions_are_resolved 152 | lfs_enabled 153 | request_access_enabled 154 | tag_list 155 | avatar 156 | ci_config_path 157 | ' 158 | } 159 | 160 | # API: edit_project_all_values 161 | 162 | function edit_project_all_values { 163 | local p_id=$1 # The ID or URL-encoded path of the project 164 | local p_name=$2 # The name of the project 165 | local p_path=$3 # Custom repository name for the project. 166 | local p_default_branch=$4 # master by default 167 | local p_description=$5 # Short project description 168 | local p_issues_enabled=$6 # Enable issues for this project 169 | local p_merge_requests_enabled=$7 # Enable merge requests for this project 170 | local p_jobs_enabled=$8 # Enable jobs for this project 171 | local p_wiki_enabled=$9 # Enable wiki for this project 172 | local p_snippets_enabled=${10} # Enable snippets for this project 173 | local p_resolve_outdated_diff_discussions=${11} # Automatically resolve merge request diffs discussions on lines changed with a push 174 | local p_container_registry_enabled=${12} # Enable container registry for this project 175 | local p_shared_runners_enabled=${13} # Enable shared runners for this project 176 | local p_visibility=${14} # See project visibility level 177 | local p_import_url=${15} # URL to import repository from 178 | local p_public_jobs=${16} # If true, jobs can be viewed by non-project-members 179 | local p_only_allow_merge_if_pipeline_succeeds=${17} # Set whether merge requests can only be merged with successful jobs 180 | local p_only_allow_merge_if_all_discussions_are_resolved=${18} # Set whether merge requests can only be merged when all the discussions are resolved 181 | local p_lfs_enabled=${19} # Enable LFS 182 | local p_request_access_enabled=${20} # Allow users to request member access 183 | local p_tag_list=${21} # The list of tags for a project; put array of tags, that should be finally assigned to a project 184 | local p_avatar=${22} # Image file for avatar of the project 185 | local p_ci_config_path=${23} # The path to CI config file 186 | 187 | edit_project \ 188 | 'id' "${p_id}" \ 189 | 'name' "${p_name}" \ 190 | 'path' "${p_path}" \ 191 | 'default_branch' "${p_default_branch}" \ 192 | 'description' "${p_description}" \ 193 | 'issues_enabled' "${p_issues_enabled}" \ 194 | 'merge_requests_enabled' "${p_merge_requests_enabled}" \ 195 | 'jobs_enabled' "${p_jobs_enabled}" \ 196 | 'wiki_enabled' "${p_wiki_enabled}" \ 197 | 'snippets_enabled' "${p_snippets_enabled}" \ 198 | 'resolve_outdated_diff_discussions' "${p_resolve_outdated_diff_discussions}" \ 199 | 'container_registry_enabled' "${p_container_registry_enabled}" \ 200 | 'shared_runners_enabled' "${p_shared_runners_enabled}" \ 201 | 'visibility' "${p_visibility}" \ 202 | 'import_url' "${p_import_url}" \ 203 | 'public_jobs' "${p_public_jobs}" \ 204 | 'only_allow_merge_if_pipeline_succeeds' "${p_only_allow_merge_if_pipeline_succeeds}" \ 205 | 'only_allow_merge_if_all_discussions_are_resolved' "${p_only_allow_merge_if_all_discussions_are_resolved}" \ 206 | 'lfs_enabled' "${p_lfs_enabled}" \ 207 | 'request_access_enabled' "${p_request_access_enabled}" \ 208 | 'tag_list' "${p_tag_list}" \ 209 | 'avatar' "${p_avatar}" \ 210 | 'ci_config_path' "${p_ci_config_path}" 211 | } 212 | 213 | # API: delete_project 214 | 215 | function delete_project { 216 | local project_id=$1 217 | 218 | echo "# delete project: project_id=[${project_id}]" >&2 219 | 220 | gitlab_delete "projects/${project_id}" 221 | } 222 | 223 | -------------------------------------------------------------------------------- /api/gitlab-bash-api-group.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Monstly based on https://docs.gitlab.com/ce/api/groups.html 4 | 5 | # API: list_groups 6 | 7 | function list_groups { 8 | local group_id=$1 9 | local params=$2 10 | 11 | gitlab_get "groups/$(url_encode "${group_id}")" "${params}" 12 | } 13 | 14 | # API: search_group_ (ALPHA) 15 | 16 | function search_group_ { 17 | local search_string=$1 18 | 19 | gitlab_get "groups/search=$(url_encode "${search_string}")" '' 20 | } 21 | 22 | # API: get_group_id_from_group_path 23 | 24 | function get_group_id_from_group_path { 25 | local group_path="$1" 26 | local answer 27 | local group_id 28 | 29 | answer=$(gitlab_get "groups/$(url_encode "${group_path}")") || return 1 30 | 31 | group_id=$(echo "${answer}" | jq .id) 32 | 33 | if [ -z "${group_id}" ] ; then 34 | echo "*** GROUP_PATH '${group_path}' doest not exist - '${answer}'" >&2 35 | exit 200 36 | fi 37 | 38 | if [ "${group_id}" = "null" ] ; then 39 | echo "*** GROUP_PATH '${group_path}' doest not exist - '${answer}'" >&2 40 | exit 201 41 | fi 42 | 43 | echo "${group_id}" 44 | } 45 | 46 | # API: show_group_config 47 | 48 | function show_group_config { 49 | local group_path_or_id_or_empty=$1 50 | local result 51 | 52 | result=$(list_groups "${group_path_or_id_or_empty}" '') 53 | 54 | if [ ! -z "${group_path_or_id_or_empty}" ]; then 55 | echo "${result}" 56 | exit 0 57 | fi 58 | 59 | # Handle --all 60 | local groups_ids 61 | 62 | groups_ids=$(echo "${result}" | jq '. [] | .id') 63 | 64 | local first=true 65 | 66 | echo -n '[' 67 | for id in ${groups_ids}; do 68 | if [ "${first}" = true ]; then 69 | first=false 70 | else 71 | echo -n ',' 72 | fi 73 | list_groups "${id}" '' 74 | done 75 | echo -n ']' 76 | } 77 | 78 | # API: create_group 79 | 80 | function create_group { 81 | local params= 82 | local first=true 83 | 84 | # optional parameters 85 | while [[ $# -gt 0 ]]; do 86 | if [ ! $# -gt 1 ]; then 87 | echo "*** create_group error: odd number of remind parameters. $#" >&2 88 | exit 1 89 | fi 90 | 91 | local param_name="$1" 92 | shift 93 | local param_value="$1" 94 | shift 95 | 96 | if [ "${first}" = true ]; then 97 | first=false 98 | else 99 | params+='&' 100 | fi 101 | 102 | params+="${param_name}=$(url_encode "${param_value}")" 103 | done 104 | 105 | # DEBUG echo "# create_group POST params: ${params}" >&2 106 | gitlab_post 'groups' "${params}" 107 | } 108 | 109 | # API: create_group_params 110 | 111 | function create_group_params { 112 | echo ' 113 | path 114 | name 115 | description 116 | lfs_enabled 117 | membership_lock 118 | request_access_enabled 119 | share_with_group_lock 120 | visibility 121 | ' 122 | } 123 | 124 | # API: edit_group 125 | 126 | function edit_group { 127 | local group_id=$1 128 | local group_name=$2 129 | local group_path=$3 130 | local group_description_define=$4 131 | local group_description=$5 132 | local group_visibility=$6 133 | local group_lfs_enabled=$7 134 | local group_request_access_enabled=$8 135 | 136 | if [ -z "${group_id}" ]; then 137 | echo "*** error: edit_group missing group_id" >&2 138 | exit 1 139 | fi 140 | if [ -z "${group_name}" ]; then 141 | echo "*** error: edit_group missing group_name" >&2 142 | exit 1 143 | fi 144 | if [ -z "${group_path}" ]; then 145 | echo "*** error: edit_group missing group_path" >&2 146 | exit 1 147 | fi 148 | ensure_boolean "${group_description_define}" 'group_description_define' 149 | 150 | local params 151 | 152 | params="name=$(url_encode "${group_name}")&path=${group_path}" 153 | 154 | if [ "${group_description_define}" = true ]; then 155 | params+="&description=$(url_encode "${group_description}")" 156 | 157 | if [ -z "${group_description}" ]; then 158 | echo "*** warning: edit_group group_description is empty" >&2 159 | fi 160 | fi 161 | if [ ! -z "${group_visibility}" ]; then 162 | params+="&visibility=${group_visibility}" 163 | fi 164 | if [ ! -z "${group_lfs_enabled}" ]; then 165 | params+="&lfs_enabled=${group_lfs_enabled}" 166 | fi 167 | if [ ! -z "${group_request_access_enabled}" ]; then 168 | params+="&request_access_enabled=${group_request_access_enabled}" 169 | fi 170 | 171 | # DEBUG echo "POST params edit_group: ${params}" >&2 172 | gitlab_put "groups/${group_id}" "${params}" 173 | } 174 | 175 | # API: delete_group 176 | 177 | function delete_group { 178 | local group_id=$1 179 | 180 | echo "# delete group: group_id='${group_id}'" >&2 181 | 182 | gitlab_delete "groups/${group_id}" 183 | } 184 | 185 | -------------------------------------------------------------------------------- /api/gitlab-bash-api-project.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function isJsonArray { 4 | local begin 5 | 6 | begin=$(echo "$1" | cut -b1 ) 7 | 8 | if [ "${begin}" = '[' ] ; then 9 | echo "true" 10 | else 11 | echo "false" 12 | fi 13 | } 14 | 15 | # API: list_projects_raw 16 | 17 | function list_projects_raw { 18 | local project_id=$1 19 | local params=$2 20 | local answer 21 | local error_message 22 | 23 | answer=$(gitlab_get "projects/${project_id}" "${params}") 24 | error_message=$(getErrorMessage "${answer}") 25 | 26 | if [ ! -z "${error_message}" ]; then 27 | echo "${answer}" # This is an error (not format) 28 | exit 0 29 | fi 30 | 31 | if [ ! -z "${project_id}" ]; then 32 | #DEBUG echo "isJsonArray:$(isJsonArray "${answer}") should be false ${project_id}" >&2 33 | echo "[${answer}]" # Always return an array (even when not found) 34 | else 35 | #DEBUG echo "isJsonArray:$(isJsonArray "${answer}") should be true" >&2 36 | echo "${answer}" 37 | fi 38 | } 39 | 40 | # API: list_projects_compact (DEPRECATED) 41 | 42 | function list_projects_compact { 43 | local project_id=$1 44 | local params=$2 45 | local answer 46 | local short_result 47 | 48 | answer=$(list_projects_raw "${project_id}" "${params}") || exit 103 49 | 50 | short_result=$(echo "${answer}" | jq '[.[] | { 51 | project_id: .id, 52 | project_name: .name, 53 | project_path: .path, 54 | group_name: .namespace.name, 55 | group_path: .namespace.path, 56 | path_with_namespace: .path_with_namespace, 57 | ssh_url_to_repo: .ssh_url_to_repo, 58 | http_url_to_repo: .http_url_to_repo, 59 | container_registry_enabled: .container_registry_enabled, 60 | issues_enabled: .issues_enabled, 61 | merge_requests_enabled: .merge_requests_enabled, 62 | wiki_enabled: .wiki_enabled, 63 | builds_enabled: .builds_enabled, 64 | snippets_enabled: .snippets_enabled, 65 | shared_runners_enabled: .shared_runners_enabled, 66 | lfs_enabled: .lfs_enabled, 67 | request_access_enabled: .request_access_enabled 68 | }]') # ' 69 | 70 | echo "${short_result}" 71 | } 72 | 73 | # API: show_project_config 74 | 75 | function show_project_config { 76 | local param_raw_display=$1 77 | local param_project_id=$2 78 | 79 | if [ ! $# -eq 2 ]; then 80 | echo "* show_project_config: Expecting 2 parameters found $# : '$*'" >&2 81 | exit 1 82 | fi 83 | 84 | ensure_boolean "${param_raw_display}" 'param_raw_display' || exit 1 85 | 86 | #DEBUG echo "### show_project_config '$1' - '$2'" >&2 87 | 88 | # Note: if "${param_project_id}" is define request time is smallest. 89 | if [ "${param_raw_display}" = "true" ] ; then 90 | list_projects_raw "${param_project_id}" 'statistics=true' || exit 1 91 | else 92 | list_projects_compact "${param_project_id}" '' || exit 1 93 | fi 94 | } 95 | 96 | # API: audit_project 97 | 98 | function audit_project { 99 | local param_project_id=$1 100 | 101 | if [ ! $# -eq 1 ]; then 102 | echo "* project_audit: Expecting 1 parameters found $# : '$*'" >&2 103 | exit 1 104 | fi 105 | 106 | list_projects_raw "${param_project_id}" 'statistics=true' || exit 1 107 | } 108 | 109 | # API: create_project 110 | 111 | function create_project { 112 | local params 113 | local first=true 114 | 115 | # optional parameters 116 | while [[ $# -gt 0 ]]; do 117 | if [ ! $# -gt 1 ]; then 118 | echo "*** create_project error: odd number of remind parameters. $#" >&2 119 | exit 1 120 | fi 121 | 122 | local param_name="$1" 123 | shift 124 | local param_value="$1" 125 | shift 126 | 127 | if [ "${first}" = true ]; then 128 | first=false 129 | else 130 | params+='&' 131 | fi 132 | 133 | case "${param_name}" in 134 | printing_merge_request_link_enabled|container_registry_enabled) 135 | ensure_boolean "${param_value}" "${param_name}" 136 | 137 | params+="${param_name}=${param_value}" 138 | ;; 139 | *) 140 | params+="${param_name}=$(url_encode "${param_value}")" 141 | ;; 142 | esac 143 | 144 | done 145 | 146 | # DEBUG echo "POST params create_project: ${params}" >&2 147 | gitlab_post 'projects' "${params}" 148 | } 149 | 150 | # API: create_project_params 151 | 152 | function create_project_params { 153 | echo ' 154 | path 155 | name 156 | namespace_id 157 | description 158 | container_registry_enabled 159 | issues_enabled 160 | jobs_enabled 161 | lfs_enabled 162 | merge_requests_enabled 163 | only_allow_merge_if_all_discussions_are_resolved 164 | only_allow_merge_if_pipeline_succeeds 165 | printing_merge_request_link_enabled 166 | public_jobs 167 | request_access_enabled 168 | snippets_enabled 169 | visibility 170 | wiki_enabled 171 | ' 172 | } 173 | 174 | # API: edit_project 175 | 176 | function edit_project { 177 | local project_id= 178 | local first=true 179 | 180 | # optional parameters 181 | while [[ $# -gt 0 ]]; do 182 | if [ ! $# -gt 1 ]; then 183 | echo "*** edit_project error: odd number of remind parameters. $# ($1) : Current parameters ${params}" >&2 184 | exit 1 185 | fi 186 | 187 | local param_name="$1" 188 | shift 189 | local param_value="$1" 190 | shift 191 | 192 | if [ "${param_name}" = 'id' ]; then 193 | # handle id 194 | project_id=${param_value} 195 | else 196 | if [ "${first}" = true ]; then 197 | first=false 198 | else 199 | params+='&' 200 | fi 201 | 202 | params+="${param_name}=$(url_encode "${param_value}")" 203 | fi 204 | 205 | done 206 | 207 | if [ -z "${project_id}" ]; then 208 | echo '* edit_project project id is missing.' >&2 209 | exit 1 210 | fi 211 | 212 | # DEBUG echo "POST params edit_project: ${params}" >&2 213 | gitlab_put "projects/${project_id}" "${params}" 214 | } 215 | 216 | # API: edit_project_parameters 217 | 218 | function edit_project_parameters { 219 | echo ' 220 | id 221 | name 222 | path 223 | default_branch 224 | description 225 | issues_enabled 226 | merge_requests_enabled 227 | jobs_enabled 228 | wiki_enabled 229 | snippets_enabled 230 | resolve_outdated_diff_discussions 231 | container_registry_enabled 232 | shared_runners_enabled 233 | visibility 234 | import_url 235 | public_jobs 236 | only_allow_merge_if_pipeline_succeeds 237 | only_allow_merge_if_all_discussions_are_resolved 238 | lfs_enabled 239 | request_access_enabled 240 | tag_list 241 | avatar 242 | ci_config_path 243 | ' 244 | } 245 | 246 | # API: edit_project_all_values 247 | 248 | function edit_project_all_values { 249 | local p_id=$1 # The ID or URL-encoded path of the project 250 | local p_name=$2 # The name of the project 251 | local p_path=$3 # Custom repository name for the project. 252 | local p_default_branch=$4 # master by default 253 | local p_description=$5 # Short project description 254 | local p_issues_enabled=$6 # Enable issues for this project 255 | local p_merge_requests_enabled=$7 # Enable merge requests for this project 256 | local p_jobs_enabled=$8 # Enable jobs for this project 257 | local p_wiki_enabled=$9 # Enable wiki for this project 258 | local p_snippets_enabled=${10} # Enable snippets for this project 259 | local p_resolve_outdated_diff_discussions=${11} # Automatically resolve merge request diffs discussions on lines changed with a push 260 | local p_container_registry_enabled=${12} # Enable container registry for this project 261 | local p_shared_runners_enabled=${13} # Enable shared runners for this project 262 | local p_visibility=${14} # See project visibility level 263 | local p_import_url=${15} # URL to import repository from 264 | local p_public_jobs=${16} # If true, jobs can be viewed by non-project-members 265 | local p_only_allow_merge_if_pipeline_succeeds=${17} # Set whether merge requests can only be merged with successful jobs 266 | local p_only_allow_merge_if_all_discussions_are_resolved=${18} # Set whether merge requests can only be merged when all the discussions are resolved 267 | local p_lfs_enabled=${19} # Enable LFS 268 | local p_request_access_enabled=${20} # Allow users to request member access 269 | local p_tag_list=${21} # The list of tags for a project; put array of tags, that should be finally assigned to a project 270 | local p_avatar=${22} # Image file for avatar of the project 271 | local p_ci_config_path=${23} # The path to CI config file 272 | 273 | edit_project \ 274 | 'id' "${p_id}" \ 275 | 'name' "${p_name}" \ 276 | 'path' "${p_path}" \ 277 | 'default_branch' "${p_default_branch}" \ 278 | 'description' "${p_description}" \ 279 | 'issues_enabled' "${p_issues_enabled}" \ 280 | 'merge_requests_enabled' "${p_merge_requests_enabled}" \ 281 | 'jobs_enabled' "${p_jobs_enabled}" \ 282 | 'wiki_enabled' "${p_wiki_enabled}" \ 283 | 'snippets_enabled' "${p_snippets_enabled}" \ 284 | 'resolve_outdated_diff_discussions' "${p_resolve_outdated_diff_discussions}" \ 285 | 'container_registry_enabled' "${p_container_registry_enabled}" \ 286 | 'shared_runners_enabled' "${p_shared_runners_enabled}" \ 287 | 'visibility' "${p_visibility}" \ 288 | 'import_url' "${p_import_url}" \ 289 | 'public_jobs' "${p_public_jobs}" \ 290 | 'only_allow_merge_if_pipeline_succeeds' "${p_only_allow_merge_if_pipeline_succeeds}" \ 291 | 'only_allow_merge_if_all_discussions_are_resolved' "${p_only_allow_merge_if_all_discussions_are_resolved}" \ 292 | 'lfs_enabled' "${p_lfs_enabled}" \ 293 | 'request_access_enabled' "${p_request_access_enabled}" \ 294 | 'tag_list' "${p_tag_list}" \ 295 | 'avatar' "${p_avatar}" \ 296 | 'ci_config_path' "${p_ci_config_path}" 297 | } 298 | 299 | # API: delete_project 300 | 301 | function delete_project { 302 | local project_id=$1 303 | 304 | echo "# delete project: project_id=[${project_id}]" >&2 305 | 306 | gitlab_delete "projects/${project_id}" 307 | } 308 | 309 | # API: get_all_projects_path_with_namespace 310 | 311 | function get_all_projects_path_with_namespace { 312 | local project_paths 313 | 314 | project_paths=$(list_projects_compact '' '' | jq -r '.[] | .path_with_namespace' ) || exit 401 315 | 316 | echo "${project_paths}" | sort 317 | } 318 | 319 | -------------------------------------------------------------------------------- /api/gitlab-bash-api.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # GitLab bash API 4 | # 5 | # Based on GitLab documentation: 6 | # https://docs.gitlab.com/ee/api/ 7 | # https://docs.gitlab.com/ce/api/ 8 | # https://gitlab.com/gitlab-org/gitlab-ce/tree/master/lib/api 9 | # https://docs.gitlab.com/ce/api/projects.html 10 | # 11 | # Last version is available on GitHub: https://github.com/cClaude/gitlab-bash-api 12 | # 13 | 14 | declare -r LF=$'\n' 15 | declare -r CR=$'\r' 16 | 17 | declare NEXT_PAGE= 18 | 19 | # 20 | # HTTP GET - Read one page 21 | # 22 | function gitlab_get_page { 23 | local api_url="$1" 24 | local api_params="$2" 25 | local page="$3" 26 | 27 | local curl_url="${GITLAB_URL_PREFIX}/api/${GITLAB_API_VERSION}/${api_url}?page=${page}&per_page=${PER_PAGE_MAX}&${api_params}" 28 | local curl_result 29 | 30 | curl_result="$( curl --include --silent --header "PRIVATE-TOKEN: ${GITLAB_PRIVATE_TOKEN}" "${curl_url}" )" 31 | local curl_rc=$? 32 | 33 | if [ ${curl_rc} -ne 0 ]; then 34 | echo "*** Error curl status ${curl_rc} : curl_url=${curl_url}" >&2 35 | return 1 36 | fi 37 | 38 | local head=true 39 | local body= 40 | local header= 41 | local line 42 | 43 | while read -r line; do 44 | if ${head} ; then 45 | if [[ "${line}" = "${CR}" ]]; then 46 | head=false 47 | else 48 | header="${header}${LF}${line}" 49 | fi 50 | else 51 | if [ -z "${body}" ]; then 52 | body="${line}" 53 | else 54 | body="${body}${LF}${line}" 55 | fi 56 | fi 57 | done < <(echo "${curl_result}") 58 | 59 | NEXT_PAGE="$( echo "${header}" | grep -i '^x-next-page:' | cut -c 14-| tr -d '[:space:]' )" 60 | PAGE_BODY="${body}" 61 | } 62 | 63 | # 64 | # HTTP GET - Read all pages 65 | # 66 | function gitlab_get { 67 | local api_url="$1" 68 | local api_params="$2" 69 | local page=1 70 | local json= 71 | local begin= 72 | 73 | NEXT_PAGE='*' 74 | 75 | while [[ ${page} =~ ^-?[0-9]+$ ]]; do 76 | gitlab_get_page "${api_url}" "${api_params}" "${page}" 77 | 78 | if [ -n "${json}" ] ; then 79 | json+=',' 80 | fi 81 | 82 | begin=$(echo "${PAGE_BODY}" | cut -b1 ) 83 | #echo "${begin}- ${page}" >>'body.txt' 84 | #echo "${PAGE_BODY}" >>'body.txt' 85 | if [ "${begin}" = '[' ] ; then 86 | json+="$( echo "${PAGE_BODY}" | cut -b2- | rev | cut -b2- | rev )" 87 | else 88 | json+="${PAGE_BODY}" 89 | fi 90 | 91 | page="${NEXT_PAGE}" 92 | done 93 | 94 | if [ "${begin}" = '[' ] ; then 95 | echo "[${json}]" 96 | else 97 | echo "${json}" 98 | fi 99 | } 100 | 101 | # 102 | # API: gitlab_post - HTTP POST - Read 1st returned page 103 | # 104 | function gitlab_post { 105 | local api_url="$1" 106 | local api_params="$2" 107 | 108 | local curl_url="${GITLAB_URL_PREFIX}/api/${GITLAB_API_VERSION}/${api_url}?per_page=${PER_PAGE_MAX}&${api_params}" 109 | local curl_result 110 | 111 | curl_result="$( curl --header "PRIVATE-TOKEN: ${GITLAB_PRIVATE_TOKEN}" -X POST --silent "${curl_url}" )" 112 | local curl_rc=$? 113 | 114 | if [ ${curl_rc} -ne 0 ]; then 115 | echo "*** Error curl status ${curl_rc} : curl_url=${curl_url}" >&2 116 | return 1 117 | fi 118 | 119 | echo "${curl_result}" 120 | } 121 | 122 | # 123 | # HTTP PUT - Read 1st returned page 124 | # 125 | function gitlab_put { 126 | local api_url="$1" 127 | local api_params="$2" 128 | 129 | local curl_url="${GITLAB_URL_PREFIX}/api/${GITLAB_API_VERSION}/${api_url}?per_page=${PER_PAGE_MAX}&${api_params}" 130 | local curl_result 131 | 132 | curl_result="$( curl --header "PRIVATE-TOKEN: ${GITLAB_PRIVATE_TOKEN}" -X PUT --silent "${curl_url}" )" 133 | local curl_rc=$? 134 | 135 | if [ ${curl_rc} -ne 0 ]; then 136 | echo "*** Error curl status ${curl_rc} : curl_url=${curl_url}" >&2 137 | return 1 138 | fi 139 | 140 | echo "${curl_result}" 141 | } 142 | 143 | # 144 | # HTTP DELETE - Read 1st returned page 145 | # 146 | function gitlab_delete { 147 | local api_url="$1" 148 | local api_params="$2" 149 | 150 | local curl_url="${GITLAB_URL_PREFIX}/api/${GITLAB_API_VERSION}/${api_url}?per_page=${PER_PAGE_MAX}&${api_params}" 151 | local curl_result 152 | 153 | curl_result="$( curl --header "PRIVATE-TOKEN: ${GITLAB_PRIVATE_TOKEN}" -X DELETE --silent "${curl_url}" )" 154 | local curl_rc=$? 155 | 156 | if [ ${curl_rc} -ne 0 ]; then 157 | echo "*** Error curl status ${curl_rc} : curl_url=${curl_url}" >&2 158 | return 1 159 | fi 160 | 161 | echo "${curl_result}" 162 | } 163 | 164 | function url_encode { 165 | # url_encode 166 | local LANG=C i c e='' 167 | for ((i=0;i<${#1};i++)); do 168 | c=${1:$i:1} 169 | # shellcheck disable=SC1001 170 | [[ "$c" =~ [a-zA-Z0-9\.\~\_\-] ]] || printf -v c '%%%02X' "'$c" 171 | e+="$c" 172 | done 173 | echo "$e" 174 | } 175 | 176 | function source_all_files_in_directory { 177 | local folder=$1 178 | local file 179 | 180 | for file in "${folder}"/* ; do 181 | source "${file}" 182 | done 183 | } 184 | 185 | function list_projects_in_group { 186 | local group_name=$1 187 | local answer 188 | 189 | answer="$( list_projects_raw )" 190 | 191 | # Rewrite result 192 | local result_for_group 193 | local size 194 | 195 | curl_result="$( echo "${answer}" | jq "[.[] | select(.namespace.name==\"${group_name}\")]" )" || exit $? 196 | size="$( echo "${result_for_group}" |jq '. | length' )" 197 | 198 | if [ "${size}" -eq 0 ] ; then 199 | echo "No project available for group [${group_name}] (group does not exist ?)" >&2 200 | exit 123 201 | fi 202 | 203 | echo "${result_for_group}" | jq -r ".[] | .path" || exit $? 204 | } 205 | 206 | function get_project_id { 207 | local group_name=$1 208 | local project_name=$2 209 | 210 | local answer 211 | local project_info 212 | local project_id 213 | local valid_project_id 214 | 215 | answer="$( gitlab_get "projects" )" || exit $? 216 | project_info="$( echo "${answer}" | jq -c ".[] | select( .path_with_namespace=\"${group_name}/${project_name}\")" )" || exit $? 217 | project_id="$( echo "${project_info}" | jq -c ".id" )" || exit $? 218 | valid_project_id="$( echo "${project_id}" | wc -l )" 219 | 220 | if [ "${valid_project_id}" -ne 1 ] ; then 221 | echo "*** More than one maching project: ${valid_project_id}" >&2 222 | exit 123 223 | fi 224 | 225 | if [ -z "${project_id}" ] ; then 226 | echo -e "** Project \"${group_name}/${project_name}\" does not exist" >&2 227 | exit 123 228 | fi 229 | 230 | echo "${project_id}" 231 | } 232 | 233 | function list_deploy_keys_raw { 234 | local project_id=$1 235 | local params=$2 236 | local answer= 237 | 238 | if [ -z "$project_id" ] ; then 239 | answer="$( gitlab_get "deploy_keys" "${params}" )" || exit $? 240 | else 241 | answer="$( gitlab_get "projects/${project_id}/deploy_keys" "${params}" )" || exit $? 242 | fi 243 | 244 | echo "${answer}" 245 | } 246 | 247 | function enable_deploy_keys { 248 | local project_id=$1 249 | local deploy_key_id=$2 250 | local answer 251 | 252 | answer="$( gitlab_post "/projects/${project_id}/deploy_keys/${deploy_key_id}/enable" )" || exit $? 253 | 254 | echo "${answer}" 255 | } 256 | 257 | function delete_deploy_keys { 258 | local project_id=$1 259 | local deploy_key_id=$2 260 | local answer 261 | 262 | answer="$( gitlab_delete "/projects/${project_id}/deploy_keys/${deploy_key_id}" )" || exit $? 263 | 264 | echo "${answer}" 265 | } 266 | 267 | function set_action { 268 | if [ -z "${ACTION}" ] ; then 269 | ACTION=$1 270 | else 271 | display_usage 272 | fi 273 | } 274 | 275 | # API : getErrorMessage 276 | 277 | function getErrorMessage { 278 | local message= 279 | message="$( echo "$1" | jq -r '. .message' 2>/dev/null )" 280 | 281 | if [ "${message}" = 'null' ]; then 282 | echo '' 283 | else 284 | echo "${message}" 285 | fi 286 | } 287 | 288 | # API : ensure_not_empty (tooling) 289 | 290 | function ensure_not_empty { 291 | local value=$1 292 | local message_if_empty=$2 293 | 294 | if [ -z "${value}" ] ; then 295 | echo "*** Missing value for: '${message_if_empty}'" >&2 296 | display_usage 297 | fi 298 | } 299 | 300 | # DEPRECATED : ensure_not_empty_deprecated 301 | 302 | function ensure_not_empty_deprecated { 303 | local var_name=$1 304 | local var_value=${!var_name} 305 | 306 | if [ -z "${var_value}" ] ; then 307 | echo "*** Missing ${var_name} value" >&2 308 | display_usage 309 | fi 310 | } 311 | 312 | # API : ensure_empty (tooling) 313 | 314 | function ensure_empty { 315 | local value=$1 316 | local message_if_not_empty=$2 317 | 318 | if [ -n "${value}" ] ; then 319 | echo "Unexpected value '${value}': ${message_if_not_empty}" >&2 320 | display_usage 321 | fi 322 | } 323 | 324 | # DEPRECATED : ensure_empty_deprecated 325 | 326 | function ensure_empty_deprecated { 327 | local var_name=$1 328 | local var_value=${!var_name} 329 | 330 | if [ -n "${var_value}" ] ; then 331 | echo "Unexpected value ${var_name}=${var_value}" >&2 332 | display_usage 333 | fi 334 | } 335 | 336 | # API : ensure_boolean (tooling) 337 | 338 | function ensure_boolean { 339 | local value=$1 340 | local parameter=$2 341 | 342 | case "${value}" in 343 | true|false) 344 | ;; 345 | *) 346 | echo "Bad value '${value}' for '${parameter}'. Should be true or false" >&2 347 | display_usage 348 | ;; 349 | esac 350 | } 351 | 352 | function jq_is_required { 353 | if ! which jq >/dev/null; then 354 | echo 'jq command is missing. Please install it. 355 | sudo apt install jq 356 | or 357 | sudo yum install jq 358 | ' >&2 359 | exit 1 360 | fi 361 | } 362 | 363 | jq_is_required || exit 1 364 | # 365 | # Load configuration 366 | # 367 | source_all_files_in_directory "${GITLAB_BASH_API_PATH}/config" 368 | 369 | if [ -d "${GITLAB_BASH_API_PATH}/my-config" ]; then 370 | source_all_files_in_directory "${GITLAB_BASH_API_PATH}/my-config" 371 | fi 372 | 373 | if [ -n "$GITLAB_BASH_API_CONFIG" ]; then 374 | if [ ! -d "${GITLAB_BASH_API_CONFIG}" ]; then 375 | echo "GITLAB_BASH_API_CONFIG=${GITLAB_BASH_API_CONFIG} - Folder not found." >&2 376 | exit 1 377 | fi 378 | 379 | source_all_files_in_directory "${GITLAB_BASH_API_CONFIG}" 380 | fi 381 | 382 | # 383 | # Check configuration 384 | # 385 | if [ -z "${GITLAB_PRIVATE_TOKEN}" ]; then 386 | echo "GITLAB_PRIVATE_TOKEN is missing." >&2 387 | exit 1 388 | fi 389 | 390 | if [ -z "${GITLAB_URL_PREFIX}" ]; then 391 | echo "GITLAB_URL_PREFIX is missing." >&2 392 | exit 1 393 | fi 394 | 395 | if [ -z "${PER_PAGE_MAX}" ]; then 396 | # Max value for GitLab is 100 397 | PER_PAGE_MAX=50 398 | fi 399 | -------------------------------------------------------------------------------- /complete/_glGroups: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Completion for gitlab cli: 5 | # glGroups 6 | # 7 | 8 | _glGroups() 9 | { 10 | local cur prev opts 11 | COMPREPLY=() 12 | opts='' 13 | cur="${COMP_WORDS[COMP_CWORD]}" 14 | prev="${COMP_WORDS[COMP_CWORD-1]}" 15 | 16 | if [ "${COMP_CWORD}" -eq 1 ]; then 17 | opts="--config --list-path --list-id --edit --create --delete" 18 | else 19 | context=${COMP_WORDS[@]:1:COMP_CWORD-1} 20 | sample='' 21 | for word in "${COMP_WORDS[@]:1:COMP_CWORD-1}" 22 | do 23 | if [ "$sample" != "" ]; then 24 | sample="$sample " 25 | fi 26 | if [ "${word:0:2}" == "--" ]; then 27 | sample="$sample$word" 28 | else 29 | sample="$sample@" 30 | fi 31 | done 32 | 33 | case $sample in 34 | '--config') 35 | opts='--path --id --all' 36 | ;; 37 | *" --path") 38 | opts='' 39 | ;; 40 | *" --id") 41 | opts='' 42 | ;; 43 | *" --name") 44 | opts='' 45 | ;; 46 | "--list-path") 47 | opts='--path --id --all' 48 | ;; 49 | "--list-id") 50 | opts="--path --id --all" 51 | ;; 52 | "--edit") 53 | opts="--id" 54 | ;; 55 | "--edit --id @") 56 | opts="--name" 57 | ;; 58 | "--edit --id @ --name @") 59 | opts="--path" 60 | ;; 61 | "--edit --id @ --name @ --path @") 62 | opts="--description" 63 | ;; 64 | "--edit --id @ --name @ --path @ --description @") 65 | opts="--visibility" 66 | ;; 67 | "--edit --id @ --name @ --path @ --description @ --visibility @") 68 | opts="--lfs_enabled" 69 | ;; 70 | "--edit --id @ --name @ --path @ --description @ --visibility @ --lfs_enabled @") 71 | opts="--request_access_enabled" 72 | ;; 73 | "--create") 74 | opts="--path" 75 | ;; 76 | "--create --path") 77 | opts="" 78 | ;; 79 | *" --name") 80 | opts="" 81 | ;; 82 | *" --path") 83 | opts="" 84 | ;; 85 | *" --visibility") 86 | opts="private internal public" 87 | ;; 88 | *" --description") 89 | opts="" 90 | ;; 91 | *" --lfs_enabled") 92 | opts="true false" 93 | ;; 94 | *" --membership_lock") 95 | opts="true false" 96 | ;; 97 | *" --request_access_enabled") 98 | opts="true false" 99 | ;; 100 | *" --share_with_group_lock") 101 | opts="true false" 102 | ;; 103 | "--create --path @"*) 104 | opts="--name --description --lfs_enabled --membership_lock --request_access_enabled --share_with_group_lock --visibility" 105 | ;; 106 | "--delete") 107 | opts="--id" 108 | ;; 109 | "--delete --id") 110 | opts="" 111 | ;; 112 | *) 113 | ;; 114 | esac 115 | fi 116 | 117 | result='' 118 | 119 | for word in $opts 120 | do 121 | if [ "$result" != "" ]; then 122 | result="$result " 123 | fi 124 | 125 | if [ "${word:0:2}" == "--" ]; then 126 | if doesntContain "${word}" "${COMP_WORDS[@]:1:COMP_CWORD-1}"; then 127 | result="$result$word" 128 | fi 129 | else 130 | result="$result$word" 131 | fi 132 | done 133 | 134 | COMPREPLY=( $(compgen -W "${result}" -- "${cur}") ) 135 | } 136 | 137 | if [ -z "${GITLAB_BASH_API_PATH}" ]; then 138 | echo "*** GITLAB_BASH_API_PATH is missing" >&2 139 | return 1 140 | fi 141 | 142 | alias glGroups="${GITLAB_BASH_API_PATH}/glGroups.sh" 143 | complete -F _glGroups glGroups 144 | c 145 | -------------------------------------------------------------------------------- /complete/_glProjects: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Completion for gitlab cli: 5 | # glProjects 6 | # 7 | 8 | _glProjects() 9 | { 10 | local cur prev opts 11 | 12 | COMPREPLY=() 13 | 14 | opts="" 15 | cur="${COMP_WORDS[COMP_CWORD]}" 16 | prev="${COMP_WORDS[COMP_CWORD-1]}" 17 | 18 | if [ "${COMP_CWORD}" -eq 1 ]; then 19 | opts="--config --list-path --list-id --create --delete" 20 | else 21 | context=${COMP_WORDS[@]:1:COMP_CWORD-1} 22 | sample="" 23 | for word in "${COMP_WORDS[@]:1:COMP_CWORD-1}" 24 | do 25 | if [ "$sample" != "" ]; then 26 | sample="$sample " 27 | fi 28 | if [ "${word:0:2}" == "--" ]; then 29 | sample="$sample$word" 30 | else 31 | sample="$sample@" 32 | fi 33 | done 34 | 35 | case $sample in 36 | "--config") 37 | opts="--compact --path --group-path --id --all" 38 | ;; 39 | "--config --compact") 40 | opts="--path --group-path --id --all" 41 | ;; 42 | *" --path") 43 | opts="" 44 | ;; 45 | *" --group-path") 46 | opts="" 47 | ;; 48 | *" --id") 49 | opts="" 50 | ;; 51 | *" --name") 52 | opts="" 53 | ;; 54 | "--list-path") 55 | opts="--path --id --all --group-path" 56 | ;; 57 | "--list-id") 58 | opts="--path --id --all --group-path" 59 | ;; 60 | "--create") 61 | opts="--group-id" 62 | ;; 63 | "--create --group-id") 64 | opts="" 65 | ;; 66 | "--create --group-id @") 67 | opts="--path" 68 | ;; 69 | *" --project-name") 70 | opts="" 71 | ;; 72 | *" --path") 73 | opts="" 74 | ;; 75 | *" --visibility") 76 | opts="private internal public" 77 | ;; 78 | *" --project-description") 79 | opts="" 80 | ;; 81 | *" --lfs-enabled") 82 | opts="true false" 83 | ;; 84 | *" --container-registry-enabled") 85 | opts="true false" 86 | ;; 87 | *" --issues-enabled") 88 | opts="true false" 89 | ;; 90 | *" --jobs-enabled") 91 | opts="true false" 92 | ;; 93 | *" --merge-requests-enabled") 94 | opts="true false" 95 | ;; 96 | *" --only-allow-merge-if-all-discussions-are-resolved") 97 | opts="true false" 98 | ;; 99 | *" --only-allow-merge-if-pipeline-succeed") 100 | opts="true false" 101 | ;; 102 | *" --printing-merge-request-link-enabled") 103 | opts="true false" 104 | ;; 105 | *" --public-jobs") 106 | opts="true false" 107 | ;; 108 | *" --request-access-enabled") 109 | opts="true false" 110 | ;; 111 | *" --snippets-enabled") 112 | opts="true false" 113 | ;; 114 | *" --wiki-enabled") 115 | opts="true false" 116 | ;; 117 | "--create --group-id @ --path @"*) 118 | opts="--project-name --project-description --container-registry-enabled --issues-enabled --jobs-enabled --lfs-enabled --merge-requests-enabled --only-allow-merge-if-all-discussions-are-resolved --only-allow-merge-if-pipeline-succeed --printing-merge-request-link-enabled --public-jobs --request-access-enabled --snippets-enabled --visibility --wiki-enabled" 119 | ;; 120 | "--delete") 121 | opts="--group-path --id" 122 | ;; 123 | "--delete --group-path @") 124 | opts="--path" 125 | ;; 126 | "--delete --id") 127 | opts="" 128 | ;; 129 | *) 130 | ;; 131 | esac 132 | fi 133 | 134 | result="" 135 | 136 | for word in $opts 137 | do 138 | 139 | if [ "$result" != "" ]; then 140 | result="$result " 141 | fi 142 | if [ "${word:0:2}" == "--" ]; then 143 | if doesntContain "${word}" "${COMP_WORDS[@]:1:COMP_CWORD-1}"; then 144 | result="$result$word" 145 | fi 146 | else 147 | result="$result$word" 148 | fi 149 | done 150 | 151 | COMPREPLY=( $(compgen -W "${result}" -- "${cur}") ) 152 | } 153 | 154 | if [ -z "${GITLAB_BASH_API_PATH}" ]; then 155 | echo "*** GITLAB_BASH_API_PATH is missing" >&2 156 | return 1 157 | fi 158 | 159 | alias glProjects="${GITLAB_BASH_API_PATH}/glProjects.sh" 160 | complete -F _glProjects glProjects 161 | 162 | -------------------------------------------------------------------------------- /complete/_gl_common: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function doesntContain { 4 | local e match="$1" 5 | shift 6 | for e; do [[ "$e" == "$match" ]] && return 1; done 7 | return 0 8 | } 9 | -------------------------------------------------------------------------------- /complete/complete-init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -z "${GITLAB_BASH_API_PATH}" ]; then 4 | GITLAB_BASH_API_PATH=$(dirname "$(dirname "$(realpath "$0")")") 5 | elif [ ! -f "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" ]; then 6 | echo "*** Bad value GITLAB_BASH_API_PATH=${GITLAB_BASH_API_PATH}" >&2 7 | echo "Try to fix using current file name" >&2 8 | 9 | GITLAB_BASH_API_PATH=$(dirname "$(dirname "$(realpath "$0")")") 10 | fi 11 | 12 | if [ -f "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" ]; then 13 | echo " 14 | Now run 15 | export GITLAB_BASH_API_PATH=${GITLAB_BASH_API_PATH} 16 | 17 | source '${GITLAB_BASH_API_PATH}/complete/_gl_common' 18 | source '${GITLAB_BASH_API_PATH}/complete/_glGroups' 19 | source '${GITLAB_BASH_API_PATH}/complete/_glProjects' 20 | " 21 | else 22 | echo "*** Bad value GITLAB_BASH_API_PATH=${GITLAB_BASH_API_PATH}" 23 | fi 24 | -------------------------------------------------------------------------------- /config/default-api-version: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # shellcheck disable=SC2034 3 | GITLAB_API_VERSION=v3 4 | -------------------------------------------------------------------------------- /config/default-audit-config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Audit filter for groups 5 | # 6 | # By default, next values are ignored (not relevant for audit): 7 | # projects: .projects, 8 | # 9 | # Theses values are define for backward compatibility 10 | # visibility_level: .visibility_level, 11 | # 12 | # shellcheck disable=SC2034 13 | GITLAB_DEFAULT_AUDIT_FOR_GROUP=' 14 | avatar_url: .avatar_url, 15 | description: .description, 16 | full_name: .full_name, 17 | full_path: .full_path, 18 | id: .id, 19 | ldap_access: .ldap_access, 20 | ldap_cn: .ldap_cn, 21 | lfs_enabled: .lfs_enabled, 22 | name: .name, 23 | parent_id: .parent_id, 24 | path: .path, 25 | request_access_enabled: .request_access_enabled, 26 | shared_projects: .shared_projects, 27 | shared_runners_minutes_limit: .shared_runners_minutes_limit, 28 | visibility: .visibility, 29 | visibility_level: .visibility_level, 30 | web_url: .web_url, 31 | ' 32 | 33 | 34 | # 35 | # Audit filter for projects 36 | # 37 | # By default, next values are ignored (not relevant for audit): 38 | # created_at: .created_at, 39 | # forks_count: .forks_count, 40 | # last_activity_at: .last_activity_at, 41 | # star_count: .star_count 42 | # 43 | # Theses values are define for backward compatibility 44 | # builds_enabled: .builds_enabled, 45 | # only_allow_merge_if_build_succeeds: .only_allow_merge_if_build_succeeds, 46 | # public: .public, 47 | # public_builds: .public_builds, 48 | # visibility_level: .visibility_level, 49 | # 50 | # shellcheck disable=SC2034 51 | GITLAB_DEFAULT_AUDIT_FOR_PROJECT=' 52 | _links: { 53 | events: ._links.events, 54 | labels: ._links.labels, 55 | members: ._links.members, 56 | merge_requests: ._links.merge_requests, 57 | repo_branches: ._links.repo_branches, 58 | self: ._links.self 59 | }, 60 | approvals_before_merge: .approvals_before_merge, 61 | archived: .archived, 62 | avatar_url: .avatar_url, 63 | builds_enabled: .builds_enabled, 64 | ci_config_path: .ci_config_path, 65 | container_registry_enabled: .container_registry_enabled, 66 | creator_id: .creator_id, 67 | default_branch: .default_branch, 68 | description: .description, 69 | http_url_to_repo: .http_url_to_repo, 70 | id: .id, 71 | import_error: .import_error, 72 | import_status: .import_status, 73 | issues_enabled: .issues_enabled, 74 | jobs_enabled: .jobs_enabled, 75 | lfs_enabled: .lfs_enabled, 76 | merge_requests_enabled: .merge_requests_enabled, 77 | name: .name, 78 | name_with_namespace: .name_with_namespace, 79 | namespace: { 80 | full_path: .namespace.full_path, 81 | id: .namespace.id, 82 | kind: .namespace.kind, 83 | members_count_with_descendants: .namespace.members_count_with_descendants, 84 | name: .namespace.name, 85 | parent_id: .namespace.parent_id, 86 | path: .namespace.path, 87 | plan: .namespace.plan, 88 | shared_runners_minutes_limit: .namespace.shared_runners_minutes_limit 89 | }, 90 | only_allow_merge_if_all_discussions_are_resolved: .only_allow_merge_if_all_discussions_are_resolved, 91 | only_allow_merge_if_pipeline_succeeds: .only_allow_merge_if_pipeline_succeeds, 92 | only_allow_merge_if_build_succeeds: .only_allow_merge_if_build_succeeds, 93 | path: .path, 94 | path_with_namespace: .path_with_namespace, 95 | permissions: { 96 | group_access: { 97 | access_level: .permissions.group_access.access_level, 98 | notification_level: .permissions.group_access.notification_level 99 | }, 100 | project_access: .permissions.project_access 101 | }, 102 | printing_merge_request_link_enabled: .printing_merge_request_link_enabled, 103 | public: .public, 104 | public_builds: .public_builds, 105 | public_jobs: .public_jobs, 106 | repository_storage: .repository_storage, 107 | request_access_enabled: .request_access_enabled, 108 | runners_token: .runners_token, 109 | shared_runners_enabled: .shared_runners_enabled, 110 | shared_with_groups: .shared_with_groups, 111 | snippets_enabled: .snippets_enabled, 112 | ssh_url_to_repo: .ssh_url_to_repo, 113 | tag_list: .tag_list, 114 | visibility: .visibility, 115 | visibility_level: .visibility_level, 116 | web_url: .web_url, 117 | wiki_enabled: .wiki_enabled 118 | ' 119 | 120 | 121 | # tag_list: .tag_list[], 122 | # namespace: .namespace[], 123 | # shared_with_groups: .shared_with_groups[], 124 | # permissions: .permissions[] 125 | 126 | #created_at: 2017-07-11T07:35:24.223Z", 127 | #last_activity_at: 2017-08-20T08:55:33.186Z", 128 | 129 | #namespace: { 130 | # id: 131 | # name: 132 | # path: 133 | # kind: 134 | # }, 135 | #shared_with_groups: [], 136 | 137 | #permissions: { 138 | # project_access: null, 139 | # group_access: { 140 | # access_level: 40, 141 | # notification_level: 3 142 | # } 143 | # } 144 | 145 | -------------------------------------------------------------------------------- /config/default-group-config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Default values for groups 5 | # 6 | # shellcheck disable=SC2034 7 | GITLAB_DEFAULT_GROUP_DESCRIPTION='PLEASE update description' 8 | 9 | # shellcheck disable=SC2034 10 | GITLAB_DEFAULT_GROUP_LFS_ENABLED=false 11 | # shellcheck disable=SC2034 12 | GITLAB_DEFAULT_GROUP_MEMBERSHIP_LOCK=true 13 | # shellcheck disable=SC2034 14 | GITLAB_DEFAULT_GROUP_REQUEST_ACCESS_ENABLED=true 15 | # shellcheck disable=SC2034 16 | GITLAB_DEFAULT_GROUP_SHARE_WITH_GROUP_LOCK=true 17 | # shellcheck disable=SC2034 18 | GITLAB_DEFAULT_GROUP_VISIBILITY=internal 19 | -------------------------------------------------------------------------------- /config/default-project-config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Default values for projects 4 | # 5 | # shellcheck disable=SC2034 6 | GITLAB_DEFAULT_PROJECT_DESCRIPTION='PLEASE update description' 7 | 8 | # shellcheck disable=SC2034 9 | GITLAB_DEFAULT_PROJECT_CONTAINER_REGISTRY_ENABLED=false 10 | # shellcheck disable=SC2034 11 | GITLAB_DEFAULT_PROJECT_ISSUES_ENABLED=false 12 | # shellcheck disable=SC2034 13 | GITLAB_DEFAULT_PROJECT_JOBS_ENABLED=false 14 | # shellcheck disable=SC2034 15 | GITLAB_DEFAULT_PROJECT_LFS_ENABLED=false 16 | # shellcheck disable=SC2034 17 | GITLAB_DEFAULT_PROJECT_MERGE_REQUESTS_ENABLED=true 18 | # shellcheck disable=SC2034 19 | GITLAB_DEFAULT_PROJECT_ONLY_ALLOW_MERGE_IF_ALL_DISCUSSIONS_ARE_RESOLVED=false 20 | # shellcheck disable=SC2034 21 | GITLAB_DEFAULT_PROJECT_ONLY_ALLOW_MERGE_IF_PIPELINE_SUCCEEDS=true 22 | # shellcheck disable=SC2034 23 | GITLAB_DEFAULT_PROJECT_PRINTING_MERGE_REQUEST_LINK_ENABLED=true 24 | # shellcheck disable=SC2034 25 | GITLAB_DEFAULT_PROJECT_PUBLIC_JOBS=false 26 | # shellcheck disable=SC2034 27 | GITLAB_DEFAULT_PROJECT_REQUEST_ACCESS_ENABLED=true 28 | # shellcheck disable=SC2034 29 | GITLAB_DEFAULT_PROJECT_SNIPPETS_ENABLED=false 30 | # shellcheck disable=SC2034 31 | GITLAB_DEFAULT_PROJECT_VISIBILITY=internal 32 | # shellcheck disable=SC2034 33 | GITLAB_DEFAULT_PROJECT_WIKI_ENABLED=false 34 | -------------------------------------------------------------------------------- /config/default-user-config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Default values for users 5 | # 6 | # shellcheck disable=SC2034 7 | GITLAB_USER_INITIAL_PASSWORD='P@zzW0rd!_CHANGE_ME' 8 | 9 | # shellcheck disable=SC2034 10 | GITLAB_USER_CAN_CREATE_GROUP=false 11 | # shellcheck disable=SC2034 12 | GITLAB_USER_CONFIRM=true 13 | # shellcheck disable=SC2034 14 | GITLAB_USER_IS_ADMIN=false 15 | # shellcheck disable=SC2034 16 | GITLAB_USER_PROJECTS_LIMIT=10 17 | # shellcheck disable=SC2034 18 | GITLAB_USER_RESET_PASSWORD=true 19 | # shellcheck disable=SC2034 20 | GITLAB_USER_SHARED_RUNNERS_MINUTES_LIMIT=0 21 | -------------------------------------------------------------------------------- /custom-config-sample/customize-curl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # An exemple if for a PoC you need to use an insecure curl connection. 4 | # 5 | 6 | shopt -s expand_aliases 7 | 8 | alias curl="$(which curl) --insecure" 9 | -------------------------------------------------------------------------------- /custom-config-sample/my-api-version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | GITLAB_API_VERSION=v4 4 | -------------------------------------------------------------------------------- /custom-config-sample/my-platform-configuration.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Configuration related to the platform 4 | # 5 | 6 | GITLAB_URL_PREFIX=https://gitlab.local/ 7 | 8 | # Optionnal 9 | 10 | # Require to clone using ssh 11 | GITLAB_CLONE_SSH_PREFIX=ssh://git@192.168.10.200/ 12 | 13 | # You can also configure in you ~/.bashrc file 14 | # 15 | # export GITLAB_BASH_API_PATH='__YOUR_PATH_TO/gitlab-bash-api' 16 | # export GITLAB_BASH_API_CONFIG="${GITLAB_BASH_API_PATH}/my-config" 17 | -------------------------------------------------------------------------------- /custom-config-sample/my-secrets-configuration.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Configuration related to the user 4 | # 5 | 6 | GITLAB_PRIVATE_TOKEN=__YOUR_GITLAB_TOKEN_HERE__ 7 | 8 | # Optionnal 9 | 10 | # Require to clone using http/https 11 | #GITLAB_USER=__YOUR_GIT_USER__ 12 | #GITLAB_PASSWORD=$(url_encode '__YOUR_GIT_USER_PASSWORD__') 13 | #GITLAB_CLONE_HTTP_PREFIX="https://${GITLAB_USER}:${GITLAB_PASSWORD}@${GITLAB_URL_PREFIX#"https://"}" 14 | -------------------------------------------------------------------------------- /glAudit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function display_usage { 4 | echo "Usage: $0 5 | Audit full gitlab bash on current credentials 6 | $0 --directory AUDIT_DESTINATION_FOLDER 7 | " >&2 8 | exit 100 9 | } 10 | 11 | function mk_relative_link { 12 | local target=$1 13 | local link_name=$2 14 | 15 | if [ -z "${target}" ]; then 16 | echo "*** mk_relative_link: target value is missing" >&2 17 | exit 1 18 | fi 19 | if [ -z "${link_name}" ]; then 20 | echo "*** mk_relative_link: link_name value is missing" >&2 21 | exit 1 22 | fi 23 | 24 | if [ -f "${link_name}" ]; then 25 | rm "${link_name}" # avoid link resolution 26 | fi 27 | 28 | local relative_target 29 | 30 | relative_target=$(realpath --no-symlinks --relative-to="$(dirname "${link_name}")" "${target}") 31 | 32 | # echo "relative_target='${relative_target}' link_name='${link_name}' target=${target}" >&2 33 | 34 | ln -s --force "${relative_target}" "${link_name}" 35 | } 36 | 37 | function build_audit_folder { 38 | local audit_folder=$1 39 | local file_type=$2 40 | 41 | if [ -z "${audit_folder}" ]; then 42 | echo "*** build_audit_folder: audit_folder value is missing" >&2 43 | exit 1 44 | fi 45 | if [ -z "${file_type}" ]; then 46 | echo "*** build_audit_folder: file_type value is missing" >&2 47 | exit 1 48 | fi 49 | 50 | local folder="${audit_folder}/${file_type}" 51 | 52 | if [ ! -d "${folder}" ]; then 53 | mkdir -p "${folder}" || exit $? 54 | fi 55 | 56 | echo "${folder}" 57 | } 58 | 59 | function build_audit_file { 60 | local audit_folder=$1 61 | local file_type=$2 62 | local file_name=$3 63 | 64 | if [ -z "${audit_folder}" ]; then 65 | echo "*** build_audit_file: audit_folder value is missing" >&2 66 | exit 1 67 | fi 68 | if [ -z "${file_type}" ]; then 69 | echo "*** build_audit_file: file_type value is missing" >&2 70 | exit 1 71 | fi 72 | if [ -z "${file_name}" ]; then 73 | echo "*** build_audit_file: file_name value is missing" >&2 74 | exit 1 75 | fi 76 | 77 | local file 78 | local parent 79 | 80 | file="$(build_audit_folder "${audit_folder}" "${file_type}")/${file_name}.json" || exit 1 81 | parent=$(dirname "${file}") || exit 1 82 | 83 | if [ ! -d "${parent}" ]; then 84 | mkdir "${parent}" 85 | fi 86 | 87 | echo "${file}" 88 | } 89 | 90 | function get_group_ids { 91 | "${GITLAB_BASH_API_PATH}/glGroups.sh" --all --list-id || exit 1 92 | } 93 | 94 | function get_project_ids { 95 | "${GITLAB_BASH_API_PATH}/glProjects.sh" --all --list-id || exit 1 96 | } 97 | 98 | function get_group_config_by_id { 99 | local group_id=$1 100 | 101 | if [ -z "${GITLAB_DEFAULT_AUDIT_FOR_GROUP}" ]; then 102 | echo "* GITLAB_DEFAULT_AUDIT_FOR_GROUP is not define" >&2 103 | exit 1 104 | fi 105 | 106 | show_group_config "${group_id}" \ 107 | | jq ". | { ${GITLAB_DEFAULT_AUDIT_FOR_GROUP} }" 108 | } 109 | 110 | function get_project_config_by_id { 111 | local project_id=$1 112 | 113 | if [ -z "${GITLAB_DEFAULT_AUDIT_FOR_PROJECT}" ]; then 114 | echo "* GITLAB_DEFAULT_AUDIT_FOR_PROJECT is not define" >&2 115 | exit 1 116 | fi 117 | 118 | audit_project "${project_id}" \ 119 | | jq ". | select(.[].id=${project_id}) | .[0] | { ${GITLAB_DEFAULT_AUDIT_FOR_PROJECT} }" 120 | } 121 | 122 | function audit_groups_configuration { 123 | local audit_folder=$1 124 | local group_ids 125 | 126 | group_ids=$(get_group_ids) 127 | 128 | for group_id in ${group_ids}; do 129 | local group_config 130 | local group_path 131 | 132 | group_config=$(get_group_config_by_id "${group_id}") 133 | group_path=$(echo "${group_config}" | jq -r '. .path') 134 | 135 | if [ -z "${group_path}" ]; then 136 | echo "*** Error: can not retrieve configuration for group '${group_id}'" >&2 137 | else 138 | local audit_file 139 | local path_link 140 | 141 | audit_file=$(build_audit_file "${audit_folder}" 'groups_by_id' "${group_id}") || exit 1 142 | path_link=$(build_audit_file "${audit_folder}" 'groups_by_path' "${group_path}") || exit 1 143 | 144 | echo "* audit group ${group_id} / ${group_path}" >&2 145 | 146 | echo "${group_config}" > "${audit_file}" 147 | 148 | mk_relative_link "${audit_file}" "${path_link}" 149 | fi 150 | done 151 | } 152 | 153 | function audit_projects_configuration { 154 | local audit_folder=$1 155 | local project_ids 156 | 157 | project_ids=$(get_project_ids) 158 | 159 | for project_id in ${project_ids}; do 160 | local project_config 161 | local project_path 162 | local project_fullpath 163 | 164 | project_config=$(get_project_config_by_id "${project_id}") 165 | project_path=$(echo "${project_config}" | jq -r '.path') 166 | project_fullpath=$(echo "${project_config}" | jq -r '.path_with_namespace') 167 | 168 | if [ -z "${project_path}" ]; then 169 | echo "*** Error: can not retrieve configuration for project '${project_id}'" >&2 170 | else 171 | local audit_file 172 | local path_link 173 | local fullpath_link 174 | 175 | audit_file=$(build_audit_file "${audit_folder}" 'projects_by_id' "${project_id}") 176 | path_link=$(build_audit_file "${audit_folder}" 'projects_by_path' "${project_path}") 177 | fullpath_link=$(build_audit_file "${audit_folder}" 'projects_by_path_with_namespace' "${project_fullpath}") 178 | 179 | echo "* audit project ${project_id} / ${project_path}" >&2 180 | # echo "* audit project ${project_id} / ${project_path} / ${project_fullpath} -> ${audit_file}" >&2 181 | 182 | echo "${project_config}" > "${audit_file}" 183 | 184 | mk_relative_link "${audit_file}" "${path_link}" 185 | mk_relative_link "${audit_file}" "${fullpath_link}" 186 | fi 187 | done 188 | } 189 | 190 | function do_audit { 191 | local audit_folder_home=$1 192 | 193 | # 194 | audit_groups_configuration "${audit_folder_home}" || exit 1 195 | # 196 | audit_projects_configuration "${audit_folder_home}" || exit 1 197 | 198 | #audit_users_configuration ? "${audit_folder_home}" || exit 1 199 | #audit_merge_request ? "${audit_folder_home}" || exit 1 200 | #audit_merge_request_configuration ? "${audit_folder_home}" || exit 1 201 | #audit_merge_request ? "${audit_folder_home}" || exit 1 202 | } 203 | 204 | function main { 205 | local audit_folder_home= 206 | 207 | while [[ $# -gt 0 ]]; do 208 | local param="$1" 209 | shift 210 | 211 | case "${param}" in 212 | -d|--directory) 213 | audit_folder_home="$1" 214 | shift 215 | ;; 216 | *) 217 | # unknown option 218 | echo "Unknown parameter ${param}" >&2 219 | display_usage 220 | ;; 221 | esac 222 | done 223 | 224 | if [ -z "${audit_folder_home}" ]; then 225 | display_usage 226 | else 227 | do_audit "${audit_folder_home}" 228 | fi 229 | } 230 | 231 | # Configuration - BEGIN 232 | if [ -z "$GITLAB_BASH_API_PATH" ]; then 233 | GITLAB_BASH_API_PATH=$(dirname "$(realpath "$0")") 234 | fi 235 | 236 | if [ ! -f "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" ]; then 237 | echo "gitlab-bash-api.sh not found! - Please set GITLAB_BASH_API_PATH" >&2 238 | exit 1 239 | fi 240 | 241 | source "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" 242 | # Configuration - END 243 | 244 | # Script start here 245 | source "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api-group.sh" 246 | source "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api-project.sh" 247 | 248 | main "$@" 249 | -------------------------------------------------------------------------------- /glBranches.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function display_usage { 4 | echo "Usage: $0 5 | Get branches configuration (ALPHA) 6 | $0 --config --id PROJECT_ID [ --name BRANCH_NAME] 7 | " >&2 8 | exit 100 9 | } 10 | 11 | function ensure_action_empty { 12 | local action=$1 13 | 14 | ensure_empty "${action}" "action already define: '${action}'" 15 | } 16 | 17 | function main { 18 | local action= 19 | local project_id= 20 | local branch_name= 21 | 22 | while [[ $# -gt 0 ]]; do 23 | param="$1" 24 | shift 25 | 26 | case "${param}" in 27 | --config) 28 | ensure_action_empty "${action}" 29 | action=showConfigAction 30 | ;; 31 | --create) 32 | ensure_action_empty "${action}" 33 | action=createAction 34 | ;; 35 | --delete) 36 | ensure_action_empty "${action}" 37 | action=deleteAction 38 | ;; 39 | --edit) 40 | ensure_action_empty "${action}" 41 | action=editAction 42 | ;; 43 | -i|--id|--project-id) 44 | project_id="$1" 45 | shift 46 | ;; 47 | --list-path) 48 | ensure_action_empty "${action}" 49 | action=listPathsAction 50 | ;; 51 | --list-id) 52 | ensure_action_empty "${action}" 53 | action=listIdsAction 54 | ;; 55 | --membership_lock) 56 | param_group_membership_lock="$1" 57 | shift 58 | 59 | ensure_boolean "${param_group_membership_lock}" '--membership_lock' 60 | ;; 61 | -n|--name) 62 | branch_name="$1" 63 | shift 64 | ;; 65 | --path) 66 | param_group_path="$1" 67 | shift 68 | ;; 69 | --request_access_enabled) 70 | param_group_request_access_enabled="$1" 71 | shift 72 | 73 | ensure_boolean "${param_group_request_access_enabled}" '--request_access_enabled' 74 | ;; 75 | --share_with_group_lock) 76 | param_group_share_with_group_lock="$1" 77 | shift 78 | 79 | ensure_boolean "${param_group_share_with_group_lock}" '--share_with_group_lock' 80 | ;; 81 | --visibility) 82 | param_group_visibility="$1" 83 | shift 84 | 85 | case "${param_group_visibility}" in 86 | private|internal|public) 87 | ;; 88 | *) 89 | echo "Illegal value '${param_group_visibility}'. --visibility should be private, internal or public." >&2 90 | display_usage 91 | ;; 92 | esac 93 | ;; 94 | *) 95 | # unknown option 96 | echo "Unknown parameter ${param}" >&2 97 | display_usage 98 | ;; 99 | esac 100 | done 101 | 102 | case "${action}" in 103 | createAction) 104 | ensure_not_empty param_group_path 105 | 106 | create_group_handle_params "${param_group_path}" "${param_group_name}" "${param_group_description}" \ 107 | "${param_group_lfs_enabled}" "${param_group_membership_lock}" "${param_group_request_access_enabled}" \ 108 | "${param_group_share_with_group_lock}" "${param_group_visibility}" \ 109 | | jq . 110 | ;; 111 | deleteAction) 112 | ensure_not_empty param_group_id 113 | delete_group "${param_group_id}" \ 114 | | jq . 115 | ;; 116 | editAction) 117 | ensure_not_empty param_group_id 118 | ensure_not_empty param_group_name 119 | ensure_not_empty param_group_path 120 | ensure_not_empty param_group_visibility 121 | 122 | edit_group "${param_group_id}" "${param_group_name}" "${param_group_path}" \ 123 | "${param_group_description_define}" "${param_group_description}" \ 124 | "${param_group_visibility}" "${param_group_lfs_enabled}" "${param_group_request_access_enabled}" \ 125 | | jq . 126 | ;; 127 | listPathsAction) 128 | list_groups_paths_handle_params "${param_all_groups}" "${param_group_id}" "${param_group_path}" 129 | ;; 130 | listIdsAction) 131 | list_groups_ids_handle_params "${param_all_groups}" "${param_group_id}" "${param_group_path}" 132 | ;; 133 | showConfigAction) 134 | list_branches "${project_id}" "${branch_name}" | jq . 135 | ;; 136 | *) 137 | # unknown option 138 | echo "Missing --config, --list-name, --list-id, --edit or --delete" >&2 139 | echo "Unexpected value for action: '${action}'" >&2 140 | display_usage 141 | ;; 142 | esac 143 | } 144 | 145 | # Configuration - BEGIN 146 | if [ -z "$GITLAB_BASH_API_PATH" ]; then 147 | GITLAB_BASH_API_PATH=$(dirname "$(realpath "$0")") 148 | fi 149 | 150 | if [ ! -f "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" ]; then 151 | echo "gitlab-bash-api.sh not found! - Please set GITLAB_BASH_API_PATH" >&2 152 | exit 1 153 | fi 154 | 155 | source "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" 156 | # Configuration - END 157 | 158 | # Script start here 159 | source "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api-branch.sh" 160 | 161 | if [ $# -eq 0 ]; then 162 | display_usage 163 | fi 164 | 165 | main "$@" 166 | -------------------------------------------------------------------------------- /glCloneAllProjects.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Limitations and bugs 4 | # * Does not support wikis 5 | 6 | # Configuration - BEGIN 7 | if [ -z "${GITLAB_BASH_API_PATH}" ]; then 8 | GITLAB_BASH_API_PATH="$( dirname "$( realpath "$0" )" )" 9 | fi 10 | 11 | if [ ! -f "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" ]; then 12 | echo "gitlab-bash-api.sh not found! - Please set GITLAB_BASH_API_PATH" >&2 13 | exit 1 14 | fi 15 | 16 | source "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" 17 | # Configuration - END 18 | 19 | # Script start here 20 | source "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api-project.sh" 21 | 22 | function display_usage { 23 | echo "Clone all projects by groups 24 | 25 | Usage: $0 26 | $0 --http [--bare] [--destination ] 27 | $0 --ssh [--bare] [--destination ] 28 | " >&2 29 | exit 1 30 | } 31 | 32 | function get_prefix_url { 33 | local clone_type=$1 34 | 35 | local prefix_url= 36 | 37 | case "${clone_type}" in 38 | http) 39 | if [ -z "${GITLAB_CLONE_HTTP_PREFIX}" ] ; then 40 | echo "*** GITLAB_CLONE_HTTP_PREFIX is not define" >&2 41 | exit 1 42 | fi 43 | 44 | prefix_url="${GITLAB_CLONE_HTTP_PREFIX}" 45 | ;; 46 | ssh) 47 | if [ -z "${GITLAB_CLONE_SSH_PREFIX}" ] ; then 48 | echo "*** GITLAB_CLONE_SSH_PREFIX is not define" >&2 49 | exit 1 50 | fi 51 | 52 | prefix_url="${GITLAB_CLONE_SSH_PREFIX}" 53 | ;; 54 | *) 55 | echo "Unkown clone_type: '${clone_type}'" 56 | exit 1 57 | ;; 58 | esac 59 | 60 | echo "${prefix_url}" 61 | } 62 | 63 | function git_clone { 64 | local p_bare=$1 65 | local project_url=$2 66 | 67 | if [ ! $# -eq 2 ]; then 68 | echo "* git_clone: Expecting 2 parameters found $# : '$*'" >&2 69 | exit 1 70 | fi 71 | 72 | echo "clone ${project_url}" 73 | if [ -d "$( basename "${project_url}" )" ];then 74 | pushd "$( basename "${project_url}" )" >/dev/null 75 | git pull --rebase 76 | local clone_rc=$? 77 | popd >/dev/null 78 | elif [ -d "$( basename "${project_url}" .git )" ];then 79 | pushd "$( basename "${project_url}" .git )" >/dev/null 80 | git fetch --all 81 | local clone_rc=$? 82 | popd >/dev/null 83 | else 84 | # shellcheck disable=SC2086 85 | git clone ${p_bare} "${project_url}" 86 | local clone_rc=$? 87 | fi 88 | 89 | if [ "${clone_rc}" -ne 0 ] ; then 90 | echo "*** Error while clonning: ${project_url}" 91 | exit 1 92 | fi 93 | } 94 | 95 | function get_all_projects_to_clone { 96 | # 97 | # Get all projects with a filled repository 98 | # 99 | declare id_project_list 100 | 101 | id_project_list="$( gitlab_get /projects | jq -r '.[] | (.id|tostring) + ":" + (.path_with_namespace)' )" || exit 1 102 | 103 | for id_project in ${id_project_list} ; do 104 | declare id 105 | declare project 106 | 107 | id=$(echo "${id_project}" | cut -d ':' -f1) || exit 1 108 | project=$(echo "${id_project}" | cut -d ':' -f2-) || exit 1 109 | 110 | # Check if there is any branch 111 | gitlab_get "/projects/${id}/repository/branches/" | jq '.[] | .name' 1>/dev/null 2>&1 112 | if [ $? -eq 0 ] ; then 113 | echo "${project}" 114 | else 115 | echo "Ignore empty project: (${id})${project}" >&2 116 | fi 117 | done 118 | 119 | # Before verison 10 of GitLab 120 | # gitlab_get "/projects/${id}/wikis" return 121 | # {"error":"404 Not Found"} 122 | 123 | } 124 | 125 | function clone_all_projects { 126 | local url_type=$1 127 | local bare=$2 128 | local root_output_directory=$3 129 | 130 | if [ ! $# -eq 3 ]; then 131 | echo "* clone_all_projects: Expecting 3 parameters found $# : '$*'" >&2 132 | exit 1 133 | fi 134 | 135 | local prefix_url 136 | 137 | prefix_url=$(get_prefix_url "${url_type}") || exit $? 138 | 139 | if [ -z "${prefix_url}" ]; then 140 | echo "*** Error when computing clone URL" >&2 141 | exit 1 142 | fi 143 | 144 | local project_paths 145 | 146 | #project_paths=$(get_all_projects_path_with_namespace) || exit $? 147 | project_paths=$(get_all_projects_to_clone) || exit $? 148 | echo "Projects to clone 149 | ------------------------------------------------- 150 | $project_paths 151 | ------------------------------------------------- 152 | " 153 | 154 | mkdir -p "${root_output_directory}" 155 | pushd "${root_output_directory}" >/dev/null 156 | 157 | for project_path in ${project_paths}; do 158 | local group_folder 159 | 160 | group_folder=$(echo "${project_path}" | cut -d'/' -f1) 161 | 162 | echo "# '${group_folder}' <- '${project_path}'" 163 | 164 | mkdir -p "${group_folder}" 165 | pushd "${group_folder}" >/dev/null 166 | 167 | git_clone "${bare}" "${prefix_url}${project_path}.git" 168 | 169 | popd >/dev/null 170 | done 171 | 172 | popd >/dev/null 173 | } 174 | 175 | function display_http_helper { 176 | local user= 177 | 178 | if [ -z "${GITLAB_USER}" ] ; then 179 | user='' 180 | else 181 | user="${GITLAB_USER}" 182 | fi 183 | 184 | echo "When using http you probably whant to use credential helper cache:" >&2 185 | echo " git config --global credential.helper 'cache --timeout 3600'" >&2 186 | echo " git config --global credential.${GITLAB_CLONE_HTTP_PREFIX} ${user}" >&2 187 | echo "or credential helper cache:" >&2 188 | echo " git config --global credential.helper store" >&2 189 | echo " git config --global credential.${GITLAB_CLONE_HTTP_PREFIX} ${user}" >&2 190 | } 191 | 192 | function main { 193 | local url_type= 194 | local bare= 195 | local root_output_directory=. 196 | 197 | while [[ $# -gt 0 ]]; do 198 | local param="$1" 199 | shift 200 | 201 | case "${param}" in 202 | --bare) 203 | bare="--bare" 204 | ;; 205 | -d|--destination) 206 | root_output_directory="$1" 207 | shift 208 | ;; 209 | --http) 210 | ensure_empty_deprecated url_type 211 | url_type="http" 212 | ;; 213 | --ssh) 214 | ensure_empty_deprecated url_type 215 | url_type="ssh" 216 | ;; 217 | *) 218 | # unknown option 219 | echo "Undefine parameter ${param}" >&2 220 | display_usage 221 | ;; 222 | esac 223 | done 224 | 225 | if [ -z "${url_type}" ] ; then 226 | echo "** Missing parameter --http or --ssh" >&2 227 | display_usage 228 | fi 229 | 230 | if [ "${url_type}" = "http" ] ; then 231 | display_http_helper 232 | fi 233 | 234 | clone_all_projects "${url_type}" "${bare}" "${root_output_directory}" 235 | } 236 | 237 | main "$@" 238 | -------------------------------------------------------------------------------- /glCreateUser.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Documentation: 4 | # https://docs.gitlab.com/ee/api/users.html#user-creation 5 | # 6 | # Parameters: 7 | # email (required) - Email 8 | # password (optional) - Password 9 | # reset_password (optional) - Send user password reset link - true or false(default) 10 | # username (required) - Username 11 | # name (required) - Name 12 | # 13 | # skype (optional) - Skype ID 14 | # linkedin (optional) - LinkedIn 15 | # twitter (optional) - Twitter account 16 | # website_url (optional) - Website URL 17 | # organization (optional) - Organization name 18 | # projects_limit (optional) - Number of projects user can create 19 | # extern_uid (optional) - External UID 20 | # provider (optional) - External provider name 21 | # bio (optional) - User's biography 22 | # location (optional) - User's location 23 | # admin (optional) - User is admin - true or false (default) 24 | # can_create_group (optional) - User can create groups - true or false 25 | # confirm (optional) - Require confirmation - true (default) or false 26 | # external (optional) - Flags the user as external - true or false(default) 27 | # shared_runners_minutes_limit (optional) - Pipeline minutes quota for this user 28 | # avatar (optional) - Image file for user's avatar# 29 | # 30 | 31 | # Configuration - BEGIN 32 | if [ -z "$GITLAB_BASH_API_PATH" ]; then 33 | GITLAB_BASH_API_PATH=$(dirname "$(realpath "$0")") 34 | fi 35 | 36 | if [ ! -f "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" ]; then 37 | echo "gitlab-bash-api.sh not found! - Please set GITLAB_BASH_API_PATH" >&2 38 | exit 1 39 | fi 40 | 41 | source "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" 42 | # Configuration - END 43 | 44 | # Script start here 45 | if [[ $# -lt 3 ]] ; then 46 | echo "Usage: $0 USER_NAME 'USER_FULLNAME' 'USER_EMAIL'" >&2 47 | exit 1 48 | fi 49 | 50 | # Parameters 51 | 52 | USER_NAME=$1 53 | USER_FULLNAME=$2 54 | USER_EMAIL=$3 55 | 56 | echo "create user: USER_NAME=[${USER_NAME}] USER_FULLNAME=[${USER_FULLNAME}] - USER_EMAIL=[${USER_EMAIL}]" 57 | 58 | # Build paramters 59 | PARAMS="email=${USER_EMAIL}" 60 | PARAMS+="&username=${USER_NAME}" 61 | 62 | ENCODED=$(url_encode "${USER_FULLNAME}") 63 | PARAMS+="&name=${ENCODED}" 64 | 65 | PARAMS+="&password=${GITLAB_USER_INITIAL_PASSWORD}" 66 | 67 | PARAMS+="&admin=${GITLAB_USER_IS_ADMIN}" 68 | PARAMS+="&can_create_group=${GITLAB_USER_CAN_CREATE_GROUP}" 69 | PARAMS+="&confirm=${GITLAB_USER_CONFIRM}" 70 | PARAMS+="&projects_limit=${GITLAB_USER_PROJECTS_LIMIT}" 71 | PARAMS+="&reset_password=${GITLAB_USER_RESET_PASSWORD}" 72 | PARAMS+="&shared_runners_minutes_limit=${GITLAB_USER_SHARED_RUNNERS_MINUTES_LIMIT}" 73 | 74 | #echo "PARAMS:${PARAMS}" 75 | 76 | answer=$(gitlab_post "users" "${PARAMS}") || exit 1 77 | USER_ID=$(echo "${answer}" | jq .id) 78 | 79 | if [ "${USER_ID}" = "null" ] ; then 80 | echo "*** USER_NAME=[${USER_NAME}] not created - already exist ?" >&2 81 | echo "${answer}" >&2 82 | exit 100 83 | fi 84 | 85 | echo "${USER_ID}" 86 | -------------------------------------------------------------------------------- /glDeployKeys.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Documentation: 4 | # https://docs.gitlab.com/ce/api/deploy_keys.html 5 | # 6 | declare ACTION='' 7 | 8 | function display_usage { 9 | echo "Usage: $0" >&2 10 | echo " List all existing deploy keys" >&2 11 | echo " $0 (no parameters)" >&2 12 | echo " List enabled deploy keys for a project" >&2 13 | echo " $0 --project-id PROJECT_ID" >&2 14 | echo " Enable a deploy key on a project" >&2 15 | echo " $0 --enable --project-id PROJECT_ID --key-id DEPLOY_KEY_ID" >&2 16 | echo " Delete a deploy key on a project" >&2 17 | echo " $0 --delete --project-id PROJECT_ID --key-id DEPLOY_KEY_ID" >&2 18 | exit 100 19 | } 20 | 21 | # Configuration - BEGIN 22 | if [ -z "$GITLAB_BASH_API_PATH" ]; then 23 | GITLAB_BASH_API_PATH=$(dirname "$(realpath "$0")") 24 | fi 25 | 26 | if [ ! -f "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" ]; then 27 | echo "gitlab-bash-api.sh not found! - Please set GITLAB_BASH_API_PATH" >&2 28 | exit 1 29 | fi 30 | 31 | source "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" 32 | # Configuration - END 33 | 34 | # Parameters 35 | PROJECT_ID= 36 | DEPLOY_KEY_ID= 37 | 38 | while [[ $# -gt 0 ]] 39 | do 40 | param="$1" 41 | shift 42 | case $param in 43 | -n|--name) 44 | PROJECT_NAME="$1" 45 | shift 46 | ;; 47 | -i|--project-id) 48 | PROJECT_ID="$1" 49 | shift 50 | ;; 51 | -k|--key-id) 52 | DEPLOY_KEY_ID="$1" 53 | shift 54 | ;; 55 | --delete) 56 | set_action 'DELETE' 57 | ;; 58 | --enable) 59 | set_action 'ENABLE' 60 | ;; 61 | *) 62 | # unknown option 63 | echo "Undefine parameter ${param}" 64 | display_usage 65 | ;; 66 | esac 67 | done 68 | 69 | case $ACTION in 70 | DELETE) 71 | ensure_not_empty_deprecated "PROJECT_ID" 72 | ensure_not_empty_deprecated "DEPLOY_KEY_ID" 73 | answer=$(delete_deploy_keys "${PROJECT_ID}" "${DEPLOY_KEY_ID}" ) 74 | ;; 75 | ENABLE) 76 | ensure_not_empty_deprecated "PROJECT_ID" 77 | ensure_not_empty_deprecated "DEPLOY_KEY_ID" 78 | answer=$(enable_deploy_keys "${PROJECT_ID}" "${DEPLOY_KEY_ID}" ) 79 | ;; 80 | *) 81 | # List 82 | ensure_empty_deprecated "DEPLOY_KEY_ID" 83 | answer=$(list_deploy_keys_raw "${PROJECT_ID}" '') 84 | ;; 85 | esac 86 | 87 | echo "${answer}" | jq . 88 | 89 | -------------------------------------------------------------------------------- /glGet.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function display_usage { 4 | echo "Usage: $0 5 | $0 --uri GL_URI 6 | $0 --uri GL_URI --params 'PARAM1=VALUE1&PARAM2=VALUE2 7 | " >&2 8 | exit 100 9 | } 10 | 11 | function main { 12 | local api_url= 13 | local api_params= 14 | 15 | while [[ $# -gt 0 ]]; do 16 | local param="$1" 17 | shift 18 | 19 | case "${param}" in 20 | '--uri'|'--url'|'-u') 21 | api_url="$1" 22 | shift 23 | ;; 24 | '--params'|'-p') 25 | api_params="$1" 26 | shift 27 | ;; 28 | *) 29 | # unknown option 30 | echo "Undefine parameter ${param}" >&2 31 | display_usage 32 | ;; 33 | esac 34 | done 35 | 36 | if [ -z "${api_url}" ] ; then 37 | echo "** Missing parameter --uri" >&2 38 | display_usage 39 | fi 40 | 41 | gitlab_get "${api_url}" "${api_params}" 42 | } 43 | 44 | # Configuration - BEGIN 45 | if [ -z "$GITLAB_BASH_API_PATH" ]; then 46 | GITLAB_BASH_API_PATH=$(dirname "$(realpath "$0")") 47 | fi 48 | 49 | if [ ! -f "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" ]; then 50 | echo "gitlab-bash-api.sh not found! - Please set GITLAB_BASH_API_PATH" >&2 51 | exit 1 52 | fi 53 | 54 | source "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" 55 | # Configuration - END 56 | 57 | # Script start here 58 | 59 | if [ $# -eq 0 ]; then 60 | display_usage 61 | fi 62 | 63 | main "$@" 64 | -------------------------------------------------------------------------------- /glGroups.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function display_usage { 4 | echo "Usage: $0 5 | Get groups configuration 6 | $0 --config --path GROUP_PATH 7 | $0 --config --id GROUP_ID 8 | $0 --config --all 9 | List groups paths 10 | $0 --list-path --path GROUP_PATH 11 | $0 --list-path --id GROUP_ID 12 | $0 --list-path --all 13 | List groups ids 14 | $0 --list-id --path GROUP_PATH 15 | $0 --list-id --id GROUP_ID 16 | $0 --list-id --all 17 | Create group 18 | $0 --create --path GROUP_PATH 19 | [--name GROUP_NAME] \\ 20 | [--description GROUP_DESCRIPTION] \\ 21 | [--lfs_enabled true|false] \\ 22 | [--membership_lock true|false] \\ 23 | [--request_access_enabled true|false] \\ 24 | [--share_with_group_lock true|false]] \\ 25 | [--visibility private|internal|public] 26 | Edit group configuration 27 | $0 --edit --id GROUP_ID --name GROUP_NAME \\ 28 | --path GROUP_PATH \\ 29 | [--description GROUP_DESCRIPTION] \\ 30 | [--visibility private|internal|public] \\ 31 | [--lfs_enabled true|false] \\ 32 | [--request_access_enabled true|false] 33 | Delete a group 34 | $0 --delete --id GROUP_ID 35 | " >&2 36 | exit 100 37 | } 38 | 39 | function create_group_handle_params { 40 | local param_group_path=$1 41 | local param_group_name=$2 42 | local param_group_description=$3 43 | local param_group_lfs_enabled=$4 44 | local param_group_membership_lock=$5 45 | local param_group_request_access_enabled=$6 46 | local param_group_share_with_group_lock=$7 47 | local param_group_visibility=$8 48 | 49 | if [ -z "${param_group_name}" ]; then 50 | param_group_name="${param_group_path}" 51 | fi 52 | if [ -z "${param_group_description}" ]; then 53 | param_group_description="${GITLAB_DEFAULT_GROUP_DESCRIPTION}" 54 | fi 55 | if [ -z "${param_group_lfs_enabled}" ]; then 56 | param_group_lfs_enabled="${GITLAB_DEFAULT_GROUP_LFS_ENABLED}" 57 | fi 58 | if [ -z "${param_group_membership_lock}" ]; then 59 | param_group_membership_lock="${GITLAB_DEFAULT_GROUP_MEMBERSHIP_LOCK}" 60 | fi 61 | if [ -z "${param_group_request_access_enabled}" ]; then 62 | param_group_request_access_enabled="${GITLAB_DEFAULT_GROUP_REQUEST_ACCESS_ENABLED}" 63 | fi 64 | if [ -z "${param_group_share_with_group_lock}" ]; then 65 | param_group_share_with_group_lock="${GITLAB_DEFAULT_GROUP_SHARE_WITH_GROUP_LOCK}" 66 | fi 67 | if [ -z "${param_group_visibility}" ]; then 68 | param_group_visibility="${GITLAB_DEFAULT_GROUP_VISIBILITY}" 69 | fi 70 | 71 | create_group 'path' "${param_group_path}" \ 72 | 'name' "${param_group_name}" \ 73 | 'description' "${param_group_description}" \ 74 | 'lfs_enabled' "${param_group_lfs_enabled}" \ 75 | 'membership_lock' "${param_group_membership_lock}" \ 76 | 'request_access_enabled' "${param_group_request_access_enabled}" \ 77 | 'share_with_group_lock' "${param_group_share_with_group_lock}" \ 78 | 'visibility' "${param_group_visibility}" 79 | } 80 | 81 | function get_group_path_or_id_or_empty { 82 | local p_all_group=$1 83 | local p_group_id=$2 84 | local p_group_path=$3 85 | 86 | local group_path_or_id_or_empty="${p_group_id}" 87 | 88 | if [ -z "${group_path_or_id_or_empty}" ]; then 89 | group_path_or_id_or_empty="${p_group_path}" 90 | fi 91 | 92 | if [ -z "${group_path_or_id_or_empty}" ]; then 93 | if [ ! "${p_all_group}" = true ]; then 94 | echo "** Missing --id, --path or --all" >&2 95 | exit 1 96 | fi 97 | fi 98 | 99 | echo "${group_path_or_id_or_empty}" 100 | } 101 | 102 | function list_groups_paths_handle_params { 103 | local group_path_or_id_or_empty 104 | local jq_filter 105 | 106 | group_path_or_id_or_empty=$(get_group_path_or_id_or_empty "$@") || exit $? 107 | 108 | if [ -z "${group_path_or_id_or_empty}" ]; then 109 | jq_filter='. [] | .path' 110 | else 111 | jq_filter='. | .path' 112 | fi 113 | 114 | local result 115 | local error_message 116 | 117 | result=$(list_groups "${group_path_or_id_or_empty}" '') 118 | error_message=$(getErrorMessage "${result}") 119 | 120 | if [ -z "${error_message}" ]; then 121 | if [ ! "${result}" = 'null' ]; then 122 | echo "${result}" | jq -r "${jq_filter}" 123 | fi 124 | else 125 | echo "* Warning: '${error_message}' while list_groups '${group_path_or_id_or_empty}'" >&2 126 | fi 127 | } 128 | 129 | function list_groups_ids_handle_params { 130 | local group_path_or_id_or_empty 131 | local jq_filter 132 | 133 | group_path_or_id_or_empty=$(get_group_path_or_id_or_empty "$@") 134 | 135 | if [ -z "${group_path_or_id_or_empty}" ]; then 136 | jq_filter='. [] | .id' 137 | else 138 | jq_filter='. | .id' 139 | fi 140 | 141 | local result 142 | local error_message 143 | 144 | result=$(list_groups "${group_path_or_id_or_empty}" '') 145 | error_message=$(getErrorMessage "${result}") 146 | 147 | if [ -z "${error_message}" ]; then 148 | if [ ! "${result}" = 'null' ]; then 149 | echo "${result}" | jq -r "${jq_filter}" 150 | fi 151 | else 152 | echo "* Warning: '${error_message}' while list_groups '${group_path_or_id_or_empty}'" >&2 153 | fi 154 | } 155 | 156 | function show_group_config_handle_params { 157 | local group_path_or_id_or_empty 158 | 159 | group_path_or_id_or_empty=$(get_group_path_or_id_or_empty "$@") || exit 1 160 | 161 | show_group_config "${group_path_or_id_or_empty}" | jq . 162 | } 163 | 164 | function main { 165 | local param= 166 | local param_all_groups=false 167 | local param_group_description= 168 | local param_group_description_define=false 169 | local param_group_id= 170 | local param_group_lfs_enabled= 171 | local param_group_membership_lock= 172 | local param_group_name= 173 | local param_group_path= 174 | local param_group_request_access_enabled= 175 | local param_group_share_with_group_lock= 176 | local param_group_visibility= 177 | local action= 178 | 179 | while [[ $# -gt 0 ]]; do 180 | local param="$1" 181 | shift 182 | 183 | case "${param}" in 184 | -a|--all) 185 | param_all_groups=true 186 | ;; 187 | --config) 188 | ensure_empty_deprecated action 189 | action=showConfigAction 190 | ;; 191 | --create) 192 | ensure_empty_deprecated action 193 | action=createAction 194 | ;; 195 | --delete) 196 | ensure_empty_deprecated action 197 | action=deleteAction 198 | ;; 199 | --description) 200 | param_group_description="$1" 201 | param_group_description_define=true 202 | shift 203 | ;; 204 | --edit) 205 | ensure_empty_deprecated action 206 | action=editAction 207 | ;; 208 | -i|--id) 209 | param_group_id="$1" 210 | shift 211 | ;; 212 | --lfs_enabled) 213 | param_group_lfs_enabled="$1" 214 | shift 215 | 216 | ensure_boolean "${param_group_lfs_enabled}" '--lfs_enabled' 217 | ;; 218 | --list-path) 219 | ensure_empty_deprecated action 220 | action=listPathsAction 221 | ;; 222 | --list-id) 223 | ensure_empty_deprecated action 224 | action=listIdsAction 225 | ;; 226 | --membership_lock) 227 | param_group_membership_lock="$1" 228 | shift 229 | 230 | ensure_boolean "${param_group_membership_lock}" '--membership_lock' 231 | ;; 232 | -n|--name) 233 | param_group_name="$1" 234 | shift 235 | ;; 236 | --path) 237 | param_group_path="$1" 238 | shift 239 | ;; 240 | --request_access_enabled) 241 | param_group_request_access_enabled="$1" 242 | shift 243 | 244 | ensure_boolean "${param_group_request_access_enabled}" '--request_access_enabled' 245 | ;; 246 | --share_with_group_lock) 247 | param_group_share_with_group_lock="$1" 248 | shift 249 | 250 | ensure_boolean "${param_group_share_with_group_lock}" '--share_with_group_lock' 251 | ;; 252 | --visibility) 253 | param_group_visibility="$1" 254 | shift 255 | 256 | case "${param_group_visibility}" in 257 | private|internal|public) 258 | ;; 259 | *) 260 | echo "Illegal value '${param_group_visibility}'. --visibility should be private, internal or public." >&2 261 | display_usage 262 | ;; 263 | esac 264 | ;; 265 | *) 266 | # unknown option 267 | echo "Unknown parameter ${param}" >&2 268 | display_usage 269 | ;; 270 | esac 271 | done 272 | 273 | case "${action}" in 274 | createAction) 275 | ensure_not_empty_deprecated param_group_path 276 | 277 | create_group_handle_params "${param_group_path}" "${param_group_name}" "${param_group_description}" \ 278 | "${param_group_lfs_enabled}" "${param_group_membership_lock}" "${param_group_request_access_enabled}" \ 279 | "${param_group_share_with_group_lock}" "${param_group_visibility}" \ 280 | | jq . 281 | ;; 282 | deleteAction) 283 | ensure_not_empty_deprecated param_group_id 284 | delete_group "${param_group_id}" \ 285 | | jq . 286 | ;; 287 | editAction) 288 | ensure_not_empty_deprecated param_group_id 289 | ensure_not_empty_deprecated param_group_name 290 | ensure_not_empty_deprecated param_group_path 291 | ensure_not_empty_deprecated param_group_visibility 292 | 293 | edit_group "${param_group_id}" "${param_group_name}" "${param_group_path}" \ 294 | "${param_group_description_define}" "${param_group_description}" \ 295 | "${param_group_visibility}" "${param_group_lfs_enabled}" "${param_group_request_access_enabled}" \ 296 | | jq . 297 | ;; 298 | listPathsAction) 299 | list_groups_paths_handle_params "${param_all_groups}" "${param_group_id}" "${param_group_path}" 300 | ;; 301 | listIdsAction) 302 | list_groups_ids_handle_params "${param_all_groups}" "${param_group_id}" "${param_group_path}" 303 | ;; 304 | showConfigAction) 305 | show_group_config_handle_params "${param_all_groups}" "${param_group_id}" "${param_group_path}" 306 | ;; 307 | *) 308 | # unknown option 309 | echo "Missing --config, --list-name, --list-id, --edit or --delete" >&2 310 | echo "Unexpected value for action: '${action}'" >&2 311 | display_usage 312 | ;; 313 | esac 314 | } 315 | 316 | # Configuration - BEGIN 317 | if [ -z "$GITLAB_BASH_API_PATH" ]; then 318 | GITLAB_BASH_API_PATH=$(dirname "$(realpath "$0")") 319 | fi 320 | 321 | if [ ! -f "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" ]; then 322 | echo "gitlab-bash-api.sh not found! - Please set GITLAB_BASH_API_PATH" >&2 323 | exit 1 324 | fi 325 | 326 | source "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" 327 | # Configuration - END 328 | 329 | # Script start here 330 | source "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api-group.sh" 331 | 332 | if [ $# -eq 0 ]; then 333 | display_usage 334 | fi 335 | 336 | main "$@" 337 | -------------------------------------------------------------------------------- /glProjects.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function display_usage { 4 | echo "Usage: $0 5 | Get projects configuration 6 | $0 --config [--compact] --id PROJECT_ID 7 | $0 --config [--compact] --group-path GROUP_PATH 8 | $0 --config [--compact] --all 9 | $0 --config [--compact] --path PROJECT_PATH 10 | List projects paths 11 | $0 --list-path --id PROJECT_ID 12 | $0 --list-path --group-path GROUP_PATH (could return more than one entry) 13 | $0 --list-path --all 14 | $0 --list-path --path PROJECT_PATH (could return more than one entry) 15 | List projects ids 16 | $0 --list-id --id PROJECT_ID 17 | $0 --list-id --group-path GROUP_PATH (could return more than one entry) 18 | $0 --list-id --all 19 | $0 --list-id --path PROJECT_PATH 20 | Create project 21 | $0 --create --group-id GROUP_ID --path PROJECT_PATH \\ 22 | [--project-name PROJECT_NAME] \\ 23 | [--project-description PROJECT_DESCRIPTION] \\ 24 | [--container-registry-enabled true|false] \\ 25 | [--issues-enabled true|false] \\ 26 | [--jobs-enabled true|false] \\ 27 | [--lfs-enabled true|false] \\ 28 | [--merge-requests-enabled true|false] \\ 29 | [--only-allow-merge-if-all-discussions-are-resolved true|false] \\ 30 | [--only-allow-merge-if-pipeline-succeed true|false] \\ 31 | [--printing-merge-request-link-enabled true|false] \\ 32 | [--public-jobs true|false] \\ 33 | [--request-access-enabled true|false] \\ 34 | [--snippets-enabled true|false] \\ 35 | [--visibility private|internal|public] \\ 36 | [--wiki-enabled true|false] 37 | Edit project 38 | $0 --edit --id PROJECT_ID --project-name PROJECT_NAME \\ 39 | [--path PROJECT_PATH] \\ 40 | [--default-branch DEFAULT_BRANCH] 41 | [--project-description PROJECT_DESCRIPTION] \\ 42 | [--container-registry-enabled true|false] \\ 43 | [--issues-enabled true|false] \\ 44 | [--jobs-enabled true|false] \\ 45 | [--lfs-enabled true|false] \\ 46 | [--merge-requests-enabled true|false] \\ 47 | [--only-allow-merge-if-all-discussions-are-resolved true|false] \\ 48 | [--only-allow-merge-if-pipeline-succeed true|false] \\ 49 | [--public-jobs true|false] \\ 50 | [--request-access-enabled true|false] \\ 51 | [--snippets-enabled true|false] \\ 52 | [--visibility private|internal|public] \\ 53 | [--wiki-enabled true|false] 54 | Edit project 55 | $0 --edit --id PROJECT_ID --project-name PROJECT_NAME \\ 56 | [--path PROJECT_PATH] \\ 57 | [--default-branch DEFAULT_BRANCH] 58 | [--project-description PROJECT_DESCRIPTION] \\ 59 | [--issues-enabled true|false] \\ 60 | [--merge-requests-enabled true|false] \\ 61 | [--jobs-enabled true|false] \\ 62 | [--wiki-enabled true|false] \\ 63 | [--snippets-enabled true|false] \\ 64 | [--container-registry-enabled true|false] \\ 65 | [--visibility private|internal|public] \\ 66 | [--public-jobs true|false] \\ 67 | [--only-allow-merge-if-pipeline-succeed true|false] \\ 68 | [--only-allow-merge-if-all-discussions-are-resolved true|false] \\ 69 | [--lfs-enabled true|false] \\ 70 | [--request-access-enabled true|false] 71 | Delete a project 72 | $0 --delete --group-path GROUP_PATH --path PROJECT_PATH 73 | $0 --delete --id PROJECT_ID 74 | " >&2 75 | 76 | exit 100 77 | } 78 | 79 | function create_projects_handle_params { 80 | local group_id=${1} 81 | local project_path=${2} 82 | local project_name=${3} 83 | local project_description=${4} 84 | local p_container_registry_enabled=${5} 85 | local p_issues_enabled=${6} 86 | local p_jobs_enabled=${7} 87 | local p_lfs_enabled=${8} 88 | local p_merge_requests_enabled=${9} 89 | local p_only_allow_merge_if_all_discussions_are_resolved=${10} 90 | local p_only_allow_merge_if_pipeline_succeeds=${11} 91 | local p_printing_merge_request_link_enabled=${12} 92 | local p_public_jobs=${13} 93 | local p_request_access_enabled=${14} 94 | local p_snippets_enabled=${15} 95 | local p_visibility=${16} 96 | local p_wiki_enabled=${17} 97 | 98 | if [ -z "${group_id}" ]; then 99 | echo "* Parameter --group-id is missing" >&2 100 | display_usage 101 | fi 102 | if [ -z "${project_path}" ]; then 103 | echo "* Parameter --path is missing" >&2 104 | display_usage 105 | fi 106 | if [ -z "${p_container_registry_enabled}" ]; then 107 | p_container_registry_enabled="${GITLAB_DEFAULT_PROJECT_CONTAINER_REGISTRY_ENABLED}" 108 | fi 109 | if [ -z "${p_issues_enabled}" ]; then 110 | p_issues_enabled="${GITLAB_DEFAULT_PROJECT_ISSUES_ENABLED}" 111 | fi 112 | if [ -z "${p_jobs_enabled}" ]; then 113 | p_jobs_enabled="${GITLAB_DEFAULT_PROJECT_JOBS_ENABLED}" 114 | fi 115 | if [ -z "${p_lfs_enabled}" ]; then 116 | p_lfs_enabled="${GITLAB_DEFAULT_PROJECT_LFS_ENABLED}" 117 | fi 118 | if [ -z "${p_merge_requests_enabled}" ]; then 119 | p_merge_requests_enabled="${GITLAB_DEFAULT_PROJECT_MERGE_REQUESTS_ENABLED}" 120 | fi 121 | if [ -z "${p_only_allow_merge_if_all_discussions_are_resolved}" ]; then 122 | p_only_allow_merge_if_all_discussions_are_resolved="${GITLAB_DEFAULT_PROJECT_ONLY_ALLOW_MERGE_IF_ALL_DISCUSSIONS_ARE_RESOLVED}" 123 | fi 124 | if [ -z "${p_only_allow_merge_if_pipeline_succeeds}" ]; then 125 | p_only_allow_merge_if_pipeline_succeeds="${GITLAB_DEFAULT_PROJECT_ONLY_ALLOW_MERGE_IF_PIPELINE_SUCCEEDS}" 126 | fi 127 | if [ -z "${p_printing_merge_request_link_enabled}" ]; then 128 | p_printing_merge_request_link_enabled="${GITLAB_DEFAULT_PROJECT_PRINTING_MERGE_REQUEST_LINK_ENABLED}" 129 | fi 130 | if [ -z "${p_public_jobs}" ]; then 131 | p_public_jobs="${GITLAB_DEFAULT_PROJECT_PUBLIC_JOBS}" 132 | fi 133 | if [ -z "${p_request_access_enabled}" ]; then 134 | p_request_access_enabled="${GITLAB_DEFAULT_PROJECT_REQUEST_ACCESS_ENABLED}" 135 | fi 136 | if [ -z "${p_snippets_enabled}" ]; then 137 | p_snippets_enabled="${GITLAB_DEFAULT_PROJECT_SNIPPETS_ENABLED}" 138 | fi 139 | if [ -z "${p_visibility}" ]; then 140 | p_visibility="${GITLAB_DEFAULT_PROJECT_VISIBILITY}" 141 | fi 142 | if [ -z "${p_wiki_enabled}" ]; then 143 | p_wiki_enabled="${GITLAB_DEFAULT_PROJECT_WIKI_ENABLED}" 144 | fi 145 | 146 | ensure_boolean "${p_container_registry_enabled}" 'container_registry_enabled' 147 | ensure_boolean "${p_printing_merge_request_link_enabled}" 'printing_merge_request_link_enabled' 148 | 149 | create_project path "${project_path}" \ 150 | container_registry_enabled "${p_container_registry_enabled}" \ 151 | description "${project_description}" \ 152 | issues_enabled "${p_issues_enabled}" \ 153 | jobs_enabled "${p_jobs_enabled}" \ 154 | lfs_enabled "${p_lfs_enabled}" \ 155 | merge_requests_enabled "${p_merge_requests_enabled}" \ 156 | name "${project_name}" \ 157 | namespace_id "${group_id}" \ 158 | only_allow_merge_if_all_discussions_are_resolved "${p_only_allow_merge_if_all_discussions_are_resolved}" \ 159 | only_allow_merge_if_pipeline_succeeds "${p_only_allow_merge_if_pipeline_succeeds}" \ 160 | printing_merge_request_link_enabled "${p_printing_merge_request_link_enabled}" \ 161 | public_jobs "${p_public_jobs}" \ 162 | request_access_enabled "${p_request_access_enabled}" \ 163 | snippets_enabled "${p_snippets_enabled}" \ 164 | visibility "${p_visibility}" \ 165 | wiki_enabled "${p_wiki_enabled}" 166 | } 167 | 168 | # shellcheck disable=SC2086 169 | function edit_project_handle_params { 170 | local id=${1} 171 | local name=${2} 172 | local path_defined=${3} 173 | local path=${4} 174 | local default_branch_defined=${5} 175 | local default_branch=${6} 176 | local description_defined=${7} 177 | local description=${8} 178 | local issues_enabled=${9} 179 | local merge_requests_enabled=${10} 180 | local jobs_enabled=${11} 181 | local wiki_enabled=${12} 182 | local snippets_enabled=${13} 183 | local container_registry_enabled=${14} 184 | local visibility=${15} 185 | local public_jobs=${16} 186 | local only_allow_merge_if_pipeline_succeeds=${17} 187 | local only_allow_merge_if_all_discussions_are_resolved=${18} 188 | local lfs_enabled=${19} 189 | local request_access_enabled=${20} 190 | #local shared_runners_enabled= 191 | #local resolve_outdated_diff_discussions= 192 | #local import_url= 193 | #local tag_list= 194 | #local avatar= 195 | #local ci_config_path= 196 | 197 | if [ -z "${id}" ]; then 198 | echo '* Parameter --id is mandatory' >&2 199 | display_usage 200 | fi 201 | if [ -z "${name}" ]; then 202 | echo '* Parameter --name is mandatory' >&2 203 | display_usage 204 | fi 205 | 206 | local edit_optional_parameters= 207 | 208 | if [ "${path_defined}" == true ]; then 209 | edit_optional_parameters+="path '${path}' " 210 | fi 211 | if [ "${default_branch_defined}" == true ]; then 212 | edit_optional_parameters+="default_branch '${default_branch}' " 213 | fi 214 | if [ "${description_defined}" == true ]; then 215 | edit_optional_parameters+="description \"${description}\" " 216 | fi 217 | if [ ! -z "${issues_enabled}" ]; then 218 | edit_optional_parameters+="issues_enabled '${issues_enabled}' " 219 | fi 220 | if [ ! -z "${merge_requests_enabled}" ]; then 221 | edit_optional_parameters+="merge_requests_enabled '${merge_requests_enabled}' " 222 | fi 223 | if [ ! -z "${jobs_enabled}" ]; then 224 | edit_optional_parameters+="jobs_enabled '${jobs_enabled}' " 225 | fi 226 | if [ ! -z "${wiki_enabled}" ]; then 227 | edit_optional_parameters+="wiki_enabled '${wiki_enabled}' " 228 | fi 229 | if [ ! -z "${snippets_enabled}" ]; then 230 | edit_optional_parameters+="snippets_enabled '${snippets_enabled}' " 231 | fi 232 | if [ ! -z "${container_registry_enabled}" ]; then 233 | edit_optional_parameters+="container_registry_enabled '${container_registry_enabled}' " 234 | fi 235 | if [ ! -z "${visibility}" ]; then 236 | edit_optional_parameters+="visibility '${visibility}' " 237 | fi 238 | if [ ! -z "${public_jobs}" ]; then 239 | edit_optional_parameters+="public_jobs '${public_jobs}' " 240 | fi 241 | if [ ! -z "${only_allow_merge_if_pipeline_succeeds}" ]; then 242 | edit_optional_parameters+="only_allow_merge_if_pipeline_succeeds '${only_allow_merge_if_pipeline_succeeds}' " 243 | fi 244 | if [ ! -z "${only_allow_merge_if_all_discussions_are_resolved}" ]; then 245 | edit_optional_parameters+="only_allow_merge_if_all_discussions_are_resolved '${only_allow_merge_if_all_discussions_are_resolved}' " 246 | fi 247 | if [ ! -z "${lfs_enabled}" ]; then 248 | edit_optional_parameters+="lfs_enabled '${lfs_enabled}' " 249 | fi 250 | if [ ! -z "${request_access_enabled}" ]; then 251 | edit_optional_parameters+="request_access_enabled '${request_access_enabled}' " 252 | fi 253 | 254 | eval edit_project 'id' "${id}" 'name' "'${name}'" ${edit_optional_parameters} 255 | } 256 | 257 | function show_projects_config_handle_params { 258 | local param_raw_display=$1 259 | local param_all=$2 260 | local param_project_id=$3 261 | local param_group_path=$4 262 | local param_project_path=$5 263 | 264 | if [ ! $# -eq 5 ]; then 265 | echo "* show_projects_config_handle_params: Expecting 5 parameters found $# : '$*'" >&2 266 | exit 1 267 | fi 268 | 269 | ensure_boolean "${param_raw_display}" 'param_raw_display' || exit 1 270 | ensure_boolean "${param_all}" 'param_all' || exit 1 271 | 272 | #DEBUG echo "### show_project_config '$1' - '$2' - '$3' - '$4' - '$5'" >&2 273 | 274 | # handle project id !!!! 275 | local answer 276 | 277 | answer=$(show_project_config "${param_raw_display}" "${param_project_id}") || exit 1 278 | 279 | local jq_filter= 280 | 281 | if [ "${param_raw_display}" = "true" ] ; then 282 | if [ ! -z "${param_group_path}" ]; then 283 | jq_filter="[.[] | select(.namespace.path==\"${param_group_path}\")]" 284 | elif [ ! -z "${param_project_path}" ]; then 285 | jq_filter="[.[] | select(.path==\"${param_project_path}\")]" 286 | elif [ "${param_all}" = "true" ] ; then 287 | jq_filter='.' 288 | elif [ ! -z "${param_project_id}" ] ; then 289 | jq_filter='.' 290 | else 291 | echo "Missing PROJECT_ID, GROUP_PATH, PROJECT_PATH or ALL parameter" >&2 292 | display_usage 293 | fi 294 | else 295 | if [ ! -z "${param_group_path}" ]; then 296 | jq_filter="[.[] | select(.group_path==\"${param_group_path}\")]" 297 | elif [ ! -z "${param_project_path}" ]; then 298 | jq_filter="[.[] | select(.project_path==\"${param_project_path}\")]" 299 | elif [ "${param_all}" = "true" ] ; then 300 | jq_filter='.' 301 | elif [ ! -z "${param_project_id}" ] ; then 302 | jq_filter='.' 303 | else 304 | echo "Missing PROJECT_ID, GROUP_PATH, PROJECT_PATH or ALL parameter" >&2 305 | display_usage 306 | fi 307 | fi 308 | 309 | local result 310 | local size= 311 | 312 | result=$(echo "${answer}" |jq "${jq_filter}" ) || exit 1 313 | 314 | if [ -z "${result}" ]; then 315 | size=0 316 | else 317 | size=$(echo "${result}" |jq '. | length' ) || exit 1 318 | fi 319 | 320 | if [ "${size}" -eq 0 ] ; then 321 | echo "* No project available." >&2 322 | fi 323 | 324 | echo "${result}" 325 | } 326 | 327 | function list_projects_paths_handle_params { 328 | local param_raw_display=$1 329 | local answer 330 | local jq_filter= 331 | 332 | answer=$(show_projects_config_handle_params "$@") 333 | 334 | if [ "${param_raw_display}" = "true" ] ; then 335 | jq_filter='.[] | .path' 336 | else 337 | jq_filter='.[] | .project_path' 338 | fi 339 | 340 | echo "${answer}" | jq -r "${jq_filter}" 341 | } 342 | 343 | function list_projects_ids_handle_params { 344 | local param_raw_display=$1 345 | local answer 346 | local jq_filter= 347 | 348 | answer=$(show_projects_config_handle_params "$@") 349 | 350 | if [ "${param_raw_display}" = "true" ] ; then 351 | jq_filter='.[] | .id' 352 | else 353 | jq_filter='.[] | .project_id' 354 | fi 355 | 356 | echo "${answer}" | jq -r "${jq_filter}" 357 | } 358 | 359 | function delete_project_handle_params { 360 | local param_project_id=$1 361 | local param_group_name=$2 362 | local param_project_name=$3 363 | 364 | local project_id= 365 | 366 | if [ -z "${param_project_id}" ]; then 367 | ensure_not_empty_deprecated 'param_group_name' 368 | ensure_not_empty_deprecated 'param_project_name' 369 | 370 | project_id=$(get_project_id "${param_group_name}" "${param_project_name}") || exit 1 371 | else 372 | project_id=${param_project_id} 373 | fi 374 | 375 | delete_project "${project_id}" 376 | } 377 | 378 | function main { 379 | local param_all=false 380 | local param_group_id= 381 | local param_group_path= 382 | local param_project_id= 383 | local param_project_path_define= 384 | local param_project_path= 385 | local param_raw_display=true 386 | local p_container_registry_enabled= 387 | local p_issues_enabled= 388 | local p_jobs_enabled= 389 | local p_lfs_enabled= 390 | local p_merge_requests_enabled= 391 | local p_only_allow_merge_if_all_discussions_are_resolved= 392 | local p_only_allow_merge_if_pipeline_succeeds= 393 | local p_printing_merge_request_link_enabled= 394 | local p_project_description_define= 395 | local p_project_description= 396 | local p_project_name= 397 | local p_public_jobs= 398 | local p_request_access_enabled= 399 | local p_snippets_enabled= 400 | local p_visibility= 401 | local p_wiki_enabled= 402 | local action= 403 | local p_default_branch= 404 | 405 | while [[ $# -gt 0 ]]; do 406 | local param="$1" 407 | shift 408 | 409 | case "${param}" in 410 | -a|--all) 411 | param_all=true 412 | ;; 413 | --compact) 414 | param_raw_display=false 415 | ;; 416 | --container-registry-enabled) 417 | p_container_registry_enabled="$1" 418 | ensure_boolean "${p_container_registry_enabled}" '--container-registry-enabled' 419 | shift 420 | ;; 421 | --create) 422 | ensure_empty_deprecated action 423 | action=createAction 424 | ;; 425 | --config) 426 | ensure_empty_deprecated action 427 | action=showConfigAction 428 | ;; 429 | --delete) 430 | ensure_empty_deprecated action 431 | action=deleteAction 432 | ;; 433 | --edit) 434 | ensure_empty_deprecated action 435 | action=editAction 436 | ;; 437 | --group-id) 438 | param_group_id="$1" 439 | shift 440 | ;; 441 | -g|--group-path) 442 | param_group_path="$1" 443 | shift 444 | ;; 445 | -i|--id) 446 | param_project_id="$1" 447 | shift 448 | ;; 449 | --issues-enabled) 450 | p_issues_enabled="$1" 451 | ensure_boolean "${p_issues_enabled}" '--issues-enabled' 452 | shift 453 | ;; 454 | --jobs-enabled) 455 | p_jobs_enabled="$1" 456 | ensure_boolean "${p_jobs_enabled}" '--jobs-enabled' 457 | shift 458 | ;; 459 | --lfs-enabled) 460 | p_lfs_enabled="$1" 461 | ensure_boolean "${p_lfs_enabled}" '--lfs-enabled' 462 | shift 463 | ;; 464 | --list-path) 465 | ensure_empty_deprecated action 466 | action=listPathsAction 467 | ;; 468 | --list-id) 469 | ensure_empty_deprecated action 470 | action=listIdsAction 471 | ;; 472 | -p|--path|--project-path) 473 | param_project_path="$1" 474 | param_project_path_define=true 475 | shift 476 | ;; 477 | --merge-requests-enabled) 478 | p_merge_requests_enabled="$1" 479 | ensure_boolean "${p_merge_requests_enabled}" '--merge-requests-enabled' 480 | shift 481 | ;; 482 | --only-allow-merge-if-all-discussions-are-resolved) 483 | p_only_allow_merge_if_all_discussions_are_resolved="$1" 484 | ensure_boolean "${p_only_allow_merge_if_all_discussions_are_resolved}" '--only-allow-merge-if-all-discussions-are-resolved' 485 | shift 486 | ;; 487 | --only-allow-merge-if-pipeline-succeed) 488 | p_only_allow_merge_if_pipeline_succeeds="$1" 489 | ensure_boolean "${p_only_allow_merge_if_pipeline_succeeds}" '--only-allow-merge-if-pipeline-succeed' 490 | shift 491 | ;; 492 | --printing-merge-request-link-enabled) 493 | p_printing_merge_request_link_enabled="$1" 494 | ensure_boolean "${p_printing_merge_request_link_enabled}" '--printing-merge-request-link-enabled' 495 | shift 496 | ;; 497 | --project-description) 498 | p_project_description="$1" 499 | p_project_description_define=true 500 | shift 501 | ;; 502 | --project-name) 503 | p_project_name="$1" 504 | shift 505 | ;; 506 | --public-jobs) 507 | p_public_jobs="$1" 508 | ensure_boolean "${p_public_jobs}" '--public-jobs' 509 | shift 510 | ;; 511 | --request-access-enabled) 512 | p_request_access_enabled="$1" 513 | ensure_boolean "${p_request_access_enabled}" '--request-access-enabled' 514 | shift 515 | ;; 516 | --snippets-enabled) 517 | p_snippets_enabled="$1" 518 | ensure_boolean "${p_snippets_enabled}" '--snippets-enabled' 519 | shift 520 | ;; 521 | --visibility) 522 | p_visibility="$1" 523 | shift 524 | 525 | case "${p_visibility}" in 526 | private|internal|public) 527 | ;; 528 | *) 529 | echo "Illegal value '${p_visibility}'. --visibility should be private, internal or public." >&2 530 | display_usage 531 | ;; 532 | esac 533 | ;; 534 | --wiki-enabled) 535 | p_wiki_enabled="$1" 536 | ensure_boolean "${p_wiki_enabled}" '--wiki-enabled' 537 | shift 538 | ;; 539 | --default-branch) 540 | p_default_branch="$1" 541 | p_default_branch_defined=true 542 | shift 543 | ;; 544 | *) 545 | # unknown option 546 | echo "Unknown parameter ${param}" >&2 547 | action= 548 | display_usage 549 | ;; 550 | esac 551 | done 552 | 553 | case "${action}" in 554 | createAction) 555 | create_projects_handle_params "${param_group_id}" "${param_project_path}" "${p_project_name}" \ 556 | "${p_project_description}" "${p_container_registry_enabled}" "${p_issues_enabled}" \ 557 | "${p_jobs_enabled}" "${p_lfs_enabled}" "${p_merge_requests_enabled}" \ 558 | "${p_only_allow_merge_if_all_discussions_are_resolved}" \ 559 | "${p_only_allow_merge_if_pipeline_succeeds}" \ 560 | "${p_printing_merge_request_link_enabled}" \ 561 | "${p_public_jobs}" "${p_request_access_enabled}" "${p_snippets_enabled}" \ 562 | "${p_visibility}" "${p_wiki_enabled}" \ 563 | | jq . 564 | ;; 565 | deleteAction) 566 | delete_project_handle_params "${param_project_id}" "${param_group_path}" "${param_project_path}" | jq . 567 | ;; 568 | editAction) 569 | edit_project_handle_params "${param_project_id}" "${p_project_name}" \ 570 | "${param_project_path_define}" "${param_project_path}" \ 571 | "${p_default_branch_defined}" "${p_default_branch}" \ 572 | "${p_project_description_define}" "${p_project_description}" \ 573 | "${p_issues_enabled}" \ 574 | "${p_merge_requests_enabled}" \ 575 | "${p_jobs_enabled}" \ 576 | "${p_wiki_enabled}" \ 577 | "${p_snippets_enabled}" \ 578 | "${p_container_registry_enabled}" \ 579 | "${p_visibility}" \ 580 | "${p_public_jobs}" \ 581 | "${p_only_allow_merge_if_pipeline_succeeds}" \ 582 | "${p_only_allow_merge_if_all_discussions_are_resolved}" \ 583 | "${p_lfs_enabled}" \ 584 | "${p_request_access_enabled}" \ 585 | | jq . 586 | ;; 587 | listPathsAction) 588 | list_projects_paths_handle_params "${param_raw_display}" "${param_all}" "${param_project_id}" "${param_group_path}" "${param_project_path}" 589 | ;; 590 | listIdsAction) 591 | list_projects_ids_handle_params "${param_raw_display}" "${param_all}" "${param_project_id}" "${param_group_path}" "${param_project_path}" 592 | ;; 593 | showConfigAction) 594 | show_projects_config_handle_params "${param_raw_display}" "${param_all}" \ 595 | "${param_project_id}" "${param_group_path}" "${param_project_path}" \ 596 | | jq . 597 | ;; 598 | *) 599 | # unknown option 600 | echo "Missing --config, --list-name, --list-id, --edit or --delete * ${action}" >&2 601 | display_usage 602 | ;; 603 | esac 604 | } 605 | 606 | # Configuration - BEGIN 607 | if [ -z "$GITLAB_BASH_API_PATH" ]; then 608 | GITLAB_BASH_API_PATH=$(dirname "$(realpath "$0")") 609 | fi 610 | 611 | if [ ! -f "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" ]; then 612 | echo "gitlab-bash-api.sh not found! - Please set GITLAB_BASH_API_PATH" >&2 613 | exit 1 614 | fi 615 | 616 | source "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" 617 | # Configuration - END 618 | 619 | # Script start here 620 | source "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api-project.sh" 621 | 622 | if [ $# -eq 0 ]; then 623 | display_usage 624 | fi 625 | 626 | main "$@" 627 | -------------------------------------------------------------------------------- /glPut.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function display_usage { 4 | echo "Usage: $0 5 | $0 --uri GL_URI 6 | $0 --uri GL_URI --params 'PARAM1=VALUE1&PARAM2=VALUE2 7 | " >&2 8 | exit 100 9 | } 10 | 11 | function main { 12 | local api_url= 13 | local api_params= 14 | 15 | while [[ $# -gt 0 ]]; do 16 | local param="$1" 17 | shift 18 | 19 | case "${param}" in 20 | '--uri'|'--url'|'-u') 21 | api_url="$1" 22 | shift 23 | ;; 24 | '--params'|'-p') 25 | api_params="$1" 26 | shift 27 | ;; 28 | *) 29 | # unknown option 30 | echo "Undefine parameter ${param}" >&2 31 | display_usage 32 | ;; 33 | esac 34 | done 35 | 36 | if [ -z "${api_url}" ] ; then 37 | echo "** Missing parameter --uri" >&2 38 | display_usage 39 | fi 40 | 41 | gitlab_put "${api_url}" "${api_params}" 42 | } 43 | 44 | # Configuration - BEGIN 45 | if [ -z "$GITLAB_BASH_API_PATH" ]; then 46 | GITLAB_BASH_API_PATH=$(dirname "$(realpath "$0")") 47 | fi 48 | 49 | if [ ! -f "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" ]; then 50 | echo "gitlab-bash-api.sh not found! - Please set GITLAB_BASH_API_PATH" >&2 51 | exit 1 52 | fi 53 | 54 | source "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" 55 | # Configuration - END 56 | 57 | # Script start here 58 | 59 | if [ $# -eq 0 ]; then 60 | display_usage 61 | fi 62 | 63 | main "$@" 64 | -------------------------------------------------------------------------------- /how-to-get-your-gitlab-api-key.md: -------------------------------------------------------------------------------- 1 | # How to get your GitLab API key 2 | 3 | ```bash 4 | #!/bin/bash 5 | 6 | # 7 | # You should at least configure: GITLAB_HOST, GITLAB_PORT, GITLAB_USER and GITLAB_PASSWORD values 8 | # 9 | GITLAB_HOST= 10 | GITLAB_PORT= 11 | GITLAB_USER= 12 | GITLAB_PASSWORD= 13 | 14 | GITLAB_URL_PREFIX="http://${GITLAB_HOST}:${GITLAB_PORT}" 15 | GITLAB_API_VERSION=v3 16 | 17 | #gain a gitlab token 18 | GITLAB__SESSION_URL="${GITLAB_URL_PREFIX}/api/${GITLAB_API_VERSION}/session" 19 | SESSION=$(curl --silent --data "login=${GITLAB_USER}&password=${GITLAB_PASSWORD}" ${GITLAB__SESSION_URL}) || exit 1 20 | 21 | echo "${SESSION}" | jq --raw-output .private_token 22 | ``` 23 | 24 | -------------------------------------------------------------------------------- /listBranches.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Documentation: 4 | # https://docs.gitlab.com/ce/api/projects.html#list-branches 5 | # 6 | 7 | # Configuration - BEGIN 8 | if [ -z "$GITLAB_BASH_API_PATH" ]; then 9 | GITLAB_BASH_API_PATH=$(dirname "$(realpath "$0")") 10 | fi 11 | 12 | if [ ! -f "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" ]; then 13 | echo "gitlab-bash-api.sh not found! - Please set GITLAB_BASH_API_PATH" >&2 14 | exit 1 15 | fi 16 | 17 | source "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" 18 | # Configuration - END 19 | 20 | # Script start here 21 | if [[ $# -lt 1 ]] ; then 22 | echo "Usage: $0 PROJECT_ID" >&2 23 | exit 1 24 | fi 25 | 26 | # Parameters 27 | PROJECT_ID=$1 28 | 29 | answer=$(gitlab_get "projects/${PROJECT_ID}/repository/branches" "${PARAMS}") || exit 1 30 | LIST_BRANCHES=$(echo "${answer}" | jq .) 31 | 32 | echo "${LIST_BRANCHES}" 33 | -------------------------------------------------------------------------------- /listUsers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Documentation: 4 | # https://docs.gitlab.com/ee/api/users.html#users-api 5 | # 6 | # Parameters: 7 | # name (required) - The name of the group 8 | # path (required) - The path of the group 9 | # description (optional) - The group's description 10 | # membership_lock (optional, boolean) - Prevent adding new members to project membership within this group 11 | # share_with_group_lock (optional, boolean) - Prevent sharing a project with another group within this group 12 | # visibility (optional) - The group's visibility. Can be private, internal, or public. 13 | # lfs_enabled (optional) - Enable/disable Large File Storage (LFS) for the projects in this group 14 | # request_access_enabled (optional) - Allow users to request member access. 15 | # parent_id (optional) - The parent group id for creating nested group. 16 | # shared_runners_minutes_limit (optional) - (admin-only) Pipeline minutes quota for this group 17 | # 18 | 19 | # Configuration - BEGIN 20 | if [ -z "$GITLAB_BASH_API_PATH" ]; then 21 | GITLAB_BASH_API_PATH=$(dirname "$(realpath "$0")") 22 | fi 23 | 24 | if [ ! -f "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" ]; then 25 | echo "gitlab-bash-api.sh not found! - Please set GITLAB_BASH_API_PATH" >&2 26 | exit 1 27 | fi 28 | 29 | source "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" 30 | # Configuration - END 31 | 32 | # Script start here 33 | if [ $# -eq 0 ]; then 34 | echo "*** $0 [--all | USER_NAME]" >&2 35 | exit 100 36 | fi 37 | 38 | # Parameters 39 | if [ "$1" = "--all" ]; then 40 | PARAMS= 41 | else 42 | PARAMS="username=$1" 43 | fi 44 | 45 | answer=$(gitlab_get "users" "${PARAMS}") || exit 1 46 | USER_LIST=$(echo "${answer}" | jq .) 47 | 48 | echo "${USER_LIST}" 49 | --------------------------------------------------------------------------------