Last active
August 3, 2025 03:22
-
-
Save Blumed/5d29a46ee55ca6d57f738ba38f3fdd33 to your computer and use it in GitHub Desktop.
This bookmarklet serves as a template for merge request messages and super detailed slack message for posting your merge request in a slack channel
This file contains hidden or 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
| const bookmarklet = { | |
| name: "gitlab-mr-template-to-slack-message-linter", | |
| version: "1.0.0" | |
| }; | |
| const jiraCompanyName = 'yourcompanynamefoundonjirasubdomian.atlassian.net'; | |
| try { | |
| const mrTemplate = document.getElementById('merge_request_description'); | |
| if(mrTemplate) { | |
| const branchSelector = document.querySelector('.branch-selector code').textContent; | |
| const ticketId = `${branchSelector.split('-')[0].replace(/^(.*\/)/,'')}-${branchSelector.split('-')[1]}`; | |
| mrTemplate.value = `## Summary | |
| - | |
| Jira Ticket: ${/(([a-z])+\-([0-9])+)/.test(ticketId) ? `https://${jiraCompanyName}.atlassian.net/browse/${ticketId.toUpperCase()}` : ''} | |
| Reviewers: | |
| `; | |
| } else { | |
| const mrLink = window.location.href; | |
| const branch = document.querySelector('.author-link.js-user-link + .ref-container').getAttribute("title"); | |
| const branchDestination = document.querySelector('.detail-page-description .ref-container:last-of-type').getAttribute("title"); | |
| const ticket = document.querySelector(`a[href*="https://${jiraCompanyName}.atlassian.net/browse/"]`); | |
| const listItems = [].slice.call(document.querySelectorAll('.description .md ul:not(.task-list) li')); | |
| const descriptionText = [].slice.call(document.querySelectorAll('.description .md p')); | |
| const list = listItems.map(listItem => `> - ${listItem.textContent.replace(',', '')}\n`).join(''); | |
| const reviewers = () => { | |
| const text = descriptionText.map(content => content.textContent); | |
| const content = text.filter(reviewer => reviewer.match('@')); | |
| if (!content.length) { | |
| return 'No Reviewers Found'; | |
| } | |
| return content[0].replace('Reviewers: ', ''); | |
| }; | |
| const squashed = document.querySelector('.js-commits-count').textContent; | |
| const pipline = document.querySelector('.ci-icon-gl-icon-wrapper > svg > use').href.baseVal; | |
| const changes = document.querySelector('[data-action="diffs"] > span').textContent.trim(); | |
| const diff = document.querySelector('[data-action="diffs"]').href; | |
| const repo = document.querySelector('nav .breadcrumb li:nth-child(2) span').textContent; | |
| const pipelineStatus = pipelineString => { | |
| if(pipelineString.includes('status_success')) return ':successful:'; | |
| if(pipelineString.includes('status_warning')) return ':warning:'; | |
| if(pipelineString.includes('status_failed')) return ':failed:'; | |
| if(pipelineString.includes('status_running')) return ':macos-loading-wheel:'; | |
| }; | |
| navigator.clipboard.writeText(`:git: *${repo}* [MR](${mrLink}) *${branch}* _into_ *${branchDestination}* | |
| > *Squashed*: ${squashed === '1' ? ':successful:' : ':failed:'} | |
| > *Pipeline*: ${pipelineStatus(pipline)} | |
| > *Jira Ticket*: ${ticket !== null ? `[link](${ticket})` : ':failed:'} | |
| > *Changes*: ${changes} [diff](${diff}) | |
| > *Reviewers*: ${reviewers()} | |
| ${listItems.length === 0 ? 'No List Items Found' : list}`); | |
| } | |
| console.log(`${bookmarklet.name}: ${bookmarklet.version}`); | |
| } catch(error) { | |
| console.log(`${bookmarklet.name} : ${bookmarklet.version} : ${error}`); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment