Skip to content

Commit

Permalink
CHANGELOG.md: Add entry for PR #2
Browse files Browse the repository at this point in the history
Also remove the username from PR link references.

Signed-off-by: Andrew Gunnerson <[email protected]>
  • Loading branch information
chenxiaolong committed Jun 23, 2024
1 parent ac1f6f9 commit 2bdab20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
When adding new changelog entries, use [Issue #0] to link to issues and
[PR #0 @user] to link to pull requests. Then run:
[PR #0] to link to pull requests. Then run:
./gradlew changelogUpdateLinks
Expand All @@ -9,8 +9,11 @@

### Unreleased

* Log boot script output to logcat ([PR #2])

### Version 1.0

* Initial release

<!-- Do not manually edit the lines below. Use `./gradlew changelogUpdateLinks` to regenerate. -->
[PR #2]: https://github.com/chenxiaolong/OEMUnlockOnBoot/pull/2
31 changes: 6 additions & 25 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -277,26 +277,15 @@ android.applicationVariants.all {
}
}

data class LinkRef(val type: String, val number: Int, val user: String?) : Comparable<LinkRef> {
data class LinkRef(val type: String, val number: Int) : Comparable<LinkRef> {
override fun compareTo(other: LinkRef): Int = compareValuesBy(
this,
other,
{ it.type },
{ it.number },
{ it.user },
)

override fun toString(): String = buildString {
append('[')
append(type)
append(" #")
append(number)
if (user != null) {
append(" @")
append(user)
}
append(']')
}
override fun toString(): String = "[$type #$number]"
}

fun checkBrackets(line: String) {
Expand All @@ -320,7 +309,7 @@ fun checkBrackets(line: String) {
fun updateChangelogLinks(baseUrl: String) {
val file = File(rootDir, "CHANGELOG.md")
val regexStandaloneLink = Regex("\\[([^\\]]+)\\](?![\\(\\[])")
val regexAutoLink = Regex("(Issue|PR) #(\\d+)(?: @([\\w-]+))?")
val regexAutoLink = Regex("(Issue|PR) #(\\d+)")
val links = hashMapOf<LinkRef, String>()
var skipRemaining = false
val changelog = mutableListOf<String>()
Expand All @@ -338,26 +327,18 @@ fun updateChangelogLinks(baseUrl: String) {
val match = regexAutoLink.matchEntire(linkText)
require(match != null) { "Invalid link format: $linkText" }

val ref = match.groupValues[0]
val type = match.groupValues[1]
val number = match.groupValues[2].toInt()
val user = match.groups[3]?.value

val link = when (type) {
"Issue" -> {
require(user == null) { "$ref should not have a username" }
"$baseUrl/issues/$number"
}
"PR" -> {
require(user != null) { "$ref should have a username" }
"$baseUrl/pull/$number"
}
"Issue" -> "$baseUrl/issues/$number"
"PR" -> "$baseUrl/pull/$number"
else -> throw IllegalArgumentException("Unknown link type: $type")
}

// #0 is used for examples only
if (number != 0) {
links[LinkRef(type, number, user)] = link
links[LinkRef(type, number)] = link
}
}

Expand Down

0 comments on commit 2bdab20

Please sign in to comment.