1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-05-31 16:34:06 +02:00

Add update-authors right in build script

This commit is contained in:
Alex Plate 2021-05-17 22:36:24 +03:00
parent b496f13c3c
commit cb9eb8f67e
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
2 changed files with 88 additions and 23 deletions

View File

@ -11,21 +11,26 @@ jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Update authors
env:
UPDATE_AUTHORS: ${{ secrets.UPDATE_AUTHORS }}
run: ./gradlew updateAuthors
- name: Update authors
env:
UPDATE_AUTHORS: ${{ secrets.UPDATE_AUTHORS }}
run: ./gradlew updateAuthors
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Update contributors list
commit_user_name: Alex Plate
commit_user_email: aleksei.plate@jetbrains.com
commit_author: Alex Plate <aleksei.plate@jetbrains.com>

View File

@ -1,7 +1,7 @@
import dev.feedforward.authorsupdate.UpdateAuthors
import dev.feedforward.markdownto.DownParser
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.detekt
import org.intellij.markdown.ast.getTextInNode
import java.net.HttpURLConnection
import java.net.URL
@ -14,7 +14,9 @@ buildscript {
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0")
classpath("com.github.AlexPl292:mark-down-to-slack:1.1.2")
classpath("com.github.AlexPl292:authors-update:0.0.9")
classpath("org.eclipse.jgit:org.eclipse.jgit:5.11.1.202105131744-r")
classpath("org.kohsuke:github-api:1.128")
classpath("org.jetbrains:markdown:0.1.45")
}
}
@ -263,11 +265,69 @@ tasks.register("updateAuthors") {
"aleksei.plate@TeamCity",
"alex.plate@192.168.0.109"
)
val token = if (updateAuthorsToken.isEmpty()) {
System.getenv("UPDATE_AUTHORS")
} else {
updateAuthorsToken
}
UpdateAuthors().update(".", token, uncheckedEmails)
UpdateAuthors().update(uncheckedEmails)
}
}
class UpdateAuthors {
fun update(uncheckedEmails: Set<String>) {
val repository = org.eclipse.jgit.lib.RepositoryBuilder().setGitDir(File("./.git")).build()
val git = org.eclipse.jgit.api.Git(repository)
val emails = git.log().call().take(20).mapTo(HashSet()) { it.authorIdent.emailAddress }
val gitHub = org.kohsuke.github.GitHub.connect()
val searchUsers = gitHub.searchUsers()
val users = mutableListOf<Author>()
for (email in emails) {
if (email in uncheckedEmails) continue
val githubUsers = searchUsers.q(email).list().toList()
if (githubUsers.isEmpty()) error("Cannot find user $email")
val user = githubUsers.single()
val htmlUrl = user.htmlUrl.toString()
val name = user.name
users.add(Author(name, htmlUrl, email))
}
val authorsFile = File("./AUTHORS.md")
val authors = authorsFile.readText()
val parser =
org.intellij.markdown.parser.MarkdownParser(org.intellij.markdown.flavours.gfm.GFMFlavourDescriptor())
val tree = parser.buildMarkdownTreeFromString(authors)
val contributorsSection = tree.children[24]
val existingEmails = mutableSetOf<String>()
for (child in contributorsSection.children) {
if (child.children.size > 1) {
existingEmails.add(
child.children[1].children[0].children[2].children[2].getTextInNode(authors).toString()
)
}
}
val newAuthors = users.filterNot { it.mail in existingEmails }
if (newAuthors.isEmpty()) return
val insertionString = newAuthors.toMdString()
val resultingString = StringBuffer(authors).insert(contributorsSection.endOffset, insertionString).toString()
authorsFile.writeText(resultingString)
}
}
fun List<Author>.toMdString(): String {
return this.joinToString() {
"""
|
|* [![icon][mail]](mailto:${it.mail})
| [![icon][github]](${it.url})
| &nbsp;
| ${it.name}
""".trimMargin()
}
}
data class Author(
val name: String,
val url: String,
val mail: String
)