Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/main/scala/codecheck/github/models/Repository.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package codecheck.github.models

import java.net.URL
import org.json4s.JValue
import codecheck.github.utils.ToDo

Expand Down Expand Up @@ -46,7 +47,19 @@ case class RepositoryListOption(
direction: SortDirection = SortDirection.asc
)

/*case*/ class RepositoryInput extends ToDo
case class RepositoryInput(
name: String,
description: Option[String] = None,
homepage: Option[URL] = None,
`private`: Boolean = false,
has_issues: Boolean = true,
has_wiki: Boolean = true,
has_downloads: Boolean = true,
team_id: Option[Int] = None,
auto_init: Boolean = false,
gitignore_template: Option[String] = None,
license_template: Option[String] = None
) extends AbstractInput

case class Repository(value: JValue) extends AbstractJson(value) {
def id = get("id").toLong
Expand All @@ -65,4 +78,4 @@ case class Permissions(value: JValue) extends AbstractJson(value) {
def admin = boolean("admin")
def push = boolean("push")
def pull = boolean("pull")
}
}
10 changes: 7 additions & 3 deletions src/main/scala/codecheck/github/operations/RepositoryOp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ trait RepositoryOp {
}
}
}
def listOwnRepositories(option: RepositoryListOption = RepositoryListOption()): Future[List[Repository]] =
def listOwnRepositories(option: RepositoryListOption = RepositoryListOption()): Future[List[Repository]] =
doList("/user/repos", option)

def listUserRepositories(user: String, option: RepositoryListOption = RepositoryListOption()): Future[List[Repository]] =
def listUserRepositories(user: String, option: RepositoryListOption = RepositoryListOption()): Future[List[Repository]] =
doList(s"/users/$user/repos", option)

def listOrgRepositories(org: String, option: RepositoryListOption = RepositoryListOption()): Future[List[Repository]] =
Expand All @@ -51,7 +51,11 @@ trait RepositoryOp {
}
}

def createRepository(input: RepositoryInput): Future[Repository] = ToDo[Future[Repository]]
def createUserRepository(input: RepositoryInput): Future[Repository] = {
exec("POST", s"/user/repos", input.value).map { res =>
new Repository(res.body)
}
}
def updateRepository(input: RepositoryInput): Future[Repository] = ToDo[Future[Repository]]

/*
Expand Down
29 changes: 27 additions & 2 deletions src/test/scala/RepositoryOpSpec.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import org.scalatest.path.FunSpec
import codecheck.github.exceptions.NotFoundException
import codecheck.github.models.Repository
import codecheck.github.models.RepositoryInput
import codecheck.github.exceptions.GitHubAPIException
import codecheck.github.exceptions.NotFoundException
import scala.concurrent.Await
import scala.concurrent.ExecutionContext.Implicits.global

class RepositoryOpSpec extends FunSpec with Constants
class RepositoryOpSpec extends FunSpec with Constants
{

describe("listOwnRepositories") {
Expand Down Expand Up @@ -45,7 +46,7 @@ class RepositoryOpSpec extends FunSpec with Constants
assert(list.size > 0)
}


}
describe("getRepository") {
it("should succeed") {
Expand All @@ -61,4 +62,28 @@ class RepositoryOpSpec extends FunSpec with Constants
assert(Await.result(api.getRepository(organization, repoInvalid), TIMEOUT).isEmpty)
}
}

/*
describe("createUserRepository") {
val createRepoName = "create-repo-name"
it("should succeed") {
val input = RepositoryInput(name = createRepoName)
val repo = Await.result(api.createUserRepository(input), TIMEOUT)
assert(repo.owner.login == user)
assert(repo.name == "create-repo-test")
}
it("should fail with existing repository name") {
val input = RepositoryInput(name = createRepoName)
try {
val repo = Await.result(api.createUserRepository(input), TIMEOUT)
fail
} catch {
case e: GitHubAPIException =>
assert(e.error.errors.head.field == "name")
case e: Throwable =>
fail
}
}
}
*/
}