Skip to content

Commit

Permalink
Merge pull request #478 from alejandrohdezma/feature/default-branch
Browse files Browse the repository at this point in the history
Add information about repository's default branch
  • Loading branch information
alejandrohdezma committed Nov 7, 2022
2 parents 35edc5e + 702221c commit ca3a75e
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 31 deletions.
10 changes: 1 addition & 9 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# @DESCRIPTION@

[![][maven-badge]][maven] [![][steward-badge]][steward]

This plugin enables several settings automatically by downloading them from Github:

- `homepage`: Retrieved from the Github repository's information.
Expand Down Expand Up @@ -33,10 +31,4 @@ If you want to know more about all the plugin's features, please head on to [its

## Contributors for this project

@CONTRIBUTORS_TABLE@

[maven]: https://search.maven.org/search?q=g:%20com.alejandrohdezma%20AND%20a:sbt-github
[maven-badge]: https://maven-badges.herokuapp.com/maven-central/com.alejandrohdezma/sbt-github/badge.svg?kill_cache=1

[steward]: https://scala-steward.org
[steward-badge]: https://img.shields.io/badge/Scala_Steward-helping-brightgreen.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII=
@CONTRIBUTORS_TABLE@
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import mdoc.MdocPlugin.autoImport.mdocVariables
* - '''ORG_URL''': Set to the value of `organizationHomepage` setting (Github's organization homepage, or owner's in
* case organization is empty and `populateOrganizationWithOwner` is `true`).
* - '''REPO''': Set to the repository's path: "owner/repo".
* - '''DEFAULT_BRANCH''': Set to the repository's default branch.
* - '''START_YEAR''': Set to the value of the `startYear` setting.
* - '''YEAR_RANGE''': Set to the value of the `yearRange` setting
* - '''COPYRIGHT_OWNER''': Set to the value of `ORG_NAME <ORG_URL>` if `ORG_URL` is present or just `ORG_NAME` in
Expand Down Expand Up @@ -88,6 +89,7 @@ object SbtGithubMdocPlugin extends AutoPlugin {
mdocVariables ++= Map(
"NAME" -> displayName.value,
"REPO" -> repository.value.map(_.name).getOrElse(""),
"DEFAULT_BRANCH" -> repository.value.map(_.defaultBranch).getOrElse(""),
"LICENSE" -> licenses.value.headOption.map(_._1).getOrElse(""),
"ORG_NAME" -> organizationName.value,
"DESCRIPTION" -> description.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "repo",
"full_name": "user1/repo",
"created_at": "2018-01-01T13:30:30Z",
"default_branch": "name",
"owner": {
"url": "{{base_directory}}/user1.json"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ sbt-github

user1/repo

name

An awesome description

MIT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

@REPO@

@DEFAULT_BRANCH@

@DESCRIPTION@

@LICENSE@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"owner": {
"url": "{{base_directory}}/user1.json"
},
"default_branch": "name",
"html_url": "https://github.com/user1/repo",
"description": "An awesome description",
"collaborators_url": "{{base_directory}}/collaborators.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ final case class Repository(
license: License,
url: URL,
startYear: Int,
defaultBranch: String,
contributorsUrl: URL,
collaboratorsUrl: URL,
releasesUrl: URL,
Expand Down Expand Up @@ -166,6 +167,7 @@ object Repository {
license <- json.get[License]("license")
url <- json.get[URL]("html_url")
startYear <- json.get[ZonedDateTime]("created_at")
defaultBranch <- json.get[String]("default_branch")
contributors <- json.get[URL]("contributors_url")
collaborators <- json.get[URL]("collaborators_url")
organizationUrl <- json.get[Option[URL]]("organization", "url")
Expand All @@ -177,6 +179,7 @@ object Repository {
license,
url,
startYear.getYear,
defaultBranch,
contributors,
sbt.url(s"$collaborators".replace("{/collaborator}", "")),
sbt.url(s"$releases".replace("{/id}", "")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object url {

/** Adds a query param with the given `key`/`value` pair to this `URL` ad returns it. */
def withQueryParam(key: String, value: String): URL = {
val uri = url.toURI // scalafix:ok Disable.URL
val uri = url.toURI

val query = Option(uri.getQuery)
.map(_ + s"&$key=$value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "repo",
"full_name": "user1/repo",
"created_at": "2018-01-01T13:30:30Z",
"default_branch": "name",
"owner": {
"url": "{{base_directory}}/user1.json"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"owner": {
"url": "{{base_directory}}/user1.json"
},
"default_branch": "name",
"html_url": "https://github.com/user1/repo",
"description": "An awesome description",
"collaborators_url": "{{base_directory}}/collaborators.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"owner": {
"url": "{{base_directory}}/user1.json"
},
"default_branch": "name",
"html_url": "https://github.com/user1/repo",
"description": "An awesome description",
"collaborators_url": "{{base_directory}}/collaborators.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"owner": {
"url": "{{base_directory}}/user1.json"
},
"default_branch": "name",
"html_url": "https://github.com/user1/repo",
"description": "An awesome description",
"collaborators_url": "{{base_directory}}/collaborators.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"url": "{{base_directory}}/user1.json"
},
"html_url": "https://github.com/user1/repo",
"default_branch": "name",
"description": "An awesome description",
"collaborators_url": "{{base_directory}}/collaborators.json",
"contributors_url": "{{base_directory}}/contributors.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class RepositorySuite extends munit.FunSuite {
"description": "The description",
"html_url": "http://example.com/repository",
"created_at": "2011-01-26T19:01:12Z",
"default_branch": "main",
"contributors_url": "http://api.github.com/repos/example/example/contributors",
"collaborators_url": "http://api.github.com/repos/example/example/collaborators",
"releases_url": "http://api.github.com/repos/example/example/releases",
Expand All @@ -56,16 +57,17 @@ class RepositorySuite extends munit.FunSuite {
val repository = Repository.get("user", "repo")

val expected = Repository(
"user/repo",
"The description",
License("id", url"http://example.com"),
url"http://example.com/repository",
2011,
url"http://api.github.com/repos/example/example/contributors",
url"http://api.github.com/repos/example/example/collaborators",
url"http://api.github.com/repos/example/example/releases",
Some(url"http://api.github.com/users/example"),
url"http://api.github.com/users/owner"
name = "user/repo",
description = "The description",
license = License("id", url"http://example.com"),
url = url"http://example.com/repository",
startYear = 2011,
defaultBranch = "main",
contributorsUrl = url"http://api.github.com/repos/example/example/contributors",
collaboratorsUrl = url"http://api.github.com/repos/example/example/collaborators",
releasesUrl = url"http://api.github.com/repos/example/example/releases",
organizationUrl = Some(url"http://api.github.com/users/example"),
ownerUrl = url"http://api.github.com/users/owner"
)

assertEquals(repository, Success(expected))
Expand All @@ -81,6 +83,7 @@ class RepositorySuite extends munit.FunSuite {
"description": "The description",
"html_url": "http://example.com/repository",
"created_at": "2011-01-26T19:01:12Z",
"default_branch": "main",
"contributors_url": "http://api.github.com/repos/example/example/contributors",
"collaborators_url": "http://api.github.com/repos/example/example/collaborators",
"releases_url": "http://api.github.com/repos/example/example/releases",
Expand All @@ -98,16 +101,17 @@ class RepositorySuite extends munit.FunSuite {
val repository = Repository.get("user", "repo")

val expected = Repository(
"user/repo",
"The description",
License("id", url"http://example.com"),
url"http://example.com/repository",
2011,
url"http://api.github.com/repos/example/example/contributors",
url"http://api.github.com/repos/example/example/collaborators",
url"http://api.github.com/repos/example/example/releases",
None,
url"http://api.github.com/users/owner"
name = "user/repo",
description = "The description",
license = License("id", url"http://example.com"),
url = url"http://example.com/repository",
startYear = 2011,
defaultBranch = "main",
contributorsUrl = url"http://api.github.com/repos/example/example/contributors",
collaboratorsUrl = url"http://api.github.com/repos/example/example/collaborators",
releasesUrl = url"http://api.github.com/repos/example/example/releases",
organizationUrl = None,
ownerUrl = url"http://api.github.com/users/owner"
)

assertEquals(repository, Success(expected))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ package object repository {
License("", url"http://example.com"),
url"http://example.com",
0,
"main",
url"http://example.com",
url"http://example.com",
url"http://example.com",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import com.alejandrohdezma.sbt.github.syntax.json.JsonValueOps
import org.http4s.dsl.io._
import org.http4s.headers.Authorization

@SuppressWarnings(Array("scalafix:Disable.blocking.io"))
class ClientSuite extends munit.FunSuite {

test("client.get should make `GET` call using auth and returning content as `A`") {
Expand Down
1 change: 1 addition & 0 deletions site/docs/sbt-mdoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The plugin provides the following `mdocVariables`:
| **ORG_EMAIL** | Set to the value of `organizationEmail` setting (Github's organization email, or owner's in case organization is empty and `populateOrganizationWithOwner` is `true`) |
| **ORG_URL** | Set to the value of `organizationHomepage` setting (Github's organization homepage or owner's in case organization is empty and `populateOrganizationWithOwner` is `true`) |
| **REPO** | Set to the repository's path: "owner/repo" |
| **DEFAULT_BRANCH** | Set to the repository's default branch |
| **START_YEAR** | Set to the value of the `startYear` setting |
| **YEAR_RANGE** | Set to the value of the `yearRange` setting |
| **COPYRIGHT_OWNER** | Set to the value of `ORG_NAME <ORG_URL>` if `ORG_URL` is present or just `ORG_NAME` in case `ORG_URL` is empty |

0 comments on commit ca3a75e

Please sign in to comment.