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:
parent
b496f13c3c
commit
cb9eb8f67e
35
.github/workflows/updateAuthors.yml
vendored
35
.github/workflows/updateAuthors.yml
vendored
@ -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>
|
||||
|
@ -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})
|
||||
|
|
||||
| ${it.name}
|
||||
""".trimMargin()
|
||||
}
|
||||
}
|
||||
|
||||
data class Author(
|
||||
val name: String,
|
||||
val url: String,
|
||||
val mail: String
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user