#Render GitHub issues and pulls nicely

1 messages ยท Page 1 of 1 (latest)

earnest jungle
#

not a bug per se but id love to see it more like "user/repo#num - comment"

languid hare
#

Unless I'm dumb, this ain't workin for me.

narrow cape
#

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]*?$\/*
arctic kelp
#

yeah i'm late

narrow cape
#

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]+)\/*
languid hare
#

refuses to work, donno why

#

nvm, i see the issue

narrow cape
#

Just the same as with the original rgex pattern of this post

narrow cape
#

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

languid hare
olive breach
#

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

olive breach
#

The commit URL is a different regex

earnest jungle
#

oh right its only issues and prs

#

i should make one for that too

olive breach
#

See Andre's regex

olive breach
#

yeah

earnest jungle
#

ooh lfg

#

yall are amazing at regex i cant even

narrow cape
#

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.

olive breach
ancient plinth
# narrow cape Wish there was a way to further customize the replace mechanic in some way like ...

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)
narrow cape
#

You could simplify the URL part in the replacement by just using $&

#

That includes the whole thing

ancient plinth
#

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

narrow cape
#

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?

ancient plinth
ancient plinth
ancient plinth
#

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>
narrow cape
#

Like I thought

#

Doesn't work if you supress embedding with <>

ancient plinth
#

that's a good thing

narrow cape
#

Depends I guess

ancient plinth
#

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

narrow cape
ancient plinth
#

oh didn't know discord did that

#

well, you can always add it to the start and end captures I suppose

narrow cape
#

With your most recent example would it not work tho

ancient plinth
#

wait how would it even work in a link though?

#

would it be ?

narrow cape
#

As the <> need to be around the URL

#

For me personally is it not much of a deal...

ancient plinth
#

yeah, when I use <>, it's always to show the raw url in markdown

#

didn't even know it suppressed embeds

ancient plinth
# ancient plinth would it be [](<>)?

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

soft idol
#

hey it works

polar wharf
#

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

polar wharf
#

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

Download Skyblocker Action 10236828309

jade cypress
polar wharf
#

oop lazy matching moment

polar wharf
polar wharf