Last active
March 28, 2018 09:01
-
-
Save akinov/0e7e8ba014bb0b72ef90213b784de715 to your computer and use it in GitHub Desktop.
Add issue template link
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 Add New Issue Template Link | |
// @namespace https://github.com/akinov | |
// @version 0.3 | |
// @description New Issue Templateを簡単に | |
// @author akinov | |
// @match https://github.com/*/issues* | |
// @grant none | |
/* load jQuery */ | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const tmplates = [ | |
{ | |
title: '機能追加', | |
queries: { | |
title: '◯◯が◯◯できる', | |
body: `## 背景 | |
## 何がしたいか (要件) | |
## TODO (仕様) | |
` | |
} | |
}, | |
{ | |
title: '子タスク', | |
queries: { | |
title: '(#)', | |
body: `## 親タスク | |
# | |
## TODO`, | |
labels: 'ready,子タスク' | |
} | |
}, | |
{ | |
title: 'バグ', | |
queries: { | |
title: '', | |
body: `## 現象 | |
## 発見された環境 | |
## 再現手順 | |
1. ログインする | |
2. ... | |
## 期待動作 | |
`, | |
labels: 'ready,バグ' | |
} | |
}, | |
{ | |
title: 'リリース', | |
queries: { | |
title: 'release/', | |
body: `タスク | |
--- | |
- [ ] リリースノート作成 | |
- [ ] テストケース見直し | |
- [ ] テスト | |
- [ ] chrome | |
- [ ] IE | |
- [ ] バグ修正 | |
- [ ] さわりタイム | |
- [ ] リリース | |
- [ ] リリース後タスク | |
- [ ] リリースノート発行 | |
- [ ] 次回のリリースイシュー作成 | |
リリース後タスク | |
------- | |
準備中に出てきたバグ | |
----------------- | |
機能一覧 | |
--------- | |
`, | |
labels: 'リリース' | |
} | |
}, | |
]; | |
const $newIssueBtn = $('a[data-hotkey=c]').wrap('<div class="dropdown float-right" />').wrap('<details class="dropdown-details details-reset" />').wrap('<summary />'); | |
const $details = $newIssueBtn.closest('details'); | |
const details = $details[0]; | |
const href = $newIssueBtn.attr('href'); | |
let $dropDownMenu = $('<ul class="dropdown-menu dropdown-menu-sw" />'); | |
// リンクリセット | |
$newIssueBtn.attr('href', '#').on('click', function() { | |
console.log(details); | |
if (details.hasAttribute('open')) { | |
details.removeAttribute('open'); | |
} else { | |
details.setAttribute('open', ''); | |
} | |
}); | |
$dropDownMenu.append(`<a class="dropdown-item" href="${href}">New Issue</a>`); | |
tmplates.forEach(function(template){ | |
$dropDownMenu.append(`<a class="dropdown-item" href="${href}?${buildQueryString(template.queries)}">${template.title}</a>`); | |
}); | |
$details.append($dropDownMenu); | |
function buildQueryString(obj) { | |
var query = "", | |
key, val; | |
for (key in obj) { | |
if (!obj.hasOwnProperty(key)) { | |
continue; | |
} | |
val = obj[key]; | |
query += (query === "") ? "" : "&"; | |
query += fixedEncodeURIComponent(key) + "="; | |
if (val != null) { | |
query += fixedEncodeURIComponent(val); | |
} | |
} | |
return query; | |
} | |
function fixedEncodeURIComponent(str) { | |
return encodeURIComponent(str).replace(/[!'()]/g, escape).replace(/\*/g, "%2A"); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment