mirror of
https://github.com/jlengrand/kotlin-samples.git
synced 2026-03-10 08:31:22 +00:00
A small utility to add the Hacktoberfest to your repositories
This commit is contained in:
71
kotlin-github-hacktoberfest-tags/.gitignore
vendored
Normal file
71
kotlin-github-hacktoberfest-tags/.gitignore
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
.DS_Store
|
||||
.idea/shelf
|
||||
/confluence/target
|
||||
/dependencies/repo
|
||||
/android.tests.dependencies
|
||||
/dependencies/android.tests.dependencies
|
||||
/dist
|
||||
/local
|
||||
/gh-pages
|
||||
/ideaSDK
|
||||
/clionSDK
|
||||
/android-studio/sdk
|
||||
out/
|
||||
/tmp
|
||||
/intellij
|
||||
workspace.xml
|
||||
*.versionsBackup
|
||||
/idea/testData/debugger/tinyApp/classes*
|
||||
/jps-plugin/testData/kannotator
|
||||
/js/js.translator/testData/out/
|
||||
/js/js.translator/testData/out-min/
|
||||
/js/js.translator/testData/out-pir/
|
||||
.gradle/
|
||||
build/
|
||||
!**/src/**/build
|
||||
!**/test/**/build
|
||||
*.iml
|
||||
!**/testData/**/*.iml
|
||||
.idea/libraries/Gradle*.xml
|
||||
.idea/libraries/Maven*.xml
|
||||
.idea/artifacts/PILL_*.xml
|
||||
.idea/artifacts/KotlinPlugin.xml
|
||||
.idea/modules
|
||||
.idea/runConfigurations/JPS_*.xml
|
||||
.idea/runConfigurations/PILL_*.xml
|
||||
.idea/runConfigurations/_FP_*.xml
|
||||
.idea/runConfigurations/_MT_*.xml
|
||||
.idea/libraries
|
||||
.idea/modules.xml
|
||||
.idea/gradle.xml
|
||||
.idea/compiler.xml
|
||||
.idea/inspectionProfiles/profiles_settings.xml
|
||||
.idea/.name
|
||||
.idea/artifacts/dist_auto_*
|
||||
.idea/artifacts/dist.xml
|
||||
.idea/artifacts/ideaPlugin.xml
|
||||
.idea/artifacts/kotlinc.xml
|
||||
.idea/artifacts/kotlin_compiler_jar.xml
|
||||
.idea/artifacts/kotlin_plugin_jar.xml
|
||||
.idea/artifacts/kotlin_jps_plugin_jar.xml
|
||||
.idea/artifacts/kotlin_daemon_client_jar.xml
|
||||
.idea/artifacts/kotlin_imports_dumper_compiler_plugin_jar.xml
|
||||
.idea/artifacts/kotlin_main_kts_jar.xml
|
||||
.idea/artifacts/kotlin_compiler_client_embeddable_jar.xml
|
||||
.idea/artifacts/kotlin_reflect_jar.xml
|
||||
.idea/artifacts/kotlin_stdlib_js_ir_*
|
||||
.idea/artifacts/kotlin_test_js_ir_*
|
||||
.idea/artifacts/kotlin_stdlib_wasm_*
|
||||
.idea/jarRepositories.xml
|
||||
.idea/csv-plugin.xml
|
||||
.idea/libraries-with-intellij-classes.xml
|
||||
node_modules/
|
||||
.rpt2_cache/
|
||||
libraries/tools/kotlin-test-js-runner/lib/
|
||||
local.properties
|
||||
buildSrcTmp/
|
||||
distTmp/
|
||||
outTmp/
|
||||
/test.output
|
||||
/kotlin-native/dist
|
||||
kotlin-ide/
|
||||
21
kotlin-github-hacktoberfest-tags/build.gradle.kts
Normal file
21
kotlin-github-hacktoberfest-tags/build.gradle.kts
Normal file
@@ -0,0 +1,21 @@
|
||||
plugins {
|
||||
kotlin("jvm") version "1.5.31"
|
||||
kotlin("plugin.serialization") version "1.5.31"
|
||||
}
|
||||
|
||||
group = "nl.jlengrand"
|
||||
version = "1.0-SNAPSHOT"
|
||||
val ktorVersion = "1.6.4"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib"))
|
||||
|
||||
implementation("io.ktor:ktor-client-core:$ktorVersion")
|
||||
implementation("io.ktor:ktor-client-cio:$ktorVersion")
|
||||
implementation("io.ktor:ktor-client-serialization:$ktorVersion")
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.features.json.*
|
||||
import io.ktor.client.features.json.serializer.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.http.*
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
suspend fun main(){
|
||||
val user = "adyen-examples"
|
||||
val repoType = RepoType.orgs
|
||||
|
||||
val repositories = getRepos(user, repoType)
|
||||
repositories.forEach { applyTag(it.fullName) }
|
||||
|
||||
client.close()
|
||||
}
|
||||
|
||||
val token: String = System.getenv("GITHUB_HACKTOBERFEST_TOKEN")
|
||||
val client = HttpClient(){ install(JsonFeature) {
|
||||
serializer = KotlinxSerializer(kotlinx.serialization.json.Json {
|
||||
prettyPrint = true
|
||||
isLenient = true
|
||||
ignoreUnknownKeys = true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
enum class RepoType { users, orgs }
|
||||
|
||||
@Serializable
|
||||
data class Tags(val names : List<String>){
|
||||
private val hacktoberfest = "hacktoberfest"
|
||||
fun isFun() = this.names.contains(hacktoberfest)
|
||||
fun addHacktoberfest() = if (isFun()) this else Tags(this.names + hacktoberfest)
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class Repository(val id : Long, @SerialName("full_name") val fullName : String )
|
||||
|
||||
suspend fun getRepos(owner: String, repoType: RepoType): List<Repository> {
|
||||
val repos: List<Repository> = client.get("https://api.github.com/$repoType/${owner}/repos?type=owner&sort=updated&per_page=10"){
|
||||
headers {
|
||||
append(HttpHeaders.Accept, "application/vnd.github.mercy-preview+json")
|
||||
}
|
||||
}
|
||||
return repos
|
||||
}
|
||||
|
||||
suspend fun applyTag(ownerAndRepo: String){
|
||||
val tags = readTags(ownerAndRepo)
|
||||
if(!tags.isFun()) {
|
||||
println("Applying tag to $ownerAndRepo")
|
||||
println(setTags(ownerAndRepo, tags.addHacktoberfest()))
|
||||
}
|
||||
else println("Tag already found. Skipping $ownerAndRepo")
|
||||
}
|
||||
|
||||
suspend fun readTags(ownerAndRepo: String): Tags {
|
||||
val tags: Tags = client.get("https://api.github.com/repos/$ownerAndRepo/topics"){
|
||||
headers {
|
||||
append(HttpHeaders.Accept, "application/vnd.github.mercy-preview+json")
|
||||
}
|
||||
}
|
||||
return tags
|
||||
}
|
||||
|
||||
suspend fun setTags(ownerAndRepo: String, tags: Tags): Tags {
|
||||
val newTags: Tags = client.put("https://api.github.com/repos/$ownerAndRepo/topics"){
|
||||
headers {
|
||||
append(HttpHeaders.Accept, "application/vnd.github.mercy-preview+json")
|
||||
append(HttpHeaders.ContentType, ContentType.Application.Json)
|
||||
append(HttpHeaders.Authorization, "token $token")
|
||||
}
|
||||
body = tags
|
||||
}
|
||||
return newTags
|
||||
}
|
||||
@@ -24,19 +24,13 @@ external fun <T> sorted(a: Array<T>): Boolean
|
||||
fun main() {
|
||||
// startFirebase()
|
||||
window.onload = {
|
||||
val firebaseConfig: Json = json()
|
||||
val fire = initializeApp(firebaseConfig)
|
||||
console.log(fire)
|
||||
console.log(sorted(arrayOf(1, 2, 3)))
|
||||
startFirebase();
|
||||
document.body?.sayHello() }
|
||||
}
|
||||
|
||||
fun startFirebase(){
|
||||
val firebaseConfig: Json = json(
|
||||
)
|
||||
|
||||
val fire = initializeApp(firebaseConfig)
|
||||
console.log(fire)
|
||||
}
|
||||
|
||||
fun Node.sayHello() {
|
||||
append {
|
||||
div {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
@file:JsQualifier("firebase")
|
||||
@file:JsNonModule
|
||||
@file:Suppress("INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS")
|
||||
|
||||
import kotlin.js.*
|
||||
|
||||
Submodule sample-firebase/test updated: a2814b311e...e5d14b0654
@@ -1,2 +1,3 @@
|
||||
rootProject.name = "kotlin-samples"
|
||||
include("sample-firebase")
|
||||
include("sample-firebase")
|
||||
include("kotlin-github-hacktoberfest-tags")
|
||||
|
||||
Reference in New Issue
Block a user