rybak / intellij-copy-commit-reference

Plugin for context menu action "Copy Commit Reference" in IDEs from JetBrains.
https://plugins.jetbrains.com/plugin/22138-copy-commit-reference
MIT License
1 stars 0 forks source link

Embed link to commit on repo management service #3

Open dtruebin opened 1 year ago

dtruebin commented 1 year ago

It would be nice if commit id in the copied text was supplied with a link that would open the commit page on the corresponding repo management service, e.g.:

2bc598d (README: make badge "Build passing" clickable, 2023-07-12)

For Bitbucket, https://plugins.jetbrains.com/plugin/8015-bitbucket-linky can probably be used as reference.

rybak commented 1 year ago

I, of course, thought about it and have seen Bitbucket Linky. Source code of plugin GitLink provides more details about support for other platforms.

To give some context, the original idea for Copy Commit Reference was to make it easier for developers who create their commits from IntelliJ-based IDEs to add references to commit messages. Lack of an easy way of doing it was one of the reasons of why I wasn't creating commits in IntelliJ myself.

Because of that, the plain text variant was the only use case in mind at the start of development. Adding rich text variant was just an after-thought. It was added (10e4ef6bded338c0f756ddf6e93190aa7255049f) just before 1.0.0 was released only because it was extremely simple to do – just call IssueLinkHtmlRenderer.formatTextWithLinks and you're done.

Supporting commit links for different platforms is much more complicated than just providing a single class. I'm unlikely to work on this in the near future.

P.S. Irrelevant to IDE use-case, but bitbucket-copy-commit-reference.user.js of Atlassian Tweaks does support links to commits in rich text. I'll probably end up making similar scripts or maybe even a single script to cover other hosting services. The script already technically supports two: Bitbucket Server and Bitbucket Cloud, which are surprisingly dissimilar nowadays.

P.P.S. Right now I'm more concerned with plugin's compatibility (64a0eb545ccb6737d32c2c5f6e22cf211bd88b6d, 9f2bc2461758fe34d9b9d26c36f4fd7041ac09e5). I should probably write down the plan as a GitHub issue or something.

rybak commented 1 year ago

I tried to make a hacky way of doing with Issue Navigation using a regex with lookahead:

^([0-9abcdef]{5,40})(?= [(].*, \d\d\d\d-\d\d-\d\d[)])

but there seems to be a bug – any lookhead breaks the output. Compare READM(E):(?= ):

image

vs READM(E):(?=) (without the space in the lookahead group):

image

rybak commented 1 year ago

bitbucket-copy-commit-reference.user.js of Atlassian Tweaks does support links to commits in rich text. I'll probably end up making similar scripts or maybe even a single script to cover other hosting services.

Last week, I've experimented a bit with a GitHub-specific userscript. Today I've converted the Atlassian Tweaks' Bitbucket userscript into a single userscript. As of version 0.2-alpha, it supports Bitbucket Cloud, GitHub, GitWeb, Gitiles, and cgit. Branch alpha has been merged to main, new README has info about supported hosting providers.