mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Replace mentions with links to profiles in the release information (#9859)
Replace mentions with links in the release information.
This commit is contained in:
parent
eeeaae4570
commit
ed80ac3154
1 changed files with 16 additions and 1 deletions
|
@ -21,10 +21,25 @@ data class GithubRelease(
|
||||||
@Serializable
|
@Serializable
|
||||||
data class GitHubAssets(@SerialName("browser_download_url") val downloadLink: String)
|
data class GitHubAssets(@SerialName("browser_download_url") val downloadLink: String)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regular expression that matches a mention to a valid GitHub username, like it's
|
||||||
|
* done in GitHub Flavored Markdown. It follows these constraints:
|
||||||
|
*
|
||||||
|
* - Alphanumeric with single hyphens (no consecutive hyphens)
|
||||||
|
* - Cannot begin or end with a hyphen
|
||||||
|
* - Max length of 39 characters
|
||||||
|
*
|
||||||
|
* Reference: https://stackoverflow.com/a/30281147
|
||||||
|
*/
|
||||||
|
val gitHubUsernameMentionRegex =
|
||||||
|
"""\B@([a-z0-9](?:-(?=[a-z0-9])|[a-z0-9]){0,38}(?<=[a-z0-9]))""".toRegex(RegexOption.IGNORE_CASE)
|
||||||
|
|
||||||
val releaseMapper: (GithubRelease) -> Release = {
|
val releaseMapper: (GithubRelease) -> Release = {
|
||||||
Release(
|
Release(
|
||||||
it.version,
|
it.version,
|
||||||
it.info,
|
it.info.replace(gitHubUsernameMentionRegex) { mention ->
|
||||||
|
"[${mention.value}](https://github.com/${mention.value.substring(1)})"
|
||||||
|
},
|
||||||
it.releaseLink,
|
it.releaseLink,
|
||||||
it.assets.map(GitHubAssets::downloadLink),
|
it.assets.map(GitHubAssets::downloadLink),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue