Skip to content

Instantly share code, notes, and snippets.

@robcthegeek
Forked from pauloportella/conventional-comments.md
Last active October 25, 2024 10:57
Show Gist options
  • Save robcthegeek/7e60d21df783feea70ba9a88c4e8842d to your computer and use it in GitHub Desktop.
Save robcthegeek/7e60d21df783feea70ba9a88c4e8842d to your computer and use it in GitHub Desktop.
How to setup conventional comments on Github

Conventional comments

πŸ‘πŸ» praise: With thanks to @pauloportella for the original Gist πŸ™πŸ»


Make it easy to create Conventional Comments in GitHub by using saved replies'.

  1. Go to https://github.com/settings/replies
  2. Open Developer Tools (normally F12 or Ctrl/Cmd + Shift + I)
  3. Copy/paste the accompanying code into the JavaScript console
  4. Press Enter

Then, when commenting on a PR on GitHub:

  1. Tap / to bring up slash commands
  2. Tap S, Tab to select 'Saved replies'
  3. Select your conventional comment using ↑ and ↓, then hit Enter
  4. Say something helpful πŸ˜‰
{
const LABELS = [
["πŸ‘", "praise", "Praises highlight something positive. Always try to leave at least one praise comment per review."],
["🧐", "nitpick", "Nitpicks are minor suggestions that don't necessarily need to be addressed but can improve the code quality."],
["πŸ’‘", "suggestion", "Suggestions are recommendations for improvement. They are not mandatory but can enhance the code."],
["⚠", "issue", "Issues indicate problems that need to be fixed before the code can be merged."],
["⚠", "issue (non-blocking)", "Non-blocking issues are problems that should be addressed but do not prevent the code from being merged."],
["πŸ“", "todo", "TODOs are tasks that need to be completed. They are usually noted for future improvements."],
["❔", "question", "Questions are used to seek clarification or more information about the code."],
["πŸ’­", "thought", "Thoughts are non-blocking comments that share ideas or considerations for future improvements."],
["πŸ› ", "chore", "Chores are routine tasks that need to be done to maintain code quality or adhere to processes."],
["πŸ—’", "note", "Notes are non-blocking comments that provide additional information or context."],
["✏", "typo", "Typo comments point out spelling or grammatical errors that need to be corrected."],
["✨", "polish", "Polish comments suggest minor improvements that can enhance the overall quality of the code."]
];
const form = document.querySelector(".new_saved_reply");
const authenticity_token = encodeURIComponent(
form.querySelector("[name=authenticity_token]").value
);
Promise.all(
LABELS.map(([emoji, type, note], index) => {
const title = encodeURIComponent(`${type[0].toUpperCase()}${type.slice(1)}`);
const body = encodeURIComponent(`<!-- ${note} -->\n**${emoji} ${type}:** `);
return fetch("replies", {
headers: {
accept:
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"accept-language": "en-US,en;q=0.9",
"cache-control": "no-cache",
"content-type": "application/x-www-form-urlencoded",
pragma: "no-cache",
"sec-fetch-dest": "document",
"sec-fetch-mode": "navigate",
"sec-fetch-site": "same-origin",
"sec-fetch-user": "?1",
"upgrade-insecure-requests": "1",
},
referrer: "https://github.com/settings/replies",
referrerPolicy: "strict-origin-when-cross-origin",
body: `authenticity_token=${authenticity_token}&title=${title}&saved_reply_id=&body=${body}&path=&line=&start_line=&preview_side=&preview_start_side=&start_commit_oid=&end_commit_oid=&base_commit_oid=&comment_id=`,
method: "POST",
mode: "cors",
credentials: "include",
})
})
).then(() => console.log("All added! Refresh the page!"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment