-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from CalMWolfs/edits
- Loading branch information
Showing
3 changed files
with
109 additions
and
73 deletions.
There are no files selected for viewing
123 changes: 62 additions & 61 deletions
123
src/main/kotlin/at/hannibal2/changelog/ContributorsBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,87 @@ | ||
package org.example | ||
package at.hannibal2.changelog | ||
|
||
import at.hannibal2.changelog.Utils.matchMatcher | ||
import java.awt.Toolkit | ||
import java.awt.datatransfer.DataFlavor | ||
|
||
/** | ||
* This script expects the raw content of the full version in question | ||
* from CHANGELOG.MD in clipboard and will print the alphabetically orderd list of all contributrs. | ||
* from CHANGELOG.MD in clipboard and will print the alphabetically ordered list of all contributors. | ||
* This also supports entries with multiple contributors | ||
*/ | ||
|
||
fun main() { | ||
val clipboard = Toolkit.getDefaultToolkit().systemClipboard?.getData(DataFlavor.stringFlavor)?.toString() | ||
if (clipboard == null) { | ||
println("clipboard empty") | ||
return | ||
} | ||
// remove sub categories | ||
var s = clipboard.split("\n").toList().filter { !it.startsWith(" + ") && !it.startsWith(" ") } | ||
.joinToString("\n") | ||
object ContributorsBuilder { | ||
|
||
// fix unecessary break points | ||
s = s.replace("\n ", " ").replace(" ", " ") | ||
private val contributionPattern = "\\+ .*\\. - (?<name>.*) \\(.*\\)".toPattern() | ||
|
||
val pattern = "\\+ .*\\. - (?<name>.*) \\(.*\\)".toPattern() | ||
fun getContributors(text: String) { | ||
|
||
val map = mutableMapOf<String, Int>() | ||
// Remove sub-categories and fix unnecessary break points | ||
val content = text.split("\n") | ||
.filter { !it.startsWith(" + ") && !it.startsWith(" ") } | ||
.joinToString("\n") | ||
.replace("\n ", " ") | ||
.replace(" ", " ") | ||
|
||
for (line in s.split("\n")) { | ||
val matcher = pattern.matcher(line) | ||
if (matcher.matches()) { | ||
val name = matcher.group("name") | ||
val names = mutableListOf<String>() | ||
if (name.contains(", ")) { | ||
names.addAll(name.split(", ")) | ||
} else if (name.contains(" & ")) { | ||
names.addAll(name.split(" & ")) | ||
} else if (name.contains(" + ")) { | ||
names.addAll(name.split(" + ")) | ||
} else if (name.contains("/")) { | ||
names.addAll(name.split("/")) | ||
} else { | ||
names.add(name) | ||
} | ||
if (name == "Alexia Alexia Luna") { | ||
println("line: $line") | ||
val contributions = mutableMapOf<String, Int>() | ||
|
||
for (line in content.split("\n")) { | ||
|
||
contributionPattern.matchMatcher(line) { | ||
val name = group("name") | ||
val names = mutableListOf<String>() | ||
if (name.contains(", ")) { | ||
names.addAll(name.split(", ")) | ||
} else if (name.contains(" & ")) { | ||
names.addAll(name.split(" & ")) | ||
} else if (name.contains(" + ")) { | ||
names.addAll(name.split(" + ")) | ||
} else if (name.contains("/")) { | ||
names.addAll(name.split("/")) | ||
} else { | ||
names.add(name) | ||
} | ||
for (oneName in names) { | ||
contributions[oneName] = contributions.getOrDefault(oneName, 0) + 1 | ||
} | ||
} | ||
} | ||
// printNumbers(map) | ||
printFormatted(contributions.keys) | ||
} | ||
|
||
for (oneName in names) { | ||
val old = map[oneName] ?: 0 | ||
map[oneName] = old + 1 | ||
private fun printFormatted(names: MutableSet<String>) { | ||
println("") | ||
val sorted = names.map { it to it.lowercase() }.sortedBy { it.second }.map { it.first } | ||
val line = StringBuilder() | ||
val total = StringBuilder() | ||
for (name in sorted) { | ||
line.append(name) | ||
if (line.length > 35) { | ||
total.append(line) | ||
total.append("\n") | ||
line.setLength(0) | ||
} else { | ||
line.append(", ") | ||
} | ||
} else { | ||
if (line.startsWith("##")) continue | ||
if (line == "") continue | ||
} | ||
println(" ") | ||
println(total) | ||
} | ||
// printNumbers(map) | ||
printFormatted(map.keys) | ||
} | ||
|
||
fun printFormatted(names: MutableSet<String>) { | ||
println("") | ||
val sorted = names.map { it to it.lowercase() }.sortedBy { it.second }.map { it.first } | ||
val line = StringBuilder() | ||
val total = StringBuilder() | ||
for (name in sorted) { | ||
line.append(name) | ||
if (line.length > 35) { | ||
total.append(line) | ||
total.append("\n") | ||
line.setLength(0) | ||
} else { | ||
line.append(", ") | ||
private fun printNumbers(map: MutableMap<String, Int>) { | ||
println("") | ||
for ((name, amount) in map.entries.sortedBy { it.value }.reversed()) { | ||
println("$name ($amount)") | ||
} | ||
} | ||
println(" ") | ||
println(total) | ||
} | ||
|
||
private fun printNumbers(map: MutableMap<String, Int>) { | ||
println("") | ||
for ((name, amount) in map.entries.sortedBy { it.value }.reversed()) { | ||
println("$name ($amount)") | ||
fun main() { | ||
val clipboard = Toolkit.getDefaultToolkit().systemClipboard?.getData(DataFlavor.stringFlavor)?.toString() | ||
if (clipboard == null) { | ||
println("clipboard empty") | ||
return | ||
} | ||
ContributorsBuilder.getContributors(clipboard) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters