Skip to content

Instantly share code, notes, and snippets.

@windbridges
Created November 13, 2023 03:35
Show Gist options
  • Save windbridges/62ee28c8932031b37d05c0c0231ab785 to your computer and use it in GitHub Desktop.
Save windbridges/62ee28c8932031b37d05c0c0231ab785 to your computer and use it in GitHub Desktop.
Tampermonkey userscript to fix title for new brach from merge request in GitLab
// ==UserScript==
// @name Fix title for new brach from merge request
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Adds small button to insert correct branch name
// @author Me
// @match https://gitlab.com/*/issues/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=gitlab.com
// ==/UserScript==
(function() {
'use strict';
const btn = document.createElement('button')
btn.className = 'gl-button btn btn-md'
btn.innerText = 'Fix'
btn.style.marginLeft = '10px'
btn.addEventListener('click', function() {
const issueId = document.body.getAttribute('data-page-type-id')
const issueTitle = document.querySelector("h1[data-testid=issue-title]").innerText
const inputName = document.getElementById('new-branch-name')
inputName.value = `${issueId}-${issueTitle.replaceAll(' ', '-')}`
inputName.dispatchEvent(new KeyboardEvent('keyup', {shiftKey: true}));
})
const appendAfterEl = document.querySelector('#create-merge-request-dropdown button[data-action=create-mr]')
appendAfterEl.after(btn)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment