Last active
December 6, 2021 22:35
-
-
Save pencil/51460c59d4c21e10e2d33f1a7208db04 to your computer and use it in GitHub Desktop.
GitHub: Set merge message to PR title and description
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 GitHub: Set merge message to PR title and description | |
// @namespace https://github.com/pencil | |
// @version 0.6 | |
// @description Set the default GitHub merge title and description to the one of the PR itself. | |
// @author Nils Caspar | |
// @match https://github.com/* | |
// @icon https://github.githubassets.com/favicons/favicon.png | |
// @grant none | |
// @downloadURL https://gist.githubusercontent.com/pencil/51460c59d4c21e10e2d33f1a7208db04/raw/script.js | |
// @updateURL https://gist.githubusercontent.com/pencil/51460c59d4c21e10e2d33f1a7208db04/raw/script.js | |
// @homepageURL https://greasyfork.org/en/scripts/426735-github-set-merge-message-to-pr-title-and-description | |
// @supportURL https://greasyfork.org/en/scripts/426735-github-set-merge-message-to-pr-title-and-description/feedback | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const $ = (str, el) => (el || document).querySelector(str), | |
$$ = (str, el) => [...(el || document).querySelectorAll(str)]; | |
const githubApp = $('.application-main'); | |
githubApp.addEventListener('click', (event) => { | |
const target = event.target; | |
if(target.getAttribute('data-details-container') != '.js-merge-pr') { | |
return; | |
} | |
console.info('updating merge message and title...'); | |
const mergeTitleField = $('#merge_title_field'), | |
mergeDescriptionField = $('#merge_message_field'), | |
prTitleContainer = $('.gh-header-title .js-issue-title'), | |
prNumberContainer = $('.gh-header-title .color-fg-muted'), | |
prDescriptionContainer = $('form.js-comment-update textarea'); | |
if(!prNumberContainer || !prNumberContainer.innerText) { | |
console.info('could not find PR number'); | |
return; | |
} | |
if(!prTitleContainer || !prTitleContainer.innerText) { | |
console.info('could not find PR title'); | |
return; | |
} | |
if(!mergeTitleField) { | |
console.info('could not find merge title'); | |
return; | |
} | |
mergeTitleField.value = prTitleContainer.innerText.trim() + ' (' + prNumberContainer.innerText.trim() + ')'; | |
if(!prDescriptionContainer || !prDescriptionContainer.innerText) { | |
console.info('could not find PR description'); | |
return; | |
} | |
if(!mergeDescriptionField) { | |
console.info('could not find merge description'); | |
return; | |
} | |
mergeDescriptionField.value = prDescriptionContainer.value; | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment