Browse Source

change id properties - require a value in all data models

main
James Fenn 1 month ago
parent
commit
6a52265432
21 changed files with 49 additions and 52 deletions
  1. +5
    -3
      README.md
  2. +1
    -1
      example-android/src/main/java/me/jfenn/gitrest/example/android/RepoAdapter.kt
  3. +1
    -1
      example-js/index.html
  4. +1
    -1
      example-jvm/src/main/java/me/jfenn/gitrest/example/jvm/Main.kt
  5. +1
    -1
      example-kotlinbrowser/src/main/kotlin/Main.kt
  6. +1
    -1
      gitrest/src/commonMain/kotlin/me/jfenn/gitrest/impl/gitea/model/GiteaRepo.kt
  7. +4
    -3
      gitrest/src/commonMain/kotlin/me/jfenn/gitrest/impl/gitea/model/GiteaUser.kt
  8. +1
    -1
      gitrest/src/commonMain/kotlin/me/jfenn/gitrest/impl/github/model/GithubLicense.kt
  9. +1
    -1
      gitrest/src/commonMain/kotlin/me/jfenn/gitrest/impl/github/model/GithubRepo.kt
  10. +1
    -1
      gitrest/src/commonMain/kotlin/me/jfenn/gitrest/impl/github/model/GithubUser.kt
  11. +1
    -1
      gitrest/src/commonMain/kotlin/me/jfenn/gitrest/impl/gitlab/model/GitlabLicense.kt
  12. +1
    -1
      gitrest/src/commonMain/kotlin/me/jfenn/gitrest/impl/gitlab/model/GitlabRepo.kt
  13. +1
    -1
      gitrest/src/commonMain/kotlin/me/jfenn/gitrest/impl/gitlab/model/GitlabUser.kt
  14. +13
    -3
      gitrest/src/commonMain/kotlin/me/jfenn/gitrest/model/DelegateResource.kt
  15. +0
    -1
      gitrest/src/commonMain/kotlin/me/jfenn/gitrest/model/License.kt
  16. +4
    -4
      gitrest/src/commonMain/kotlin/me/jfenn/gitrest/model/ProviderString.kt
  17. +3
    -14
      gitrest/src/commonMain/kotlin/me/jfenn/gitrest/model/Repo.kt
  18. +0
    -1
      gitrest/src/commonMain/kotlin/me/jfenn/gitrest/model/User.kt
  19. +3
    -4
      gitrest/src/jsMain/kotlin/gitrest/js/License.kt
  20. +3
    -4
      gitrest/src/jsMain/kotlin/gitrest/js/Repo.kt
  21. +3
    -4
      gitrest/src/jsMain/kotlin/gitrest/js/User.kt

+ 5
- 3
README.md View File

@@ -142,8 +142,10 @@ The library relies on its own identifier format similar to the URI syntax used i

Not all data is complete for every provider/context. For example, Gitea doesn't provide any license information in their Repository model - so that data will obviously be missing.

Each data model contains `id`, `context`, and `provider` values with respect to the corresponding portions of the URI.

- `User`
- `login`: The username.
- `id`: The username.
- `name`: The full name of the user (defaults to `login` if unspecified).
- `url`: The webpage / user-facing link to the user's profile.
- `avatarUrl`: A link to the user's avatar / profile picture.
@@ -151,7 +153,7 @@ Not all data is complete for every provider/context. For example, Gitea doesn't
- `email`: The user's public email address.
- `bio`: The user bio.
- `Repo`
- `slug`: The repository slug identifier, i.e. `james/git-rest-wrapper`
- `id`: The repository slug identifier, i.e. `james/git-rest-wrapper`
- `description`: The repository/project description.
- `url`: The webpage / user-facing repository link.
- `websiteUrl`: The project website or homepage.
@@ -159,7 +161,7 @@ Not all data is complete for every provider/context. For example, Gitea doesn't
- `gitUrlSsh`: SSH uri for `git clone`
- `license`: Repository `License` object - may be incomplete/missing, depending on implementation.
- `License`
- `key`: The license identifier/key, according to SPDX
- `id`: The license identifier/key, according to SPDX
- `name`: A full user-facing license name (defaults to `key` if unspecified)
- `description`: A short summary / description of the license.
- `body`: The full license text.


+ 1
- 1
example-android/src/main/java/me/jfenn/gitrest/example/android/RepoAdapter.kt View File

@@ -22,7 +22,7 @@ class RepoAdapter(
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val repo = items.getOrNull(position) ?: return

holder.title.text = repo.id?.id ?: "undefined"
holder.title.text = repo.id

holder.description.movementMethod = LinkMovementMethod()
holder.description.text = Html.fromHtml("""


+ 1
- 1
example-js/index.html View File

@@ -19,7 +19,7 @@
let delegate = new gitrest.RequestProvider();
delegate.getRepo("github@api.github.com:fennifith/Attribouter").then((repo) => {
console.log(repo);
document.getElementById("repoName").innerText = repo.slug;
document.getElementById("repoName").innerText = repo.id;
document.getElementById("repoDesc").innerText = repo.description;
document.getElementById("repoLink").href = repo.url;
document.getElementById("sshUrl").innerText = repo.gitUrlSsh;


+ 1
- 1
example-jvm/src/main/java/me/jfenn/gitrest/example/jvm/Main.kt View File

@@ -16,7 +16,7 @@ val delegate = RequestProviderDelegate(arrayOf(
suspend fun fetchRepository(repoId: String) {
delegate.getRepo(repoId)?.let {
println("""
${it.slug}:
${it.id}:
${it.description}
${it.url}
${it.websiteUrl}


+ 1
- 1
example-kotlinbrowser/src/main/kotlin/Main.kt View File

@@ -45,7 +45,7 @@ suspend fun fetchRepo(id: String) = delegate.getRepo(id)?.let { repo ->
document.body!!.append {
div {
h3 {
+(repo.slug ?: "")
+(repo.id)
}
p {
repo.url?.let { url ->


+ 1
- 1
gitrest/src/commonMain/kotlin/me/jfenn/gitrest/impl/gitea/model/GiteaRepo.kt View File

@@ -9,7 +9,7 @@ import me.jfenn.gitrest.util.OptionalStringSerializer
class GiteaRepo : Repo() {

@SerialName("full_name")
override val slug: String? = null
override var id: String = ""

@SerialName("description")
@Serializable(with = OptionalStringSerializer::class)


+ 4
- 3
gitrest/src/commonMain/kotlin/me/jfenn/gitrest/impl/gitea/model/GiteaUser.kt View File

@@ -9,14 +9,15 @@ import me.jfenn.gitrest.util.OptionalStringSerializer
class GiteaUser : User() {

@SerialName("login")
override val login: String? = null
override var id: String = ""

@SerialName("full_name")
@Serializable(with = OptionalStringSerializer::class)
override val name: String? = null

override val url: String? // hack to provide user URLs - Gitea's API doesn't provide an html_url field
get() = login?.let { login -> id?.context?.let { context -> "https://${context}/${login}" } }
// hack to provide user URLs - Gitea's API doesn't provide an html_url field
override val url: String?
get() = "https://${context}/${id}"

@SerialName("avatar_url")
override val avatarUrl: String? = null


+ 1
- 1
gitrest/src/commonMain/kotlin/me/jfenn/gitrest/impl/github/model/GithubLicense.kt View File

@@ -7,7 +7,7 @@ import kotlinx.serialization.Serializable
@Serializable
class GithubLicense : License() {
@SerialName("key")
override val key: String? = null
override var id: String = ""

@SerialName("name")
override val name: String? = null


+ 1
- 1
gitrest/src/commonMain/kotlin/me/jfenn/gitrest/impl/github/model/GithubRepo.kt View File

@@ -9,7 +9,7 @@ import me.jfenn.gitrest.util.OptionalStringSerializer
class GithubRepo : Repo() {

@SerialName("full_name")
override val slug: String? = null
override var id: String = ""

@SerialName("description")
@Serializable(with = OptionalStringSerializer::class)


+ 1
- 1
gitrest/src/commonMain/kotlin/me/jfenn/gitrest/impl/github/model/GithubUser.kt View File

@@ -9,7 +9,7 @@ import me.jfenn.gitrest.util.OptionalStringSerializer
class GithubUser : User() {

@SerialName("login")
override val login: String? = null
override var id: String = ""

@SerialName("name")
@Serializable(with = OptionalStringSerializer::class)


+ 1
- 1
gitrest/src/commonMain/kotlin/me/jfenn/gitrest/impl/gitlab/model/GitlabLicense.kt View File

@@ -8,7 +8,7 @@ import kotlinx.serialization.Serializable
class GitlabLicense : License() {

@SerialName("key")
override val key: String? = null
override var id: String = ""

@SerialName("nickname")
override val name: String? = null


+ 1
- 1
gitrest/src/commonMain/kotlin/me/jfenn/gitrest/impl/gitlab/model/GitlabRepo.kt View File

@@ -9,7 +9,7 @@ import me.jfenn.gitrest.util.OptionalStringSerializer
class GitlabRepo : Repo() {

@SerialName("path_with_namespace")
override val slug: String? = null
override var id: String = ""

@SerialName("description")
@Serializable(with = OptionalStringSerializer::class)


+ 1
- 1
gitrest/src/commonMain/kotlin/me/jfenn/gitrest/impl/gitlab/model/GitlabUser.kt View File

@@ -9,7 +9,7 @@ import me.jfenn.gitrest.util.OptionalStringSerializer
class GitlabUser : User() {

@SerialName("username")
override val login: String? = null
override var id: String = ""

@SerialName("name")
@Serializable(with = OptionalStringSerializer::class)


+ 13
- 3
gitrest/src/commonMain/kotlin/me/jfenn/gitrest/model/DelegateResource.kt View File

@@ -5,10 +5,20 @@ import kotlinx.serialization.Transient
open class DelegateResource {

@Transient
open var id: ProviderString? = null
open var id: String = ""
@Transient
open var context: String? = null
@Transient
open var provider: String = ""

@Transient val providerString: ProviderString get() = ProviderString(provider, context, id)

internal open fun setId(providerString: ProviderString) {
this.context = providerString.context
this.provider = providerString.provider

internal open fun setId(id: ProviderString) {
this.id = id
if (id.isBlank())
throw RuntimeException("GIT-REST: Malformed response, .id not provided in ${this::class.simpleName}, requested $providerString")
}

}

+ 0
- 1
gitrest/src/commonMain/kotlin/me/jfenn/gitrest/model/License.kt View File

@@ -1,7 +1,6 @@
package me.jfenn.gitrest.model

open class License : DelegateResource() {
open val key: String? = null
open val name: String? = null
open val description: String? = null
open val body: String? = null


+ 4
- 4
gitrest/src/commonMain/kotlin/me/jfenn/gitrest/model/ProviderString.kt View File

@@ -14,7 +14,7 @@ class ProviderString {

constructor(str: String) {
if (str.isEmpty())
throw RuntimeException("Attribouter - Empty ProviderString")
throw RuntimeException("GIT-REST: Empty ProviderString")

// TODO: parse URL as provider-string (split into context:id with no known provider) - partial support for HTTP and SSH uris wouldn't be bad (ignore `git` provider, strip off `*.git` from end of ids, etc...)

@@ -35,7 +35,7 @@ class ProviderString {
context = arr[1]
id = arr[2]
}
else -> throw RuntimeException("Attribouter - ProviderString with too many parts! '$str' Format: 'provider@context:id'")
else -> throw RuntimeException("GIT-REST: ProviderString with too many parts! '$str' Format: 'provider@context:id'")
}
}

@@ -44,12 +44,12 @@ class ProviderString {
}

override fun toString(): String {
return id
return "${toProviderString()}:$id"
}

override fun equals(other: Any?): Boolean {
return (other as? ProviderString)?.let {
provider == it.provider && id == it.id
provider == it.provider && context == it.context && id == it.id
} ?: super.equals(other)
}



+ 3
- 14
gitrest/src/commonMain/kotlin/me/jfenn/gitrest/model/Repo.kt View File

@@ -1,7 +1,6 @@
package me.jfenn.gitrest.model

open class Repo : DelegateResource() {
open val slug: String? = null
open val description: String? = null
open val url: String? = null
open val websiteUrl: String? = null
@@ -9,18 +8,8 @@ open class Repo : DelegateResource() {
open val gitUrlSsh: String? = null
open val license: License? = null

override fun setId(id: ProviderString) {
super.setId(id)
license?.apply {
key?.let { licenseKey ->
setId(
ProviderString(
provider = id.provider,
context = id.context,
id = licenseKey
)
)
}
}
override fun setId(providerString: ProviderString) {
super.setId(providerString)
license?.setId(providerString)
}
}

+ 0
- 1
gitrest/src/commonMain/kotlin/me/jfenn/gitrest/model/User.kt View File

@@ -1,7 +1,6 @@
package me.jfenn.gitrest.model

open class User : DelegateResource() {
open val login: String? = null
open val name: String? = null
open val url: String? = null
open val avatarUrl: String? = null


+ 3
- 4
gitrest/src/jsMain/kotlin/gitrest/js/License.kt View File

@@ -1,10 +1,9 @@
package gitrest.js

import me.jfenn.gitrest.model.ProviderString

class License(license: me.jfenn.gitrest.model.License) {
val id: ProviderString? = license.id
val key: String? = license.key
val id: String = license.id
val context: String? = license.context
val provider: String = license.provider
val name: String? = license.name
val description: String? = license.description
val body: String? = license.body


+ 3
- 4
gitrest/src/jsMain/kotlin/gitrest/js/Repo.kt View File

@@ -1,10 +1,9 @@
package gitrest.js

import me.jfenn.gitrest.model.ProviderString

class Repo(repo: me.jfenn.gitrest.model.Repo) {
val id: ProviderString? = repo.id
val slug: String? = repo.slug
val id: String = repo.id
val context: String? = repo.context
val provider: String = repo.provider
val description: String? = repo.description
val url: String? = repo.url
val websiteUrl: String? = repo.websiteUrl


+ 3
- 4
gitrest/src/jsMain/kotlin/gitrest/js/User.kt View File

@@ -1,10 +1,9 @@
package gitrest.js

import me.jfenn.gitrest.model.ProviderString

class User(user: me.jfenn.gitrest.model.User) {
val id: ProviderString? = user.id
val login: String? = user.login
val id: String = user.id
val context: String? = user.context
val provider: String = user.provider
val name: String? = user.name
val url: String? = user.url
val avatarUrl: String? = user.avatarUrl


Loading…
Cancel
Save