Skip to content

Instantly share code, notes, and snippets.

@wickdninja
Last active May 8, 2017 14:19
Show Gist options
  • Save wickdninja/f2f6544d8cd923cb0cb693e1c4b485d6 to your computer and use it in GitHub Desktop.
Save wickdninja/f2f6544d8cd923cb0cb693e1c4b485d6 to your computer and use it in GitHub Desktop.
Scrape PR page for list of JIRA tickets
/* jshint esversion:6*/
class Scraper {
constructor(keys) {
this.count = 0;
this.output = '\n\n';
this.keys = keys;
}
scrape() {
keys.forEach(key => this.logTickets(key));
}
// removes duplicate entries from array
removeDuplicates(arr) {
let s = new Set(arr);
let it = s.values();
return Array.from(it);
}
logTickets(key) {
var regex = new RegExp(`${key}(.{5})`, 'g', 'i');
// find all JIRA tickets in page
var found = document.body.innerText.match(regex);
var cleaned = this.removeDuplicates(found);
if (cleaned.length === 0) return;
this.count += cleaned.length;
// convert to string
var joined = cleaned.join('\n');
// format for output
this.output += `${joined}\n`;
}
print() {
// print to console
console.log(`${this.output}\n\nCount: ${this.count}\n\n`);
}
}
// JIRA project keys (ignore case not working as well as I had hoped.. probably using it incorrectly ¯\_(ツ)_/¯ )
var keys = ['abp', 'ABP', 'Abp', 'aBp', 'aBP', 'ABp'];
var scaper = new Scraper(keys);
scaper.scrape();
scaper.print();
@wickdninja
Copy link
Author

wickdninja commented May 1, 2017

How To

  • Open a PR whose commits logs contain JIRA ticket references used for smart commits.
  • Open dev tools (F12 or Ctrl + Shift + i)
  • Copy gist to clipboard
  • Paste gist into console
  • Press Enter to execute
  • Copy list of tickets that are printed to the console

NOTE: CHROME ONLY

if you want to save console output to file
right click in console and Save As

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment