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
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • 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); });

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • 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