From 98276135d01fa3a7a2f366faa333879bccf5d992 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 30 Sep 2020 15:47:45 +0600 Subject: [PATCH 1/6] start 0.1.1 --- CHANGELOG.md | 7 +++++++ gradle.properties | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000000..4288299184c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +## 0.1.0 + +Inited :) + +### 0.1.1 diff --git a/gradle.properties b/gradle.properties index f669fa56528..fad12944bb9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,4 +14,4 @@ gradle_bintray_plugin_version=1.8.5 uuidVersion=0.2.2 group=dev.inmo -version=0.1.0 +version=0.1.1 From 083287a77b99b3d6fdfbf80c5a161f81e9204089 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 30 Sep 2020 15:56:24 +0600 Subject: [PATCH 2/6] doWithAll for readstandardcrudrepo --- CHANGELOG.md | 4 ++++ .../repos/pagination/PaginationExtensions.kt | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/PaginationExtensions.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 4288299184c..3e8ba924460 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,3 +5,7 @@ Inited :) ### 0.1.1 + +* `Repos` + * `Common` + * Extension `ReadStandardCRUDRepo#doWithAll` has been added diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/PaginationExtensions.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/PaginationExtensions.kt new file mode 100644 index 00000000000..38d351c21ef --- /dev/null +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/PaginationExtensions.kt @@ -0,0 +1,15 @@ +package dev.inmo.micro_utils.repos.pagination + +import dev.inmo.micro_utils.pagination.doWithPagination +import dev.inmo.micro_utils.pagination.nextPageIfNotEmpty +import dev.inmo.micro_utils.repos.ReadStandardCRUDRepo + +suspend inline fun > REPO.doWithAll( + block: (List) -> Unit +) { + doWithPagination { + getByPagination(it).also { + block(it.results) + }.nextPageIfNotEmpty() + } +} From 04e6c7b5744e00b8b809afdf4c6d4ea6f2d6681e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 2 Oct 2020 19:13:04 +0600 Subject: [PATCH 3/6] add doForAll and getAll for every type of repo --- CHANGELOG.md | 5 ++- .../micro_utils/repos/StandartKeyValueRepo.kt | 4 +- .../pagination/CRUDPaginationExtensions.kt | 31 ++++++++++++++ .../KeyValuePaginationExtensions.kt | 31 ++++++++++++++ .../OneToManyPaginationExtensions.kt | 41 +++++++++++++++++++ .../repos/pagination/PaginationExtensions.kt | 15 ------- 6 files changed, 109 insertions(+), 18 deletions(-) create mode 100644 repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CRUDPaginationExtensions.kt create mode 100644 repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt create mode 100644 repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt delete mode 100644 repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/PaginationExtensions.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e8ba924460..f56c225cb53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,4 +8,7 @@ Inited :) * `Repos` * `Common` - * Extension `ReadStandardCRUDRepo#doWithAll` has been added + * Extensions `doForAll` and `getAll` were added for all current types of repos: + * `ReadStandardCRUDRepo` + * `StandardReadKeyValueRepo` + * `OneToManyReadKeyValueRepo` diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartKeyValueRepo.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartKeyValueRepo.kt index b3a1a4637f7..6cc2c6a03f7 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartKeyValueRepo.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartKeyValueRepo.kt @@ -6,8 +6,8 @@ import kotlinx.coroutines.flow.Flow interface StandardReadKeyValueRepo : Repo { suspend fun get(k: Key): Value? - suspend fun values(pagination: Pagination, reversed: Boolean): PaginationResult - suspend fun keys(pagination: Pagination, reversed: Boolean): PaginationResult + suspend fun values(pagination: Pagination, reversed: Boolean = false): PaginationResult + suspend fun keys(pagination: Pagination, reversed: Boolean = false): PaginationResult suspend fun contains(key: Key): Boolean suspend fun count(): Long } diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CRUDPaginationExtensions.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CRUDPaginationExtensions.kt new file mode 100644 index 00000000000..e626262f229 --- /dev/null +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/CRUDPaginationExtensions.kt @@ -0,0 +1,31 @@ +package dev.inmo.micro_utils.repos.pagination + +import dev.inmo.micro_utils.pagination.* +import dev.inmo.micro_utils.repos.ReadStandardCRUDRepo + +suspend inline fun > REPO.doForAll( + @Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") + methodCaller: suspend REPO.(Pagination) -> PaginationResult, + block: (List) -> Unit +) { + doWithPagination { + methodCaller(it).also { + block(it.results) + }.nextPageIfNotEmpty() + } +} + +suspend inline fun > REPO.doForAll( + block: (List) -> Unit +) = doForAll({ getByPagination(it) }, block) + +suspend inline fun > REPO.getAll( + @Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") + methodCaller: suspend REPO.(Pagination) -> PaginationResult +): List { + val resultList = mutableListOf() + doForAll(methodCaller) { + resultList.addAll(it) + } + return resultList +} diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt new file mode 100644 index 00000000000..8bd84afdce0 --- /dev/null +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/KeyValuePaginationExtensions.kt @@ -0,0 +1,31 @@ +package dev.inmo.micro_utils.repos.pagination + +import dev.inmo.micro_utils.pagination.* +import dev.inmo.micro_utils.repos.* + +suspend inline fun > REPO.doForAll( + @Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") + methodCaller: suspend REPO.(Pagination) -> PaginationResult, + block: (List>) -> Unit +) { + doWithPagination { + methodCaller(it).also { keys -> + block(keys.results.mapNotNull { key -> get(key) ?.let { value -> key to value } }) + }.nextPageIfNotEmpty() + } +} + +suspend inline fun > REPO.doForAll( + block: (List>) -> Unit +) = doForAll({ keys(it, false) }, block) + +suspend inline fun > REPO.getAll( + @Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") + methodCaller: suspend REPO.(Pagination) -> PaginationResult +): List> { + val resultList = mutableListOf>() + doForAll(methodCaller) { + resultList.addAll(it) + } + return resultList +} diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt new file mode 100644 index 00000000000..313721d170b --- /dev/null +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/OneToManyPaginationExtensions.kt @@ -0,0 +1,41 @@ +package dev.inmo.micro_utils.repos.pagination + +import dev.inmo.micro_utils.pagination.* +import dev.inmo.micro_utils.repos.* + +suspend inline fun > REPO.doForAll( + @Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") + methodCaller: suspend REPO.(Pagination) -> PaginationResult, + block: (List>>) -> Unit +) { + doWithPagination { + methodCaller(it).also { keys -> + block( + keys.results.mapNotNull { key -> + val values = mutableListOf() + doWithPagination { + get(key, it).also { + values.addAll(it.results) + }.nextPageIfNotEmpty() + } + key to values + } + ) + }.nextPageIfNotEmpty() + } +} + +suspend inline fun > REPO.doForAll( + block: (List>>) -> Unit +) = doForAll({ keys(it, false) }, block) + +suspend inline fun > REPO.getAll( + @Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") + methodCaller: suspend REPO.(Pagination) -> PaginationResult +): List>> { + val resultList = mutableListOf>>() + doForAll(methodCaller) { + resultList.addAll(it) + } + return resultList +} diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/PaginationExtensions.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/PaginationExtensions.kt deleted file mode 100644 index 38d351c21ef..00000000000 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/pagination/PaginationExtensions.kt +++ /dev/null @@ -1,15 +0,0 @@ -package dev.inmo.micro_utils.repos.pagination - -import dev.inmo.micro_utils.pagination.doWithPagination -import dev.inmo.micro_utils.pagination.nextPageIfNotEmpty -import dev.inmo.micro_utils.repos.ReadStandardCRUDRepo - -suspend inline fun > REPO.doWithAll( - block: (List) -> Unit -) { - doWithPagination { - getByPagination(it).also { - block(it.results) - }.nextPageIfNotEmpty() - } -} From 17c6d4a889701ac81b3b8dfe2d8c49e8cfa1086e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 2 Oct 2020 20:45:16 +0600 Subject: [PATCH 4/6] add github release mechanism --- .gitignore | 2 ++ build.gradle | 2 ++ changelog_info_retriever | 27 +++++++++++++++++++++++++++ github_release.gradle | 27 +++++++++++++++++++++++++++ gradle.properties | 1 + 5 files changed, 59 insertions(+) create mode 100644 changelog_info_retriever create mode 100644 github_release.gradle diff --git a/.gitignore b/.gitignore index 5dc177e2715..2542547c968 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ settings.xml .gradle/ build/ out/ + +secret.gradle diff --git a/build.gradle b/build.gradle index 8be9aaaa6a0..4e79f30a28a 100644 --- a/build.gradle +++ b/build.gradle @@ -9,6 +9,7 @@ buildscript { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$gradle_bintray_plugin_version" + classpath "com.github.breadmoirai:github-release:$github_release_plugin_version" } } @@ -20,3 +21,4 @@ repositories { } apply from: "./extensions.gradle" +apply from: "./github.gradle" diff --git a/changelog_info_retriever b/changelog_info_retriever new file mode 100644 index 00000000000..00c4a482060 --- /dev/null +++ b/changelog_info_retriever @@ -0,0 +1,27 @@ +#!/bin/bash + +function parse() { + version=$1 + + read -r + while [ -z "`echo $REPLY | grep -e "^#\+ $version"`" ] + do + read -r + done + + read -r + while [ -z "`echo $REPLY | grep -e "^#\+"`" ] + do + echo "$REPLY" + read -r + done +} + +version=$1 +file=$2 + +if [ -n "$file" ]; then + parse $version < "$file" +else + parse $version +fi diff --git a/github_release.gradle b/github_release.gradle new file mode 100644 index 00000000000..60efbdcc981 --- /dev/null +++ b/github_release.gradle @@ -0,0 +1,27 @@ +private String getCurrentVersionChangelog() { + OutputStream changelogDataOS = new ByteArrayOutputStream() + exec { + standardOutput = changelogDataOS + commandLine './changelog_info_retriever', "$library_version", 'CHANGELOG.md' + } + + return changelogDataOS.toString().trim() +} + +if (new File(projectDir, "secret.gradle").exists()) { + apply from: './secret.gradle' + apply plugin: "com.github.breadmoirai.github-release" + + githubRelease { + token "${project.property('GITHUB_RELEASE_TOKEN')}" + + owner "InsanusMokrassar" + repo "MicroUtils" + + tagName "$library_version" + releaseName "$library_version" + targetCommitish "$library_version" + + body getCurrentVersionChangelog() + } +} diff --git a/gradle.properties b/gradle.properties index fad12944bb9..3eeb5c15579 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,6 +10,7 @@ ktor_version=1.4.1 klockVersion=1.12.1 gradle_bintray_plugin_version=1.8.5 +github_release_plugin_version=2.2.12 uuidVersion=0.2.2 From 5f9cb25e18043c7319ae87b65ef1c71e454328c0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 3 Oct 2020 01:00:44 +0600 Subject: [PATCH 5/6] Update build.gradle --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 48450a9390c..a5445f8c503 100644 --- a/build.gradle +++ b/build.gradle @@ -22,4 +22,4 @@ repositories { } apply from: "./extensions.gradle" -apply from: "./github.gradle" +apply from: "./github_release.gradle" From 9824bf4297c7a3304c330c1cbd3d485a2c5aa330 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 3 Oct 2020 15:46:18 +0600 Subject: [PATCH 6/6] fix changelog retriever file --- changelog_info_retriever | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) mode change 100644 => 100755 changelog_info_retriever diff --git a/changelog_info_retriever b/changelog_info_retriever old mode 100644 new mode 100755 index 00c4a482060..8980f88ef6f --- a/changelog_info_retriever +++ b/changelog_info_retriever @@ -1,20 +1,17 @@ #!/bin/bash function parse() { - version=$1 + version=$1 - read -r - while [ -z "`echo $REPLY | grep -e "^#\+ $version"`" ] - do - read -r - done + while IFS= read -r line && [ -z "`echo $line | grep -e "^#\+ $version"`" ] + do + : # do nothing + done - read -r - while [ -z "`echo $REPLY | grep -e "^#\+"`" ] - do - echo "$REPLY" - read -r - done + while IFS= read -r line && [ -z "`echo $line | grep -e "^#\+"`" ] + do + echo "$line" + done } version=$1