feat(build): migrate to Crowdin V2 API
This commit is contained in:
parent
cb0a2fe6ee
commit
8e14f8ccaf
6 changed files with 46 additions and 12 deletions
1
.github/workflows/sync_crowdin.yml
vendored
1
.github/workflows/sync_crowdin.yml
vendored
|
@ -25,7 +25,6 @@ jobs:
|
||||||
env:
|
env:
|
||||||
CROWDIN_LOGIN: ${{ secrets.CROWDIN_LOGIN }}
|
CROWDIN_LOGIN: ${{ secrets.CROWDIN_LOGIN }}
|
||||||
CROWDIN_PROJECT_KEY: ${{ secrets.CROWDIN_PROJECT_KEY }}
|
CROWDIN_PROJECT_KEY: ${{ secrets.CROWDIN_PROJECT_KEY }}
|
||||||
CROWDIN_PROJECT_IDENTIFIER: ${{ secrets.CROWDIN_PROJECT_IDENTIFIER }}
|
|
||||||
|
|
||||||
- name: Check if PR is required
|
- name: Check if PR is required
|
||||||
run: if [[ $(git status -s) != '' ]]; then echo "UPDATED=true" >> $GITHUB_ENV; fi
|
run: if [[ $(git status -s) != '' ]]; then echo "UPDATED=true" >> $GITHUB_ENV; fi
|
||||||
|
|
|
@ -98,6 +98,8 @@ dependencies {
|
||||||
implementation(libs.build.ktfmt)
|
implementation(libs.build.ktfmt)
|
||||||
implementation(libs.build.mavenpublish)
|
implementation(libs.build.mavenpublish)
|
||||||
implementation(libs.build.metalava)
|
implementation(libs.build.metalava)
|
||||||
|
implementation(libs.build.moshi)
|
||||||
|
implementation(libs.build.moshi.kotlin)
|
||||||
implementation(libs.build.okhttp)
|
implementation(libs.build.okhttp)
|
||||||
implementation(libs.build.r8)
|
implementation(libs.build.r8)
|
||||||
implementation(libs.build.semver)
|
implementation(libs.build.semver)
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
package app.passwordstore.gradle.crowdin
|
package app.passwordstore.gradle.crowdin
|
||||||
|
|
||||||
|
import app.passwordstore.gradle.crowdin.api.ListProjects
|
||||||
|
import com.squareup.moshi.Moshi
|
||||||
|
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
import okhttp3.MediaType.Companion.toMediaType
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
import org.gradle.api.DefaultTask
|
import org.gradle.api.DefaultTask
|
||||||
import org.gradle.api.provider.Property
|
import org.gradle.api.provider.Property
|
||||||
import org.gradle.api.tasks.Input
|
import org.gradle.api.tasks.Input
|
||||||
|
@ -26,15 +31,37 @@ abstract class BuildOnApiTask : DefaultTask() {
|
||||||
.readTimeout(5, TimeUnit.MINUTES)
|
.readTimeout(5, TimeUnit.MINUTES)
|
||||||
.callTimeout(10, TimeUnit.MINUTES)
|
.callTimeout(10, TimeUnit.MINUTES)
|
||||||
.build()
|
.build()
|
||||||
val url =
|
val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
|
||||||
CROWDIN_BUILD_API_URL.format(crowdinIdentifier.get(), crowdinLogin.get(), crowdinKey.get())
|
val projectAdapter = moshi.adapter(ListProjects::class.java)
|
||||||
val request = Request.Builder().url(url).get().build()
|
val projectRequest =
|
||||||
client.newCall(request).execute().close()
|
Request.Builder()
|
||||||
|
.url("$CROWDIN_BASE_URL/projects")
|
||||||
|
.header("Authorization", "Bearer ${crowdinKey.get()}")
|
||||||
|
.get()
|
||||||
|
.build()
|
||||||
|
client.newCall(projectRequest).execute().use { response ->
|
||||||
|
val projects = projectAdapter.fromJson(response.body!!.source())
|
||||||
|
if (projects != null) {
|
||||||
|
val identifier =
|
||||||
|
projects.projects
|
||||||
|
.first { data -> data.project.identifier == crowdinIdentifier.get() }
|
||||||
|
.project
|
||||||
|
.id
|
||||||
|
.toString()
|
||||||
|
val buildRequest =
|
||||||
|
Request.Builder()
|
||||||
|
.url(CROWDIN_BUILD_API_URL.format(identifier))
|
||||||
|
.header("Authorization", "Bearer ${crowdinKey.get()}")
|
||||||
|
.post("{}".toRequestBody("application/json".toMediaType()))
|
||||||
|
.build()
|
||||||
|
client.newCall(buildRequest).execute().close()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
|
|
||||||
private const val CROWDIN_BUILD_API_URL =
|
private const val CROWDIN_BASE_URL = "https://api.crowdin.com/api/v2"
|
||||||
"https://api.crowdin.com/api/project/%s/export?login=%s&account-key=%s"
|
private const val CROWDIN_BUILD_API_URL = "$CROWDIN_BASE_URL/projects/%s/translations/builds"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,6 @@ import org.gradle.api.tasks.Delete
|
||||||
import org.gradle.kotlin.dsl.create
|
import org.gradle.kotlin.dsl.create
|
||||||
import org.gradle.kotlin.dsl.register
|
import org.gradle.kotlin.dsl.register
|
||||||
|
|
||||||
private const val EXCEPTION_MESSAGE =
|
|
||||||
"""Applying `crowdin-plugin` requires a projectName to be configured via the "crowdin" extension."""
|
|
||||||
private const val CROWDIN_BUILD_API_URL =
|
|
||||||
"https://api.crowdin.com/api/project/%s/export?login=%s&account-key=%s"
|
|
||||||
|
|
||||||
@Suppress("Unused")
|
@Suppress("Unused")
|
||||||
class CrowdinDownloadPlugin : Plugin<Project> {
|
class CrowdinDownloadPlugin : Plugin<Project> {
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package app.passwordstore.gradle.crowdin.api
|
||||||
|
|
||||||
|
import com.squareup.moshi.Json
|
||||||
|
|
||||||
|
data class ListProjects(@Json(name = "data") val projects: List<ProjectData>)
|
||||||
|
|
||||||
|
data class ProjectData(@Json(name = "data") val project: Project)
|
||||||
|
|
||||||
|
data class Project(val id: Long, val identifier: String)
|
|
@ -43,6 +43,8 @@ build-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.r
|
||||||
build-ktfmt = "com.facebook:ktfmt:0.43"
|
build-ktfmt = "com.facebook:ktfmt:0.43"
|
||||||
build-mavenpublish = "com.vanniktech:gradle-maven-publish-plugin:0.25.1"
|
build-mavenpublish = "com.vanniktech:gradle-maven-publish-plugin:0.25.1"
|
||||||
build-metalava = "me.tylerbwong.gradle.metalava:plugin:0.3.3"
|
build-metalava = "me.tylerbwong.gradle.metalava:plugin:0.3.3"
|
||||||
|
build-moshi = "com.squareup.moshi:moshi:1.14.0"
|
||||||
|
build-moshi-kotlin = "com.squareup.moshi:moshi-kotlin:1.14.0"
|
||||||
build-okhttp = "com.squareup.okhttp3:okhttp:4.10.0"
|
build-okhttp = "com.squareup.okhttp3:okhttp:4.10.0"
|
||||||
build-r8 = "com.android.tools:r8:8.0.34"
|
build-r8 = "com.android.tools:r8:8.0.34"
|
||||||
build-semver = "com.vdurmont:semver4j:3.1.0"
|
build-semver = "com.vdurmont:semver4j:3.1.0"
|
||||||
|
|
Loading…
Reference in a new issue