A Gitlab API wrapper that helps to automate common actions on CI jobs

Overview

Gitlab CI client

build and test

This is a Gitlab API wrapper that helps to automate common actions on CI jobs (eg: Open a merge request, Open or close an issue etc)

Basic Usage

docker run \
  -e GITLAB_PRIVATE_TOKEN=<YOUR-ACCESS_TOKEN> \
  -e CI_SERVER_URL=<YOUR-GITLAB-CI_SERVER_URL> \
  sparkfabrik/gitlab-ci-client mergeRequests.all "[null,{\"state\":\"opened\"}]"

The above command will return all opened merge requests.

You can also pass -v, -vv or -vvv to increase output verbosity.

Command format

gitlab-ci-client <RESOURCE>.<METHOD>(required arg: string) "[arg1,arg2,...,argN]" (optional arg: array of arguments as json string)

How it works

The first argument defines which API resource you want to use and which action you want to perform.

Here's a list of all available resources:

  • deployKeys
  • deployments
  • environments
  • groups
  • groupsBoards
  • groupsEpics
  • groupsMilestones
  • issueBoards
  • issueLinks
  • issues
  • issuesStatistics
  • jobs
  • keys
  • mergeRequests
  • milestones
  • namespaces
  • projects
  • repositories
  • repositoryFiles
  • schedules
  • snippets
  • systemHooks
  • tags
  • users
  • version
  • wiki

The second argument is a json string that represents an array or arguments. This array is passed to the API as a query string.

Each resource has its own set of actions and common actions among all resources could have different set of arguments. This work is based on https://github.com/GitLabPHP/Client project and to know all available actions for each resource please refer to available methods in the classes defined here: https://github.com/GitLabPHP/Client/tree/11.8/src/Api

For full list of available resources and methods, please refer to the official documentation.

Gitlab CI pipeline

It is possible to use this client to automate steps in a CI pipeline. The only required action is to create an Access Token for your project and set a CI/CD Variable with the name GITLAB_PRIVATE_TOKEN. The scope required is "api". This will grant access to your repository and all its resources.

Once done you can run as any other script in your gitlab-ci step.

Examples in gitlab-ci pipeline

example-gitlab-ci-job:
  stage: build
  image: ghcr.io/sparkfabrik/gitlab-ci-client
  script:
    - |
        mergeRequests.create "[$CI_PROJECT_ID,\"autobranch/$CI_PIPELINE_ID\",\"develop\",\"AUTO: New merge request from pipeline $CI_PIPELINE_ID\"]"

The above example will create a new merge request on the current project from branch "autobranch/$CI_PIPELINE_ID" (which is supposed to be created by this job before this execution) to branch "develop" and will title it "AUTO: New merge request from pipeline $CI_PIPELINE_ID".

Another example for fetching all opened merge requests:

example-gitlab-ci-job:
  stage: build
  image: ghcr.io/sparkfabrik/gitlab-ci-client
  script:
    - |
    mergeRequests.all '[null,{"state":"opened","iids":[123,456]}]'

The above example will return only opened merge requests for the current project among a subset of given merge request ids (iids).

Note that if you want to pass env variables you have to use double-quotes and, thus, you have to escape the double-quotes of the json string.

Of course these are just simple examples. There are plenty of actions you can automate with this tool. The sky is the limit.

You might also like...
Laravel 8.x package wrapper library for Metatrader 5 Web API

Laravel 8.x package wrapper library for Metatrader 5 Web API

An unofficial wrapper client for lknpd.nalog.ru API

Unofficial MoyNalog API client An unofficial wrapper client for lknpd.nalog.ru API Install Via Composer $ composer require shoman4eg/moy-nalog Usage S

The Official Vultr API PHP Wrapper

WIP - This is not the final API Client. Unstable release use with caution. Vultr API PHP Client. Getting Started Must have a PSR7, PSR17, and PSR18 Co

A PHP Stream wrapper for Amazon S3

S3StreamWrapper A simple stream wrapper for Amazon S3. Example ?php use S3StreamWrapper\S3StreamWrapper; S3StreamWrapper::register(); $options = a

laravel wrapper for dicom images services

laravel wrapper for dicom images services

A Laravel wrapper for thephpleague's Fractal package

laravel-api-response A Laravel wrapper for thephpleague's Fractal package Install Via Composer composer require lykegenes/laravel-api-response Then, a

An asynchronous ClamAV wrapper written in PHP with amphp/socket

amphp-clamav An asynchronous ClamAV wrapper written with amphp/socket Installing composer require pato05/amphp-clamav Examples Ping and scan of a fil

Laravel wrapper for the Facebook Graph PHP 8 SDK

Laravel Facebook Graph SDK Installation Getting started with Laravel Facebook Graph is easy - first, install the package via composer composer require

OVHcloud APIs lightweight PHP wrapper

Lightweight PHP wrapper for OVHcloud APIs - The easiest way to use OVHcloud APIs in your PHP applications - Compatible with PHP 7.4, 8.0, 8.1 - Not affiliated with OVHcloud

Comments
  • Bump guzzlehttp/guzzle from 7.4.3 to 7.4.4

    Bump guzzlehttp/guzzle from 7.4.3 to 7.4.4

    Bumps guzzlehttp/guzzle from 7.4.3 to 7.4.4.

    Release notes

    Sourced from guzzlehttp/guzzle's releases.

    Release 7.4.4

    See change log for changes.

    Changelog

    Sourced from guzzlehttp/guzzle's changelog.

    7.4.4 - 2022-06-09

    • Fix failure to strip Authorization header on HTTP downgrade
    • Fix failure to strip the Cookie header on change in host or HTTP downgrade
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Bump guzzlehttp/guzzle from 7.4.3 to 7.4.5

    Bump guzzlehttp/guzzle from 7.4.3 to 7.4.5

    Bumps guzzlehttp/guzzle from 7.4.3 to 7.4.5.

    Release notes

    Sourced from guzzlehttp/guzzle's releases.

    Release 7.4.5

    See change log for changes.

    Release 7.4.4

    See change log for changes.

    Changelog

    Sourced from guzzlehttp/guzzle's changelog.

    7.4.5 - 2022-06-20

    • Fix change in port should be considered a change in origin
    • Fix CURLOPT_HTTPAUTH option not cleared on change of origin

    7.4.4 - 2022-06-09

    • Fix failure to strip Authorization header on HTTP downgrade
    • Fix failure to strip the Cookie header on change in host or HTTP downgrade
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump guzzlehttp/guzzle from 7.4.2 to 7.4.3

    Bump guzzlehttp/guzzle from 7.4.2 to 7.4.3

    Bumps guzzlehttp/guzzle from 7.4.2 to 7.4.3.

    Release notes

    Sourced from guzzlehttp/guzzle's releases.

    Release 7.4.3

    See change log for changes.

    Changelog

    Sourced from guzzlehttp/guzzle's changelog.

    7.4.3 - 2022-05-25

    • Fix cross-domain cookie leakage
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
Owner
SparkFabrik
SparkFabrik
A PHP implementation of the Unleash protocol aka Feature Flags in GitLab

A PHP implementation of the Unleash protocol aka Feature Flags in GitLab. You may also be interested in the Symfony Bundle for this package. This impl

Unleash 38 Dec 25, 2022
This package is a simple API laravel wrapper for Pokemontcg with a sleek Model design for API routes and authentication.

This package is a simple API laravel wrapper for Pokemontcg with a sleek Model design for API routes and authentication.

Daniel Henze 3 Aug 29, 2022
PHP 5.3+ library which helps you to interact with the DigitalOcean API

DigitalOcean The version 2 of the API will be available soon ! Please visit DigitalOceanV2 and contribute :) This PHP 5.3+ library helps you to intera

Antoine Kirk 156 Jul 30, 2022
A PHP wrapper for Spotify's Web API.

Spotify Web API PHP This is a PHP wrapper for Spotify's Web API. It includes the following: Helper methods for all API endpoints: Information about ar

Jonathan Wilsson 796 Jan 8, 2023
Simple Curl based wrapper for Binance API for PHP scripts

Simple Curl based wrapper for Binance API for PHP scripts Feaures API support for SPOT data/trading FAPI/DAPI support for futures data/trading Curl-on

Mr Crypster 22 May 1, 2022
Google Drive Api Wrapper by PHP

GoogleDrive Api Wrapper usage at first you need to create oauth client on google cloud platform. so go to the your google console dashboard and create

Arash Abedi 2 Mar 24, 2022
An elegant wrapper around Google Vision API

STILL UNDER DEVELOPMENT - DO NOT USE IN PRODUCTION Requires PHP 8.0+ For feedback, please contact me. This package provides an elegant wrapper around

Ahmad Mayahi 24 Nov 20, 2022
Twitch Helix API PHP Wrapper for Laravel

Laravel Twitch PHP Twitch Helix API Wrapper for Laravel 5+ ⚠️ Changes on May 01, 2020 Since May 01, 2020, Twitch requires all requests to contain a va

Roman Zipp 87 Dec 7, 2022
Super-simple, minimum abstraction MailChimp API v3 wrapper, in PHP

MailChimp API Super-simple, minimum abstraction MailChimp API v3 wrapper, in PHP. I hate complex wrappers. This lets you get from the MailChimp API do

Drew McLellan 2k Dec 22, 2022
Google Translator Api Wrapper For Php Developers.

Google Translator Api Wrapper For Php Developers.

Roldex Stark 2 Oct 12, 2022