Skip to content

Instantly share code, notes, and snippets.

@drocco007
Last active April 16, 2016 08:21
Show Gist options
  • Save drocco007/e40331374835e0ab1f3a to your computer and use it in GitHub Desktop.
Save drocco007/e40331374835e0ab1f3a to your computer and use it in GitHub Desktop.
Using Jupyter and the bash kernel to explore extracting JIRA issues from git
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Extracting JIRA issues from git"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"cd ~/source/brightlink/brighttrac"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[?1h\u001b=\r",
"bdf155c\u001b[m\r\n",
"\r",
"\u001b[K\u001b[?1l\u001b>"
]
}
],
"source": [
"git log -n 1 --pretty=\"%h\""
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[?1h\u001b=\r",
"1425060432:bdf155c\u001b[m\r\n",
"\r",
"\u001b[K\u001b[?1l\u001b>"
]
}
],
"source": [
"git log -n 1 --pretty=\"%at:%h\""
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[?1h\u001b=\r",
"1425060432:bdf155c upgrade chosen jquery plugin to version 1.3.0 and update css \u001b[m \bfile for bootstrap 3 NCIDQ-188\u001b[m\r\n",
"\u001b[m\r\n",
"\r",
"\u001b[K\u001b[?1l\u001b>"
]
}
],
"source": [
"git log -n 1 --pretty=\"%at:%h %s %b\""
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"rev='1425060432:bdf155c upgrade chosen jquery plugin to version 1.3.0 and update css file for bootstrap 3 NCIDQ-188 '"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1425060432:bdf155c upgrade chosen jquery plugin to version 1.3.0 and update css file for bootstrap 3 NCIDQ-188 "
]
}
],
"source": [
"printf \"$rev\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Pull out the timestamp & revision"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1425060432:bdf155c"
]
}
],
"source": [
"stamp=($rev)\n",
"printf \"$stamp\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Extract the JIRA issue number from the message"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"NCIDQ-188"
]
}
],
"source": [
"msg=$(echo $rev | grep -o -E '\\b([A-Z]+)-[0-9]+\\b')\n",
"printf \"$msg\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Commit with multiple JIRA issues"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"rev='1424883066:ffb594f ability for candidates to remove CEU items and remove pre-audit functionality NASMBT-201 refactor ce.js and add namespace BT.Portal.ce NASMBT-201 refactor core ce.js NASMBT-201 '"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1424883066:ffb594f ability for candidates to remove CEU items and remove pre-audit functionality NASMBT-201 refactor ce.js and add namespace BT.Portal.ce NASMBT-201 refactor core ce.js NASMBT-201 "
]
}
],
"source": [
"printf \"$rev\""
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1424883066:ffb594f"
]
}
],
"source": [
"stamp=($rev)\n",
"printf \"$stamp\""
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"NASMBT-201\r\n",
"NASMBT-201\r\n",
"NASMBT-201"
]
}
],
"source": [
"msg=$(echo $rev | grep -o -E '\\b([A-Z]+)-[0-9]+\\b')\n",
"printf \"$msg\""
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"NASMBT-201"
]
}
],
"source": [
"msg=$(echo $rev | grep -o -E '\\b([A-Z]+)-[0-9]+\\b' | sort | uniq)\n",
"printf \"$msg\""
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1424883066:ffb594f NASMBT-201\r\n"
]
}
],
"source": [
"echo \"$stamp\" \"$msg\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Remove newlines so each log message is contained on a single line"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1425060432:bdf155c upgrade chosen jquery plugin to version 1.3.0 and update css file for bootstrap 3 NCIDQ-188 \r\n",
"1424883066:ffb594f ability for candidates to remove CEU items and remove pre-audit functionality NASMBT-201 refactor ce.js and add namespace BT.Portal.ce NASMBT-201 refactor core ce.js NASMBT-201 \r\n",
"1424813663:2c23e27 ability for candidates to remove CEU items and remove pre-audit functionality NASMBT-201 \r\n",
"1424879275:d2d7070 Exam type selection button too small for text NDEBUSBT-37 \r\n",
"1424889229:b9741d6 Show disabled nav links with correct (muted) font coloring \r\n",
"1424711263:b20f72a create custom profile link NASMBT-202 \r\n",
"1424705463:0f04a30 Correcting missed/duplicated schema update. Removing duplicate 4.066 \r\n",
"1424705161:7ac937c Correcting missed/duplicated schema update. Moving 4.066->4.070 \r\n",
"1424468018:77d8bb4 fix spacing NASMBT-162 \r\n",
"1423843427:8321f94 Added audit percentages when renewing during Reinstatement Window NASMBT-162 updated audit percentages for reinstatement window NASMBT-162 update audit percentages for reinstatement windows NASMBT-162 \r\n"
]
}
],
"source": [
"cd ~/source/brightlink/brighttrac\n",
"logs=$(git log -n 10 --pretty=\"%at:%h %s %b\" -z | tr -s '\\n' ' ' | tr '\\0' '\\n')\n",
"\n",
"echo \"$logs\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### For each commit message, print out the timestamp, SHA1, and JIRA ticket number(s), skipping messages that do not have any."
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1425060432:bdf155c NCIDQ-188 \r\n",
"1424883066:ffb594f NASMBT-201 \r\n",
"1424813663:2c23e27 NASMBT-201 \r\n",
"1424879275:d2d7070 NDEBUSBT-37 \r\n",
"1424711263:b20f72a NASMBT-202 \r\n",
"1424468018:77d8bb4 NASMBT-162 \r\n",
"1423843427:8321f94 NASMBT-162 \r\n",
"1424461177:34634e0 NASMBT-173 \r\n",
"1424446880:de4accc NASMBT-191 \r\n",
"1424378821:c771180 NASMBT-195 \r\n",
"1424355204:9e1f0ad NASMBT-189 \r\n",
"1424359490:7aa0415 NHABT-11640 \r\n",
"1423868185:b60e741 NHABT-11640 \r\n",
"1423868934:c7643ba NASMBT-148 \r\n",
"1423858158:6dcec01 NASMBT-165 \r\n",
"1423769714:1919979 NASMBT-135 \r\n",
"1423682840:1223d47 ENVIRO-274 \r\n",
"1423756981:6847485 NASMBT-163 \r\n",
"1423674997:30cc3c0 NHABT-11647 \r\n",
"1423672288:7c3bc3e COREBT-11266 \r\n",
"1423671465:12fb61a COREBT-11266 \r\n",
"1423522355:2c2f06d NASMBT-150 \r\n",
"1423498539:74e3f9e NASMBT-149 \r\n",
"1423251886:0a16cd3 NASMBT-157 \r\n",
"1423157625:d45d0f5 NASMBT-192 \r\n",
"1423151841:102219e NASMBT-185 \r\n",
"1423086848:d12da17 NASMBT-183 \r\n",
"1423063573:4ae0ca8 NASMBT-183 \r\n",
"1423000559:f388b11 NASMBT-182 \r\n",
"1423000118:3006424 NASMBT-182 \r\n",
"1422996673:f0d28a9 NASMBT-182 \r\n",
"1422990445:68e49f6 NASMBT-182 \r\n",
"1422050320:1a216fd NASMBT-74 \r\n",
"1422454001:52488a5 ENVIRO-269 \r\n",
"1421959606:de7e2a0 COREBT-11262 \r\n",
"1421945995:1b364cb NASMBT-143 \r\n",
"1421858662:ac7760f COREBT-11244 \r\n",
"1421854422:5d4383d COREBT-11245 \r\n",
"1421437498:b720156 NHABT-11547 \r\n",
"1421425593:49382eb NASMBT-143 \r\n",
"1420957380:4f2fbab NASMBT-107 \r\n",
"1420690996:35cedb2 NASMBT-140 \r\n",
"1420689265:97cb454 NASMBT-139 \r\n",
"1420657194:acdb5f0 NASMBT-138 \r\n",
"1420650383:9b671f5 NASMBT-130 \r\n",
"1420039141:0d7b945 NCIDQ-114 \r\n",
"1419977963:c2288f7 NCIDQ-90 \r\n",
"1419974104:154a963 NCIDQ-167 \r\n",
"1419965893:c6a0748 NCIDQ-175 \r\n",
"1419869688:aa68aa1 NCIDQ-38 \r\n",
"1419360732:6ae6bf5 NCIDQ-38 \r\n",
"1419360729:0174cc6 NCIDQ-38 \r\n",
"1418956792:ac88fc5 NCIDQ-38 \r\n",
"1418956789:5c4a075 NCIDQ-38 \r\n",
"1418922927:70fe20e NCIDQ-156 \r\n",
"1418756506:08584af NCIDQ-164 \r\n",
"1418418885:d3eceab NCIDQ-118 \r\n",
"1418315846:5ee4ba1 NCIDQ-141 \r\n",
"1418312382:53b95f6 NHABT-11546 \r\n",
"1418311101:09c078f NHABT-11540 \r\n",
"1418230345:1def698 NHABT-11557 \r\n",
"1418222473:4467b06 NHABT-11559 \r\n",
"1418221819:e0b8877 NHABT-11558 \r\n",
"1418162326:6323d78 NCIDQ-97 \r\n",
"1418162322:a545bf0 NCIDQ-97 \r\n",
"1418160757:2a1af9b NHABT-11550 \r\n",
"1418135846:15e3ef1 NHABT-11543 \r\n",
"1418063607:e438567 NCIDQ-139 \r\n",
"1418060104:e262387 NCIDQ-138 \r\n",
"1418055804:6fa6731 NCIDQ-135 \r\n",
"1418049422:c66fc22 NCIDQ-134 \r\n",
"1417814024:56197c8 NCIDQ-129 \r\n",
"1417813048:ddddbb7 NCIDQ-131 \r\n",
"1417812487:0756e15 NCIDQ-127 \r\n",
"1417810906:7657211 NCIDQ-130 \r\n",
"1417807268:9a7280a NHABT-11544 \r\n",
"1417804894:922914c NHABT-11536 \r\n",
"1417715952:ab6205b NHABT-11552 \r\n",
"1417619319:9d98242 NCIDQ-113 \r\n",
"1417556792:0064dd5 NCIDQ-40 \r\n",
"1417539691:3d6f1cc COREBT-11254 \r\n",
"1417462456:998e31f NCIDQ-107 \r\n",
"1417448821:bf56506 NCIDQ-97 \r\n",
"1417008731:97891b7 NASMBT-121 \r\n",
"1417008587:000a97e NASMBT-121 \r\n",
"1416938025:d25584b NCIDQ-59 NCIDQ-61 NCIDQ-63 \r\n",
"1416935873:6941584 NASMBT-125 \r\n",
"1416932486:a33f8cf NASMBT-115 \r\n",
"1416932464:50e65e3 COREBT-11254 \r\n",
"1416932461:a8f06a3 NCIDQ-69 \r\n",
"1416927905:7229994 COREBT-11254 \r\n",
"1416683299:fdd016d COREBT-11255 \r\n",
"1416607691:0036c2d COREBT-11254 \r\n",
"1416514421:1115e9e NASMBT-125 \r\n",
"1416513372:efcdf39 NASMBT-125 \r\n",
"1416499753:c33801d COREBT-11255 \r\n"
]
}
],
"source": [
"cd ~/source/brightlink/brighttrac\n",
"# LOGS=\"git log --pretty=\\\"%at:%h %s %b\\\" -z | tr -s '\\n' ' ' | tr '\\0' '\\n'\"\n",
"\n",
"git log -n 150 --pretty=\"%at:%h %s %b\" -z | tr -s '\\n' ' ' | tr '\\0' '\\n' | while read log;\n",
"do\n",
" stamp=($log)\n",
" msg=$(echo $log | grep -o -E '\\b([A-Z]+)-[0-9]+\\b' | sort | uniq | tr -s '\\n' ' ')\n",
" \n",
" if [ -n \"$msg\" ]\n",
" then\n",
" echo \"$stamp\" \"$msg\"\n",
" fi\n",
"done"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Bash",
"language": "bash",
"name": "bash"
},
"language_info": {
"codemirror_mode": "shell",
"file_extension": ".sh",
"mimetype": "text/x-sh",
"name": "bash"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment