-
Notifications
You must be signed in to change notification settings - Fork 9
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 #51 from Kortvk/add-click-up-integration
Add task to automate ClickUp workflows
- Loading branch information
Showing
11 changed files
with
396 additions
and
1 deletion.
There are no files selected for viewing
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
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
38 changes: 38 additions & 0 deletions
38
...ugin/src/main/java/ru/kode/android/build/publish/plugin/extension/config/ClickUpConfig.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ru.kode.android.build.publish.plugin.extension.config | ||
|
||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.InputFile | ||
import org.gradle.api.tasks.Optional | ||
|
||
interface ClickUpConfig { | ||
val name: String | ||
|
||
/** | ||
* The path to the file containing the API token for the ClickUp | ||
*/ | ||
@get:InputFile | ||
val apiTokenFile: RegularFileProperty | ||
|
||
/** | ||
* Pattern to be used to format version to the ClickUp tasks | ||
*/ | ||
@get:Input | ||
@get:Optional | ||
val fixVersionPattern: Property<String> | ||
|
||
/** | ||
* The id of the custom field to be used for the fix version in the ClickUp tasks | ||
*/ | ||
@get:Input | ||
@get:Optional | ||
val fixVersionFieldId: Property<String> | ||
|
||
/** | ||
* The tag name to be used for the ClickUp tasks | ||
*/ | ||
@get:Input | ||
@get:Optional | ||
val tagName: Property<String> | ||
} |
125 changes: 125 additions & 0 deletions
125
.../src/main/java/ru/kode/android/build/publish/plugin/task/clickup/ClickUpAutomationTask.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 |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package ru.kode.android.build.publish.plugin.task.clickup | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.plugins.BasePlugin | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.InputFile | ||
import org.gradle.api.tasks.Optional | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.api.tasks.options.Option | ||
import org.gradle.workers.WorkQueue | ||
import org.gradle.workers.WorkerExecutor | ||
import ru.kode.android.build.publish.plugin.enity.Tag | ||
import ru.kode.android.build.publish.plugin.enity.mapper.fromJson | ||
import ru.kode.android.build.publish.plugin.task.clickup.work.AddFixVersionWork | ||
import ru.kode.android.build.publish.plugin.task.clickup.work.AddTagToTaskWork | ||
import javax.inject.Inject | ||
|
||
abstract class ClickUpAutomationTask | ||
@Inject | ||
constructor( | ||
private val workerExecutor: WorkerExecutor, | ||
) : DefaultTask() { | ||
init { | ||
description = "Task to automate ClickUp statuses" | ||
group = BasePlugin.BUILD_GROUP | ||
} | ||
|
||
@get:InputFile | ||
@get:Option(option = "tagBuildFile", description = "Json contains info about tag build") | ||
abstract val tagBuildFile: RegularFileProperty | ||
|
||
@get:InputFile | ||
@get:Option(option = "changelogFile", description = "File with saved changelog") | ||
abstract val changelogFile: RegularFileProperty | ||
|
||
@get:Input | ||
@get:Option( | ||
option = "issueNumberPattern", | ||
description = "How task number formatted", | ||
) | ||
abstract val issueNumberPattern: Property<String> | ||
|
||
@get:InputFile | ||
@get:Option( | ||
option = "apiTokenFile", | ||
description = "API token for ClickUp", | ||
) | ||
abstract val apiTokenFile: RegularFileProperty | ||
|
||
@get:Input | ||
@get:Option( | ||
option = "fixVersionPattern", | ||
description = "How fix version should be formatted", | ||
) | ||
@get:Optional | ||
abstract val fixVersionPattern: Property<String> | ||
|
||
@get:Input | ||
@get:Option( | ||
option = "fixVersionFieldId", | ||
description = "Field id for fix version in ClickUp", | ||
) | ||
@get:Optional | ||
abstract val fixVersionFieldId: Property<String> | ||
|
||
@get:Input | ||
@get:Option( | ||
option = "taskTag", | ||
description = "What tag should be used for tasks", | ||
) | ||
@get:Optional | ||
abstract val taskTag: Property<String> | ||
|
||
@TaskAction | ||
fun upload() { | ||
val currentBuildTag = fromJson(tagBuildFile.asFile.get()) | ||
val changelog = changelogFile.asFile.get().readText() | ||
val issues = | ||
Regex(issueNumberPattern.get()) | ||
.findAll(changelog) | ||
.mapTo(mutableSetOf()) { it.groupValues[0] } | ||
if (issues.isEmpty()) { | ||
logger.info("issues not found in the changelog, nothing will change") | ||
} else { | ||
val workQueue: WorkQueue = workerExecutor.noIsolation() | ||
workQueue.submitUpdateVersionIfPresent(currentBuildTag, issues) | ||
workQueue.submitSetTagIfPresent(issues) | ||
} | ||
} | ||
|
||
private fun WorkQueue.submitUpdateVersionIfPresent( | ||
currentBuildTag: Tag.Build, | ||
issues: Set<String>, | ||
) { | ||
if (fixVersionPattern.isPresent && fixVersionFieldId.isPresent) { | ||
val version = | ||
fixVersionPattern.get() | ||
.format( | ||
currentBuildTag.buildVersion, | ||
currentBuildTag.buildNumber, | ||
currentBuildTag.buildVariant, | ||
) | ||
val fieldId = fixVersionFieldId.get() | ||
submit(AddFixVersionWork::class.java) { parameters -> | ||
parameters.apiToken.set(apiTokenFile.asFile.get().readText()) | ||
parameters.issues.set(issues) | ||
parameters.version.set(version) | ||
parameters.fieldId.set(fieldId) | ||
} | ||
} | ||
} | ||
|
||
private fun WorkQueue.submitSetTagIfPresent(issues: Set<String>) { | ||
if (taskTag.isPresent) { | ||
val tagName = taskTag.get() | ||
submit(AddTagToTaskWork::class.java) { parameters -> | ||
parameters.apiToken.set(apiTokenFile.asFile.get().readText()) | ||
parameters.issues.set(issues) | ||
parameters.tagName.set(tagName) | ||
} | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
.../plugin/src/main/java/ru/kode/android/build/publish/plugin/task/clickup/api/ClickUpApi.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package ru.kode.android.build.publish.plugin.task.clickup.api | ||
|
||
import retrofit2.Call | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
import retrofit2.http.Path | ||
import ru.kode.android.build.publish.plugin.task.clickup.entity.AddFieldToTaskRequest | ||
|
||
interface ClickUpApi { | ||
@POST("v2/task/{task_id}/tag/{tag_name}") | ||
fun addTagToTask( | ||
@Path("task_id") taskId: String, | ||
@Path("tag_name") tagName: String, | ||
): Call<Unit> | ||
|
||
@POST("v2/task/{task_id}/field/{field_id}") | ||
fun addFieldToTask( | ||
@Path("task_id") taskId: String, | ||
@Path("field_id") fieldId: String, | ||
@Body request: AddFieldToTaskRequest, | ||
): Call<Unit> | ||
} |
9 changes: 9 additions & 0 deletions
9
...in/java/ru/kode/android/build/publish/plugin/task/clickup/entity/AddFieldToTaskRequest.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package ru.kode.android.build.publish.plugin.task.clickup.entity | ||
|
||
import com.squareup.moshi.JsonClass | ||
|
||
@JsonClass(generateAdapter = true) | ||
@Suppress("ConstructorParameterNaming") // network model | ||
data class AddFieldToTaskRequest( | ||
val value: String, | ||
) |
Oops, something went wrong.