(patch) Pre-commit and builds
All checks were successful
/ Build and Release Library (push) Successful in 1m15s

This commit is contained in:
Pat Garrity 2024-03-24 04:02:38 +00:00
parent cfcbfdfdac
commit c3cb5502e8
5 changed files with 40 additions and 19 deletions

View file

@ -26,7 +26,7 @@ jobs:
pre-commit run --all-files pre-commit run --all-files
- name: 'Prepare Versioned Build' - name: 'Prepare Versioned Build'
run: | run: |
latest_git_tag="$(git describe --tags --abbrev=0)" latest_git_tag="$(git describe --tags --abbrev=0 || echo 'No Tags')"
latest_commit_message="$(git show -s --format=%s HEAD)" latest_commit_message="$(git show -s --format=%s HEAD)"
if [[ "$latest_commit_message" == *"(major)"* ]]; then if [[ "$latest_commit_message" == *"(major)"* ]]; then
export GS_RELEASE_TYPE="major" export GS_RELEASE_TYPE="major"

View file

@ -27,7 +27,7 @@ jobs:
pre-commit run --all-files pre-commit run --all-files
- name: 'Prepare Versioned Build' - name: 'Prepare Versioned Build'
run: | run: |
latest_git_tag="$(git describe --tags --abbrev=0)" latest_git_tag="$(git describe --tags --abbrev=0 || echo 'No Tags')"
latest_commit_message="$(git show -s --format=%s HEAD)" latest_commit_message="$(git show -s --format=%s HEAD)"
if [[ "$latest_commit_message" == *"(major)"* ]]; then if [[ "$latest_commit_message" == *"(major)"* ]]; then
export GS_RELEASE_TYPE="major" export GS_RELEASE_TYPE="major"

View file

@ -17,3 +17,23 @@ externalResolvers +=
val GsSlug: ModuleID = val GsSlug: ModuleID =
"gs" %% "gs-slug-v0" % "0.1.0" "gs" %% "gs-slug-v0" % "0.1.0"
``` ```
## Slug Type
`Slug` is the type exposed by this library. It is an extremely small,
restricted, opaque type (`String`) that adheres to the following regular
expression:
```
^[a-z0-9]+(?:\-[a-z0-9]+)*$
```
This type is intended for use in the following scenarios:
- Restricted ASCII is acceptable.
- URL safety is desired.
Additionally, `Slug` is usually intended to be unique within some _context_,
where the implementation defines the context. For example, if some organization
owns a number of repositories, each repository might have a `Slug` which is
unique within that organization.

View file

@ -2,16 +2,15 @@ package gs.slug.v0
import scala.util.matching.Regex import scala.util.matching.Regex
/** /** Restricted string intended to be used as a unique, URL-safe identifier
* Restricted string intended to be used as a unique, URL-safe identifier
* within some specific context (not a globally unique identifier). This type * within some specific context (not a globally unique identifier). This type
* adheres to the regular expression: `^[a-z0-9]+(?:\-[a-z0-9]+)*$` * adheres to the regular expression: `^[a-z0-9]+(?:\-[a-z0-9]+)*$`
* *
* Essentially, Slugs follow these rules: * Essentially, Slugs follow these rules:
* *
* - Segments are defined as lowercase alphanumeric ASCII strings. * - Segments are defined as lowercase alphanumeric ASCII strings.
* - Segments are separated by exactly one `-` character. * - Segments are separated by exactly one `-` character.
* - At least one segment is required. * - At least one segment is required.
* *
* If you need full unicode support, more characters, fewer constraints, etc. * If you need full unicode support, more characters, fewer constraints, etc.
* don't use this type. * don't use this type.
@ -22,21 +21,22 @@ object Slug:
val SlugPattern: Regex = "^[a-z0-9]+(?:\\-[a-z0-9]+)*$".r val SlugPattern: Regex = "^[a-z0-9]+(?:\\-[a-z0-9]+)*$".r
/** /** Instantiate a [[Slug]] by validating the candidate input.
* Instantiate a [[Slug]] by validating the candidate input. *
* * @param candidate
* @param candidate The candidate string used to create the [[Slug]]. * The candidate string used to create the [[Slug]].
* @return The [[Slug]], or `None` if the candidate is invalid. * @return
*/ * The [[Slug]], or `None` if the candidate is invalid.
def validate(candidate: String): Option[Slug] = */
def validate(candidate: String): Option[Slug] =
if SlugPattern.matches(candidate) then Some(candidate) else None if SlugPattern.matches(candidate) then Some(candidate) else None
given CanEqual[Slug, Slug] = CanEqual.derived given CanEqual[Slug, Slug] = CanEqual.derived
extension (slug: Slug) extension (slug: Slug)
/** /** Render this [[Slug]] as a string.
* Render this [[Slug]] as a string. *
* * @return
* @return The string representation of this [[Slug]]. * The string representation of this [[Slug]].
*/ */
def str(): String = slug def str(): String = slug

View file

@ -1,6 +1,7 @@
package gs.slug.v0 package gs.slug.v0
class SlugTests extends munit.FunSuite: class SlugTests extends munit.FunSuite:
test("should instantiate valid slugs") { test("should instantiate valid slugs") {
('a' to 'z').foreach(c => assertValidSlug(c.toString())) ('a' to 'z').foreach(c => assertValidSlug(c.toString()))
('0' to '9').foreach(c => assertValidSlug(c.toString())) ('0' to '9').foreach(c => assertValidSlug(c.toString()))