Bookmarklet to generate a commit message for an issue in Linear.app

Updated . Posted . Visible to the public.

Your commit messages should include the ID of the issue your code belongs to.
Our preferred syntax prefixes the issue title with its ID in brackets, e.g. [FOO-123] Avatars for users.
Here is how to generate that from an issue in Linear.

Add a new link to your browser's bookmarks bar with the following URL.

javascript:(async () => {
  let output;
  if (document.querySelector('[data-view-id="issue-view"]')) {
    const [id, ...words] = document.title.split(' ');
    output = `[${id}] ${words.join(' ')}`;
  } else {
    let text;
    try {
      text = await navigator.clipboard.readText();
    } catch (error) {
      return alert('Error: Access to clipboard required');
    }
    const titles = [...text.matchAll(/\[((?:\\.|[^\]\\])+)\]\([^)]*\)/g)]
      .map(match => match[1].replace(/\\(.)/g, '$1').trim().replace(/^([A-Z]+-\d+):?\s*/, '[$1] '))
      .filter(Boolean);
    if (!titles.length) {
      return alert('Error: No linear issues selected');
    }
    output = titles.join('; ');
  }
  prompt('Commit message:', output);
})();
  • When viewing an issue, you can now click that link to open a browser prompt where you can Ctrl+C your commit message.
  • When selecting multiple issues with (Press X on highlighted issues and CTRL+C to copy all to the clipboard), you can now click that link to open a browser prompt where you can Ctrl+C your commit message.
Profile picture of Arne Hartherz
Arne Hartherz
Last edit
Emanuel
Keywords
linear, snippet
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2024-05-17 13:56)