Skip to content

Commit

Permalink
Changed: removed duplicate GitHub repo type and changed its name and …
Browse files Browse the repository at this point in the history
…field names
  • Loading branch information
kevin-lee committed Feb 12, 2021
1 parent 64bd8ff commit 63dea9a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 37 deletions.
10 changes: 4 additions & 6 deletions src/main/scala/kevinlee/github/GitHubApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ object GitHubApi {
tagName: Git.TagName,
repo: GitHub.GitHubRepoWithAuth,
): F[Either[GitHubError, Option[GitHubRelease.Response]]] = {
val url = s"$baseUrl/repos/${repo.gitHubRepo.org.org}/${repo.gitHubRepo.repo.repo}/releases/tags/${tagName.value}"
val url = s"$baseUrl/repos/${repo.toRepoNameString}/releases/tags/${tagName.value}"
val httpRequest = HttpRequest.withHeaders(
HttpRequest.Method.get,
HttpRequest.Uri(url),
Expand All @@ -213,7 +213,7 @@ object GitHubApi {
params: GitHubRelease.CreateRequestParams,
repo: GitHub.GitHubRepoWithAuth,
): F[Either[GitHubError, Option[GitHubRelease.Response]]] = {
val url = s"$baseUrl/repos/${repo.gitHubRepo.org.org}/${repo.gitHubRepo.repo.repo}/releases"
val url = s"$baseUrl/repos/${repo.toRepoNameString}/releases"
val httpRequest = HttpRequest
.withHeadersAndJsonBody[GitHubRelease.CreateRequestParams](
HttpRequest.Method.post,
Expand All @@ -237,8 +237,7 @@ object GitHubApi {
params: GitHubRelease.UpdateRequestParams,
repo: GitHub.GitHubRepoWithAuth,
): F[Either[GitHubError, Option[GitHubRelease.Response]]] = {
val url =
s"$baseUrl/repos/${repo.gitHubRepo.org.org}/${repo.gitHubRepo.repo.repo}/releases/${params.releaseId.releaseId}"
val url = s"$baseUrl/repos/${repo.toRepoNameString}/releases/${params.releaseId.releaseId}"
val httpRequest = HttpRequest
.withHeadersAndJsonBody[GitHubRelease.UpdateRequestParams](
HttpRequest.Method.patch,
Expand All @@ -263,8 +262,7 @@ object GitHubApi {
params: GitHubRelease.UploadAssetParams,
repo: GitHub.GitHubRepoWithAuth,
)(implicit ec: ExecutionContext): F[Either[GitHubError, (File, Option[GitHubRelease.Asset])]] = {
val url =
s"$baseUploadUrl/repos/${repo.gitHubRepo.org.org}/${repo.gitHubRepo.repo.repo}/releases/${params.releaseId.releaseId}/assets"
val url = s"$baseUploadUrl/repos/${repo.toRepoNameString}/releases/${params.releaseId.releaseId}/assets"
val httpRequest = HttpRequest
.withHeadersParamsAndFileBody(
HttpRequest.Method.post,
Expand Down
45 changes: 24 additions & 21 deletions src/main/scala/kevinlee/github/data/GitHub.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,45 @@ import kevinlee.http.HttpRequest
/** @author Kevin Lee
* @since 2019-03-09
*/
@SuppressWarnings(Array(
"org.wartremover.warts.ExplicitImplicitTypes",
"org.wartremover.warts.ImplicitConversion",
"org.wartremover.warts.ImplicitParameter",
"org.wartremover.warts.PublicInference",
))
@SuppressWarnings(
Array(
"org.wartremover.warts.ExplicitImplicitTypes",
"org.wartremover.warts.ImplicitConversion",
"org.wartremover.warts.ImplicitParameter",
"org.wartremover.warts.PublicInference",
)
)
object GitHub {

final case class OAuthToken(token: String) extends AnyVal {
override def toString: String = "***Protected***"
}

@newtype case class RepoOrg(org: String)
@newtype case class RepoName(name: String)

final case class Repo(repoOrg: RepoOrg, repoName: RepoName)

object Repo {
def repoNameString(repo: Repo): String = s"${repo.repoOrg.org}/${repo.repoName.name}"
}

@newtype case class Changelog(changelog: String)

@newtype case class ChangelogLocation(changeLogLocation: String)

final case class GitHubRepo(
org: GitHubRepo.Org,
repo: GitHubRepo.Repo,
final case class Repo(
org: Repo.Org,
name: Repo.Name,
)

object GitHubRepo {
object Repo {

@newtype case class Org(org: String)

@newtype case class Repo(repo: String)
@newtype case class Name(name: String)

def repoNameString(repo: Repo): String = s"${repo.org.org}/${repo.name.name}"

implicit final class RepoOps(val repo: Repo) extends AnyVal {
def toRepoNameString: String = Repo.repoNameString(repo)
}

}

final case class GitHubRepoWithAuth(
gitHubRepo: GitHubRepo,
gitHubRepo: Repo,
accessToken: Option[GitHubRepoWithAuth.AccessToken],
)

Expand All @@ -72,6 +71,10 @@ object GitHub {
)
}

implicit final class RepoOps(val repo: GitHubRepoWithAuth) extends AnyVal {
def toRepoNameString: String = Repo.repoNameString(repo.gitHubRepo)
}

}

final case class User(
Expand Down
20 changes: 10 additions & 10 deletions src/main/scala/kevinlee/sbt/devoops/DevOopsGitReleasePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ object DevOopsGitReleasePlugin extends AutoPlugin {
repoUrl.repoUrl.split(":").last.split("/")
names.takeRight(2) match {
case Array(org, name) =>
GitHub.Repo(GitHub.RepoOrg(org), GitHub.RepoName(name.stripSuffix(".git"))).asRight
GitHub.Repo(GitHub.Repo.Org(org), GitHub.Repo.Name(name.stripSuffix(".git"))).asRight
case _ =>
GitHubError.invalidGitHubRepoUrl(repoUrl).asLeft
}
Expand Down Expand Up @@ -475,16 +475,16 @@ object DevOopsGitReleasePlugin extends AutoPlugin {
GitHubRelease.Prerelease.no,
),
GitHub.GitHubRepoWithAuth(
GitHub.GitHubRepo(
GitHub.Repo(
GitHub
.GitHubRepo
.Repo
.Org(
repo.repoOrg.org
repo.org.org
),
GitHub
.GitHubRepo
.Repo(
repo.repoName.name
.Repo
.Name(
repo.name.name
),
),
GitHub.GitHubRepoWithAuth.AccessToken(oAuthToken.token).some,
Expand Down Expand Up @@ -525,9 +525,9 @@ object DevOopsGitReleasePlugin extends AutoPlugin {
)(r => List(s"Get GitHub repo org and name: ${GitHub.Repo.repoNameString(r)}"))

repoWithAuth = GitHub.GitHubRepoWithAuth(
GitHub.GitHubRepo(
GitHub.GitHubRepo.Org(repo.repoOrg.org),
GitHub.GitHubRepo.Repo(repo.repoName.name),
GitHub.Repo(
GitHub.Repo.Org(repo.org.org),
GitHub.Repo.Name(repo.name.name),
),
GitHub.GitHubRepoWithAuth.AccessToken(oAuthToken.token).some,
)
Expand Down

0 comments on commit 63dea9a

Please sign in to comment.