This bookmark run a javascript to apply a simple template at textbox in Github!
If you need use to Gitlab or Bitbucket you need change the css selector!
Motivation: I don't recommend use this if you own the repository because you could create the template directly on Github.
-
Create a new book mark. To this example i will use chrome.
- Access
chrome://bookmarks/
- Right click and click on
Add new bookmark
- Choose a good name i recommend
Pull request template
- Access
If you need create to other browser you can read: firefox, edge
- To change the textbox use this function or if you want a complex template you can create ownself function:
function() {
document.querySelector("#pull_request_body").value = "# π Description";
}
- To use it you need use a snnipet to allow execute Javascript at URL
javascript:(YOUR FUNCTION CODE HERE)();
Example:
javascript:(function() { alert('OlΓ‘') })();
If you want use my template you can copy here:
(function(){const[url]=location.href.split('?');const[,branch]=url.split(location.href.includes('...')?'...':'compare/');const[,unformatedID]=branch.split('/');const id=(unformatedID??'').toUpperCase();const commits = document.querySelectorAll('li.js-commits-list-item > .js-details-container > .Details-content--hidden > pre');const changes = new Set();for (let i = 0; i < commits.length;i++) {const[,change]=commits?.item(i)?.textContent?.split('Changes to be committed:\n\t')??[];if (change)changes.add(...change.split('\n\t'));}document.querySelector('#pull_request_body').value = ['# π Description','','<DESCRICAO AQUI>','','## π Evidence that this works','','<UPLOAD IMAGES>','','## π§ͺ How to validate','','Run the application locally:','','- [ ] Should something','','','## π·οΈ Related tasks','','- '+id,'','','## π Pull request related','','- #000','','','### ποΈ Changes','','On branch:','','> **' + branch + '**','','','Changes to be committed:','','> '+[...changes].sort().join('\n')].join('\n')})()
This function works getting all file changes and the branch (should be feat/ID/name
, or anything/ID/name
) name to complete task id as can you see below:
function() {
const[url] = location.href.split('?');
const[,branch] = url.split(location.href.includes('...') ? '...' : 'compare/');
const[,unformatedID] = branch.split('/');
const id = (unformatedID ?? '').toUpperCase();
const commits = document.querySelectorAll('li.js-commits-list-item > .js-details-container > .Details-content--hidden > pre');
const changes = new Set();
for (let i = 0; i < commits.length;i++) {
const[,change] = commits?.item(i)?.textContent?.split('Changes to be committed:\n\t') ?? [];
if (change) changes.add(...change.split('\n\t'));
}
document.querySelector('#pull_request_body').value = [
'# π Description',
'',
'<DESCRICAO AQUI>',
'',
'## π Evidence that this works',
'',
'<UPLOAD IMAGES>',
'',
'## π§ͺ How to validate',
'',
'Run the application locally:',
'',
'- [ ] Should something',
'',
'',
'## π·οΈ Related tasks',
'',
'- '+id,
'',
'',
'## π Pull request related',
'',
'- #000',
'',
'',
'### ποΈ Changes',
'',
'On branch:',
'',
'> **' + branch + '**',
'',
'',
'Changes to be committed:',
'',
'> '+[...changes].sort().join('\n')
].join('\n')
}
- Add the copied code to Bookmark URL
β οΈ Attention: The function code needs be encoded to use in URI. You can use a online encoder or use this Javacript function BEFORE add to Bookmark URL.