Last active
October 10, 2024 03:15
-
-
Save lamngockhuong/8c7c2d73ddbefc3297232cde1d69e048 to your computer and use it in GitHub Desktop.
Auto Select Merge Type for GitHub Pull-Request
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 Auto Select Merge Type for GitHub PR | |
// @namespace https://gist.github.com/search?q=user%3Alamngockhuong+filename%3Auserscript+language%3Ajs&ref=searchresults | |
// @version 0.7 | |
// @description Automatically selects merge type based on target branch for GitHub PRs | |
// @icon64 data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAAXNSR0IArs4c6QAAD3VJREFUeF7VWwlwlFWe/70vFzkgJIQg35c0kXNlSllELrlmpsRVyiqMHAXWOu6MirI4HngMusiMyjVlFBhWQXSgGGfd4giLU86wqDUFKETEUDgKu8iZ4+tIEnKQgxydfuvvdX9NJ+nufF+n2XX/VV2B7nf+3v9+/ydwnemsrucmCDFZAmM0KW+SQB6EGCSk7A8gyT99K4SohZSXhBAXJfDfGnACQFGOaZZfzyWKWA8uAVE6ePAUTdPmSilnQYgRvZzjDIA/Syl3u9zuIwKQvRyvU/eYAVDicmXA41kkhHgEwDBrFpGcjKTx45F4yy2IHzZMfeIGDoSWlgaRlqaaycZGeBsb0VFVBc/Zs/CcO4e2r79G67FjkFevBhYsgLNeKd9BfPw7Q0pLa2MBRK8BKMvJyYTX+7wElkAItSNtwACk3HsvUmbNQuLYsRCJiVGtVba1oe34cTTv24fmvXvhvXzZGqcRwEYhREFueXlNVIP7O0UNgAS0El3/Z02IlwFkcrykiRPR97HH0OcnP4GIj+/Nurr1lR4PWv76VzRs3ozWL76wfq+BlCty3e5NAvBGM2FUAJi6PqpDiO0AJqqNT5qE9OeeUwCEotbWVrS0tIB/29ra0NHRoT5S+sRZCIG4uDj1SUxMRFJSEvr06aP+hhzv889R/9praD16VP3sBT6PBx7MMc1vnYL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79oa3tEE2IRgOHW74Lv/7o+nc3Ohpaa2vnpbFMTOiorrz2d/dvf0Prll77s7TU6w6ez/fr02ZJ5/nxMylBiBoC1RqbX3Lo+uUPKuULTZknA2VVuF2SZvRVe7581TdttmObnP9jH0+HYrywnxxBSTvYCfy8BpqHzvrcigwSQ4RVCva0TUvKYa79/+HhJAheF1/tfUtO+Epp2xFVW5o6Gte32+R+NPOSY8kvOYwAAAABJRU5ErkJggg== | |
// @source https://gist.github.com/lamngockhuong/8c7c2d73ddbefc3297232cde1d69e048 | |
// @updateURL https://gist.githubusercontent.com/lamngockhuong/8c7c2d73ddbefc3297232cde1d69e048/raw/auto-select-merge-type-for-github-pr.userscript.js | |
// @downloadURL https://gist.githubusercontent.com/lamngockhuong/8c7c2d73ddbefc3297232cde1d69e048/raw/auto-select-merge-type-for-github-pr.userscript.js | |
// @author Lam Ngoc Khuong | |
// @match https://github.com/*/pull/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const releaseBranches = ['main', 'master'] | |
function selectMergeOption() { | |
const targetBranchElement = document.querySelector('span.css-truncate-target'); | |
if (!targetBranchElement) { | |
console.log("<<AutoSelectMergeType>> π Target branch element not found yet!"); | |
return; | |
} | |
const targetBranch = targetBranchElement.textContent.trim(); | |
console.log("<<AutoSelectMergeType>> π Target branch detected: " + targetBranch); | |
// Locate the merge type buttons | |
const mergeButton = document.querySelector('button.merge-box-button.btn-group-merge'); | |
const squashButton = document.querySelector('button.merge-box-button.btn-group-squash'); | |
// Locate the merge dropdown button | |
const dropdownButton = document.querySelector('.select-menu-button.js-merge-method-menu-button'); | |
if (!dropdownButton) { | |
console.log("<<AutoSelectMergeType>> π Merge options dropdown not found!"); | |
return; | |
} | |
// Open the dropdown menu | |
dropdownButton.click(); | |
// Wait for the dropdown to open, then select the appropriate merge option | |
setTimeout(() => { | |
let mergeOption; | |
// Logic to select merge type | |
if (releaseBranches.includes(targetBranch)) { | |
mergeOption = document.querySelector('.select-menu-item.js-merge-box-button-merge'); | |
console.log("<<AutoSelectMergeType>> π Selecting regular merge for branch: " + targetBranch); | |
} else { | |
mergeOption = document.querySelector('.select-menu-item.js-merge-box-button-squash'); | |
console.log("<<AutoSelectMergeType>> π Selecting squash merge for branch: " + targetBranch); | |
} | |
if (mergeOption) { | |
mergeOption.click(); | |
dropdownButton.blur(); | |
} else { | |
console.log("<<AutoSelectMergeType>> π Merge option not found!"); | |
} | |
}, 500); // Delay to ensure the dropdown menu is fully loaded | |
} | |
window.addEventListener('load', selectMergeOption); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment