Skip to content

Instantly share code, notes, and snippets.

@DavidWells
Last active March 31, 2022 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidWells/7b28376f066f9c99e43fb3ece949653f to your computer and use it in GitHub Desktop.
Save DavidWells/7b28376f066f9c99e43fb3ece949653f to your computer and use it in GitHub Desktop.
Script to automatically grab commits from a PR or a compare view and give you markdown to copy/paste into issues or Slack
/*
1. Go to PR view (e.g. https://github.com/user/repon/pull/123)
or compare URL (https://github.com/user/repon/compare/{PREV_COMMIT_HASH}...{RC})
2. Open up JS dev console
3. Paste in the code below
4. Profit
*/
// Script to automatically pull commits + messages into a list to copy/pastewindow
var words = Array.from(document.querySelectorAll('.TimelineItem .mb-1 a:first-of-type'))
// console.log('words', words)
var links = Array.from(document.querySelectorAll('.TimelineItem .mb-1 a:first-of-type'))
// console.log('links', links)
var urlMessage = ''
var urlMessageMd = ''
var urlMessageSlack = ''
var url = window.location.href
// check if github.com/repo/repo/...compare/hash..master
var isComparePage = url.indexOf('compare') > -1
if (isComparePage) {
urlMessage = `View deploy diff`
urlMessageMd = `[${urlMessage}](${url})`
urlMessageSlack = `${urlMessage} - ${url}`
}
var md = words.reduce((acc, curr, i) => {
const text = curr.innerText
acc+= `- [${text.trim()}](${links[i].href})
`
return acc
}, '')
// Markdown format
console.log('Markdown')
console.log(urlMessageMd)
console.log(md)
console.log('───────────────────────')
var slack = words.reduce((acc, curr, i) => {
const text = curr.innerText
acc+= `- ${text.trim()} ${links[i].href}
`
return acc
}, '')
// slack format
console.log('Slack')
console.log(urlMessageSlack)
console.log(slack)
console.log('───────────────────────')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment