#Render GitHub issues and pulls nicely
1 messages ยท Page 1 of 1 (latest)
ive been loving this but found a little corner case with links to comments, like this one:
https://github.com/11ty/eleventy/issues/836#issuecomment-1732396888
11ty/eleventy#836#issuecomment-1732396888
not a bug per se but id love to see it more like "user/repo#num - comment"
Unless I'm dumb, this ain't workin for me.
Still works
I also made a regex to display commits as <repo>@<commit> with commit being first 7 characters and in inline code block:
https:\/\/(to)?github\.com\/(?<repo>[a-zA-Z0-9-]+\/[a-zA-Z0-9._-]+)\/commit\/(?<commit>[a-z0-9]{7})[a-z0-9]*?$\/*
Example:
Vencord/Vesktop@6993b2a
actually - it kind of is! i think the link goes to the issue instead of the comment
yeah i'm late
Btw, tiny update to the regex pattern to include discussions (literally just add discussions to the group):
https:\/\/(to)?github\.com\/(?<repo>[A-Za-z0-9-]+\/[A-Za-z0-9._-]+)\/(issues|pull|discussions)\/(?<number>[0-9]+)\/*
i put this in the find section right? what about the replace?
refuses to work, donno why
nvm, i see the issue
Just the same as with the original rgex pattern of this post
I have it like this:
Regex: https:\/\/(to)?github\.com\/(?<repo>[a-zA-Z0-9-]+\/[a-zA-Z0-9._-]+)\/commit\/(?<commit>[a-z0-9]{7})[a-z0-9]*?$\/*
Replace: [$<repo>@`$<commit>`]($&)
And it works fine for me
i made a fix for this:
Regex: <?https?:\/\/(to)?github\.com\/(?<repo>[A-Za-z0-9-]+\/[A-Za-z0-9._-]+)\/(issues|pull)\/(?<number>[0-9]+)\/*(?<hash>#(?:issue(?:comment)?|pullrequestreview|event|ref-commit)-[\da-f]+)?>?
Replace: [$<repo>#$<number>$<hash>]($&)
it also captures angle brackets <> so i can make it not embed if i wanted to
i don't think you can make it look nicer within the constraints of the textreplace plugin, outside of removing the timestamp
regex demo: https://regex101.com/r/882sha/1
ooh thanks
tysm
yeah that works
lemme try...
darn
The commit URL is a different regex
See Andre's regex
this one?
sweet
yeah
Why do [0-9]+ and not just \d+? It's legit the same and needs less typing
Also, I made a modification to the regex:
<?https:\/\/(?:to)?github\.com\/(?<repo>[a-zA-Z0-9-]+\/[a-zA-Z0-9._-]+)\/(?:issues|pull(?:s)?|discussions)\/(?<number>\d+)\/*(?:#(?<hash>issue(?:comment)?|pullrequestreview|event|ref-commit)-[\da-f]+)?>?
Gives an output like this:
11ty/eleventy#836 issuecomment
Downside is, that there will be an empty space at the end if no comment or alike is linked...
Wish there was a way to further customize the replace mechanic in some way like have {{$<hash>? ($<hash>):}} to input a value if the group has content...
But for what it is does this work fine.
because i went silly from reading all the regex
I just do 2 rules for this, so I also get the issuecomment etc in brackets, which is more similar to how github does it natively.
I have this for pure links (without comments):
(?:\s|^)(?<fqdn>https:\/\/(?:to)?github\.com)\/(?<repo>[\w\d-]+\/[\w\d._-]+)\/(?<type>(?:issues)|(?:pull))\/(?<number>\d+)\/?(?:\s|$)
``` replacing to: ```
[$<repo>#$<number>]($<fqdn>/$<repo>/$<type>/$<number>)
and for links with comments, I just do this:
(?:\s|^)(?<fqdn>https:\/\/(?:to)?github\.com)\/(?<repo>[\w\d-]+\/[\w\d._-]+)\/(?<type>(?:issues)|(?:pull))\/(?<number>\d+)\/?(?<href>#(?<htype>\w+)-(?<hid>[\d\w]+))\/?(?:\s|$)
``` replacing to: ```
[$<repo>#$<number> ($<htype> $<hid>)]($<fqdn>/$<repo>/$<type>/$<number>$<href>)
giving you this from a result:
hyprwm/Hyprland#5141 (pullrequestreview 1941524349)
Or if you want it exactly how github does it, which just puts (comment) there, you can use this replace pattern instead: ```
$<repo>#$<number> (comment)
giving you:
[hyprwm/Hyprland#5141 (comment)](https://github.com/hyprwm/Hyprland/pull/5141#pullrequestreview-1941524349)
You could simplify the URL part in the replacement by just using $&
That includes the whole thing
I know, but that would match the \s too, consuming a whitespace
and I like to wrap the pattern with (?:\s|^) and (?:\s|$) , so that it needs a whitespace around the text, that way if I actually send something like [foobar](https://github.com/...) it won't trigger the rule
though thinking of it, this will still consume the whitespace, just not replace it back, I'd have to capture these and put them back in the replace string, that's annoying
Also, personal preference, but I think you could leave the https:// out of the fqdn group and include it in the replacement itself... Would especially make it a bit easier if you want to capture multiple possible domains. Like in my case github and codeberg
Also, why exactly are you doing non-capturing groups for issues and pull?
oh right, I thought the | would only match s|p without the group that's why, turns out it doesn't
yeah, that's not a bad idea
That would be more the [] thing
yep
got it to this now:
(?<start>\s|^)https:\/\/(?<fqdn>(?:to)?github\.com)\/(?<repo>[\w\d-]+\/[\w\d._-]+)\/(?<type>issues|pull)\/(?<number>\d+)\/?(?<end>\s|$)
``` -> ```
$<start>[$<repo>#$<number>](https://$<fqdn>/$<repo>/$<type>/$<number>)$<end>
``` and ```
(?<start>\s|^)https:\/\/(?<fqdn>(?:to)?github\.com)\/(?<repo>[\w\d-]+\/[\w\d._-]+)\/(?<type>issues|pull)\/(?<number>\d+)\/?(?<href>#(?<htype>\w+)-(?<hid>[\d\w]+))\/?(?<end>\s|$)
``` -> ```
$<start>[$<repo>#$<number> ($<htype> $<hid>)](https://$<fqdn>/$<repo>/$<type>/$<number>$<href>)$<end>
that's a good thing
Depends I guess
that's the point of those whitespace captures there
you might want to put a custom text in the markdown link with a github issue link
that way, this won't override it and create a markdown link in your markdown link
you don't surround markdown links with <>, that's meant for full URLs shown without any abbreviation
so I'd say it's behaving just as it should
Or for just supressing the embed
oh didn't know discord did that
well, you can always add it to the start and end captures I suppose
With your most recent example would it not work tho
yeah, when I use <>, it's always to show the raw url in markdown
didn't even know it suppressed embeds
if it's just this, it would be doable, but I probably wouldn't even want that, imo it's nice to be able to send the full url with <> if you want to for some reason
i made this rule that should work with all types of issue links
match: https:\/\/github\.com\/(?<user>.+?)\/(?<repo>.+?)\/issues\/(?<issueId>\d+)(?:#(?:issuecomment|(?:ref-(?:issue|commit))|event)(?<preciseId>-[\dA-Za-z]+))?
replace: [$<user>/$<repo>#$<issueId>$<preciseId>](<$&>)
examples:
https://github.com/Johni0702/bobby/issues/72
https://github.com/Johni0702/bobby/issues/72#issuecomment-1518831417
https://github.com/Johni0702/bobby/issues/72#ref-issue-2144198300
https://github.com/Johni0702/bobby/issues/72#ref-commit-cc42d7f
https://github.com/Fabulously-Optimized/fabulously-optimized/issues/556#event-8113384994
Johni0702/bobby#72
Johni0702/bobby#72-1518831417
Johni0702/bobby#72-2144198300
Johni0702/bobby#72-cc42d7f
Fabulously-Optimized/fabulously-optimized#556-8113384994
it use lazy matching and i have user and repo split so that it's easy to hide the user if i don't want it
if textreplace had a way to do if not include on the matched string, then i would be able to do smth even more cleaner
here is a rule to convert an artifact link from GH into a nightly.link one so that people can download it without logging into GH
i made this rule that should work with all types of issue links
match: [https:\/\/github\.com\/(?<user>.+?)\/(?<repo>.+?)\/issues\/(?<issueId>\d+)(?:#(?:issuecomment|(?:ref-(?:issue|commit))|event)(?<preciseId>-[\dA-Za-z]+))?](https://github/.com//(?<user>.+?)\/(?<repo>.+?)\/actions\/runs\/(?<runId>\d+)\/artifacts\/(?<artifactId>\d+))
replace: [Download $<repo> Action $<runId>](<https://nightly.link/$<user>/$<repo>/actions/runs/$<runId>>)
examples:
https://github.com/SkyblockerMod/Skyblocker/actions/runs/10236828309/artifacts/1773713170
Okay but what about this but literally just for the repo itself, so like https://github.com/Vendicated/Vencord shows up as Vendicated/Vencord
can be doable easily
match: https:\/\/github\.com\/(?<user>.+?)\/(?<repo>.+?)
replace: [$<user>/$<repo>](<$&>)
obv place the more generic rules at the bottom so they get evaluated last
Vendicated/Vencord
oop lazy matching moment
[test] Vendicated/Vencord this is a test
ok so this will work
match: https:\/\/github\.com\/(?<user>[-.\w]+)\/(?<repo>[-.\w]+)
replace: [$<user>/$<repo>](<$&>)