Skip to content

Instantly share code, notes, and snippets.

@ifyoumakeit
Last active May 6, 2024 14:31
Show Gist options
  • Star 65 You must be signed in to star a gist
  • Fork 16 You must be signed in to fork a gist
  • Save ifyoumakeit/4148a8c3e61b7868935651272c03f793 to your computer and use it in GitHub Desktop.
Save ifyoumakeit/4148a8c3e61b7868935651272c03f793 to your computer and use it in GitHub Desktop.
GitHub Conventional Comments (instructions to install in comment below code)
(async function generateReplies(document) {
// https://conventionalcomments.org/#labels
const LABEL = {
praise: "praise",
nitpick: "nitpick",
suggestion: "suggestion",
issue: "issue",
todo: "todo",
question: "question",
thought: "thought",
chore: "chore",
typo: "typo",
polish: "polish",
quibble: "quibble",
note: "note"
};
const NON_BLOCKING = [LABEL.nitpick, LABEL.thought, LABEL.quibble, LABEL.note];
const COMMENT = {
[LABEL.praise]:
"Praises highlight something positive. Try to leave at least one of these comments per review. Do not leave false praise (which can actually be damaging). Do look for something to sincerely praise.",
[LABEL.nitpick]:
"Nitpicks are trivial preference-based requests. These should be non-blocking by nature.",
[LABEL.suggestion]:
"Suggestions propose improvements to the current subject. It's important to be explicit and clear on what is being suggested and why it is an improvement. Consider using patches and the blocking or non-blocking decorations to further communicate your intent.",
[LABEL.issue]:
"Issues highlight specific problems with the subject under review. These problems can be user-facing or behind the scenes. It is strongly recommended to pair this comment with a suggestion. If you are not sure if a problem exists or not, consider leaving a question.",
[LABEL.todo]:
"TODO's are small, trivial, but necessary changes. Distinguishing todo comments from issues: or suggestions: helps direct the reader's attention to comments requiring more involvement.",
[LABEL.question]:
"Questions are appropriate if you have a potential concern but are not quite sure if it's relevant or not. Asking the author for clarification or investigation can lead to a quick resolution.",
[LABEL.thought]:
"Thoughts represent an idea that popped up from reviewing. These comments are non-blocking by nature, but they are extremely valuable and can lead to more focused initiatives and mentoring opportunities.",
[LABEL.chore]:
"Chores are simple tasks that must be done before the subject can be “officially” accepted. Usually, these comments reference some common process. Try to leave a link to the process description so that the reader knows how to resolve the chore.",
[LABEL.note]:
"Notes are always non-blocking and simply highlight something the reader should take note of.",
[LABEL.typo]:
"Typo comments are like todo:, where the main issue is a mispelling.",
[LABEL.polish]:
"Polish comments are like a suggestion, where there is nothing necessarily wrong with the relevant content, there's just some ways to immediately improve the quality.",
[LABEL.quibble]:
"Quibbles are very much like nitpick:, except it does not conjure up images of lice and animal hygiene practices.",
};
function post(key, token) {
const blockingText = NON_BLOCKING.includes(key) ? " (non-blocking)" : "";
return fetch("replies", {
headers: { "content-type": "application/x-www-form-urlencoded" },
method: "POST",
mode: "cors",
credentials: "include",
body: new URLSearchParams({
body: `<!-- ${COMMENT[key]} -->\n**${key}${blockingText}:** ‏`,
authenticity_token: token,
title: `${key[0].toUpperCase()}${key.slice(1)}${blockingText}`,
}).toString(),
});
}
const form = document.querySelector(".new_saved_reply");
const token = form.querySelector("[name=authenticity_token]").value;
// Replies are order alphabetically, so order doesn't need to preserved.
await Promise.all(Object.keys(LABEL).map(key => post(key, token)));
console.log("All added! Refresh the page!");
})(window.document);
@ifyoumakeit
Copy link
Author

ifyoumakeit commented Aug 6, 2020

GitHub Conventional Comments!

Conventional Comments is a standard for formatting comments of any kind of review/feedback process. GitHub Saved Replies are re-usable text snippets that you can use throughout GitHub comment fields. Combining the two gives you GitHub Conventional Comments!

How to install

  1. Go to https://github.com/settings/replies
  2. Open Developer Tools
  3. Paste and run above code in JavaScript console

How to add a conventional comment

Go to a Pull Request or Issue comment box and press CTRL + . or click reply button.

Note: doesn't work in gists.

@ifyoumakeit
Copy link
Author

ifyoumakeit commented Aug 7, 2020

Screenshots

image

@GZLiew
Copy link

GZLiew commented Dec 14, 2022

Amazing snippet!

@dcrtest007
Copy link

testing

@dcrtest007
Copy link

tesss

@dcrtest007
Copy link

**nitpick (non-blocking, if-minor);

@ifyoumakeit
Copy link
Author

Updated to add todo, polish, quibble and typo.

@ifyoumakeit
Copy link
Author

Added note and some non-blocking tags for those that always non-blocking.

@miketheman
Copy link

@ifyoumakeit something about the non_blocking made these specific ones return undefined

@ifyoumakeit
Copy link
Author

@miketheman so fast! I forgot that I was using the LABELS as a lookup. It's fixed.

@miketheman
Copy link

@ifyoumakeit excellent, thanks!

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