How to autorebase MRs in GitLab CI

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • SonarQube - Static code analysis for 29 languages.
  • OPS - Build and Run Open Source Unikernels
  • Scout APM - Less time debugging, more time building
  • node-fetch

    A light-weight module that brings the Fetch API to Node.js

    js node-fetch, node implementation of fetch API from the browser.

  • v4

    #!/usr/bin/env node const fetch = require("node-fetch"); const projectId = process.argv[2] ? process.argv[2] : process.env.CI_PROJECT_ID, apiToken = process.argv[3] ? process.argv[3] : process.env.API_TOKEN, apiV4Url = process.env.CI_API_V4_URL ? process.env.CI_API_V4_URL : "https://gitlab.com/api/v4"; function callApi(command, method = "GET") { console.log("query", apiV4Url + "/projects/" + projectId + command); return fetch(apiV4Url + "/projects/" + projectId + command, { method, headers: { "PRIVATE-TOKEN": apiToken }, }); } callApi("/merge_requests?state=opened") .then((response) => response.json()) .then((response) => { const iids = response.map((mr) => mr.iid); return Promise.all( iids.map((iid) => { return callApi(`/merge_requests/${iid}/rebase`, "PUT") .then((response) => response.json()) .then((response) => { response.iid = iid; return response; }) .catch(console.error); }) ); }) .then((resultSummary) => { console.log(resultSummary); }) .catch((error) => { console.error(error); });

  • SonarQube

    Static code analysis for 29 languages.. Your projects are multi-language. So is SonarQube analysis. Find Bugs, Vulnerabilities, Security Hotspots, and Code Smells so you can release quality code every time. Get started analyzing your projects today for free.

  • profile

    For this script to run, we have to create an API token. Here you can create personal access token:

  • In the case of my repo, the ULR is https://gitlab.com/how-to.dev/autorebase-merge-requests/-/settings/ci_cd.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts