Last active
July 28, 2022 11:55
-
-
Save mu88/07cccfc2df0549c18607c1e560b911b0 to your computer and use it in GitHub Desktop.
Bitbucket - Remove PR identifier from commit message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Bitbucket - Remove PR identifier from commit message title | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description Moves the Pull Request identifier from the Git commit message title into the description | |
// @author mu88 | |
// @match https://<<Bitbucket host>>/**/pull-requests/*/overview | |
// @icon https://<<Bitbucket host>>/s/-848199135/6d8324a/n1cn5w/1.0/_/download/resources/com.atlassian.bitbucket.server.bitbucket-webpack-INTERNAL:favicon/favicon.ico | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
"use strict"; | |
const commitTitleElementSelector = "#commit-message-title"; | |
const commitDescriptionElementSelector = ".css-1rr2v4a"; | |
const regex = /(Pull request #\d+: ){1}.*/s; | |
var mergeButton = document.querySelector(".merge-button"); | |
mergeButton.addEventListener("click", onMergeClicked); | |
function onMergeClicked() { | |
window.setTimeout(isDialogReady, 200); | |
} | |
function isDialogReady() { | |
if (document.querySelector(commitTitleElementSelector)) { | |
modifyCommitMessage(); | |
return; | |
} | |
window.setTimeout(isDialogReady, 200); | |
return; | |
} | |
function modifyCommitMessage() { | |
setNewValues(...createNewValues(...getOriginalValues())); | |
} | |
function getOriginalValues() { | |
var commitTitleElement = document.querySelector(commitTitleElementSelector); | |
var commitDescriptionElement = document.querySelector(commitDescriptionElementSelector); | |
var originalCommitTitle = commitTitleElement.value; | |
var originalCommitDescription = commitDescriptionElement.value; | |
return [originalCommitTitle, originalCommitDescription]; | |
} | |
function createNewValues(originalCommitTitle, originalCommitDescription) { | |
var pullRequestIdentifier = originalCommitTitle.match(regex)[1]; | |
var newCommitTitle = originalCommitTitle.replace(pullRequestIdentifier, ""); | |
var newCommitDescription = pullRequestIdentifier + originalCommitDescription; | |
return [newCommitTitle, newCommitDescription]; | |
} | |
function setNewValues(newCommitTitle, newCommitDescription) { | |
var commitTitleElement = document.querySelector(commitTitleElementSelector); | |
var commitDescriptionElement = document.querySelector(commitDescriptionElementSelector); | |
commitTitleElement.value = newCommitTitle; | |
commitDescriptionElement.value = newCommitDescription; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment