Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
smallhadroncollider committed Mar 6, 2019
2 parents d0f0f0b + 1bbec60 commit 27b0c0f
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 36 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ A `.cmt` file consist of two parts: the input parts and the output format.
For example, the [AngularJS Commit Message Guidelines](https://gist.github.com/stephenparish/9941e89d80e2bc58a153):

```txt
# The input parts
{
# Shows a list of options
"Type" = [
"feat",
"fix",
Expand All @@ -39,12 +41,15 @@ For example, the [AngularJS Commit Message Guidelines](https://gist.github.com/s
"test",
"chore"
]
"Scope" = @
"Scope" = @ # Allows a single line of input
"Subject" = @
"Body" = !@
"Body" = !@ # Allows multi-line input
"Footer" = !@
}
# The output format
# Takes the values provided from the input stage
# and interpolates them in
${Type} (${Scope}): ${Subject}
${Body}
Expand All @@ -70,10 +75,13 @@ You can accept a output called `${*}`, which will add in whatever is passed to `
For example:

```txt
# Input parts
# * input not needed, as comes from command-line
{
"Scope" = @
}
# Scope from input and * from command-line
(${Scope}): ${*}
```

Expand Down
3 changes: 2 additions & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: cmt
version: 0.1.3.0
version: 0.2.0.0
github: "smallhadroncollider/cmt"
license: BSD3
author: "Small Hadron Collider / Mark Wales"
Expand Down Expand Up @@ -51,6 +51,7 @@ tests:
- -with-rtsopts=-N
dependencies:
- cmt
- file-embed
- tasty
- tasty-discover
- tasty-hunit
Expand Down
5 changes: 3 additions & 2 deletions roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

- pre-commit errors don't get displayed at all
> Probably need to show stderr in some cases?
- Extra new-line at the end of the output

## Features

- Show options in flat list if short?
- Store previous commit info if it fails
> Store if commit fails. `cmt --prev` option?
- List option?
> Automatically adds a hyphen to each entry?
- Add comments to .cmt
- Show options in flat list if short?
- Make parts optional
> @? and !@? operators?
- Option to show files that have changed
Expand All @@ -32,3 +32,4 @@
> If ${*} detected, then say if no command line argument given
- Should search up directories to find .cmt
- Should support ~/.cmt for global option
- Add comments to .cmt
20 changes: 0 additions & 20 deletions src/Cmt/Parser/Attoparsec.hs

This file was deleted.

31 changes: 25 additions & 6 deletions src/Cmt/Parser/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,52 @@ import ClassyPrelude

import Data.Attoparsec.Text

import Cmt.Parser.Attoparsec (chopt, lexeme, tnotChar)
import Cmt.Types.Config

-- useful bits
lexeme :: Parser a -> Parser a
lexeme p = skipSpace *> p <* skipSpace

tchar :: Char -> Parser Text
tchar ch = singleton <$> char ch

chopt :: Char -> Parser Text
chopt ch = option "" (tchar ch)

tnotChar :: Char -> Parser Text
tnotChar c = pack <$> many1 (notChar c)

commentP :: Parser ()
commentP = lexeme $ many' (char '#' *> many' (notChar '\n') *> char '\n') $> ()

stripComments :: Parser a -> Parser a
stripComments p = lexeme $ commentP *> p <* commentP

word :: Parser Text
word = pack <$> many1 (letter <|> space)

valid :: [Name] -> Parser Text
valid names = choice $ "*" : (string <$> names)

-- format parts
formatNamedP :: [Name] -> Parser FormatPart
formatNamedP names = Named <$> (string "${" *> valid names <* char '}')

formatLiteralP :: Parser FormatPart
formatLiteralP = Literal <$> (singleton <$> anyChar)

formatP :: [Name] -> Parser Format
formatP names = lexeme $ many1 (formatNamedP names <|> formatLiteralP)
formatP names = stripComments $ many1 (formatNamedP names <|> formatLiteralP)

-- part types
-- input parts
lineP :: Parser PartType
lineP = char '@' $> Line

linesP :: Parser PartType
linesP = string "!@" $> Lines

listItemP :: Parser Text
listItemP = lexeme $ char '"' *> tnotChar '"' <* char '"' <* chopt ','
listItemP = stripComments $ char '"' *> tnotChar '"' <* char '"' <* chopt ','

listP :: Parser PartType
listP = Options <$> (char '[' *> many' listItemP <* char ']')
Expand All @@ -46,10 +65,10 @@ nameP = char '"' *> word <* char '"' <* lexeme (char '=')

-- part
partP :: Parser Part
partP = lexeme $ Part <$> nameP <*> (listP <|> lineP <|> linesP)
partP = stripComments $ Part <$> nameP <*> (listP <|> lineP <|> linesP)

partsP :: Parser [Part]
partsP = lexeme $ char '{' *> many' partP <* char '}'
partsP = stripComments $ stripComments (char '{') *> many' partP <* stripComments (char '}')

configP :: Parser Config
configP = do
Expand Down
10 changes: 5 additions & 5 deletions src/Cmt/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Cmt.Types.Config where

import ClassyPrelude (Maybe (..), Show, Text)
import ClassyPrelude (Eq, Maybe (..), Show, Text)

type Output = (Name, Text)

Expand All @@ -11,25 +11,25 @@ type Name = Text
data FormatPart
= Named Name
| Literal Text
deriving (Show)
deriving (Show, Eq)

type Format = [FormatPart]

data PartType
= Options [Text]
| Line
| Lines
deriving (Show)
deriving (Show, Eq)

data Part =
Part Name
PartType
deriving (Show)
deriving (Show, Eq)

data Config =
Config [Part]
Format
deriving (Show)
deriving (Show, Eq)

partName :: Part -> Name
partName (Part name _) = name
Expand Down
66 changes: 66 additions & 0 deletions test/Cmt/Parser/ConfigTest.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}

module Cmt.Parser.ConfigTest where

import ClassyPrelude

import Test.Tasty
import Test.Tasty.HUnit

import Data.FileEmbed (embedFile)

import Cmt.Parser.Config (config)
import Cmt.Types.Config

basic :: Text
basic = decodeUtf8 $(embedFile "test/data/.cmt")

basicConfig :: Config
basicConfig =
Config [Part "Week" Line] [Named "Week", Literal ":", Literal " ", Named "*", Literal "\n"]

angular :: Text
angular = decodeUtf8 $(embedFile "test/data/.cmt-angular")

comments :: Text
comments = decodeUtf8 $(embedFile "test/data/.cmt-comments")

angularConfig :: Config
angularConfig =
Config
[ Part "Type" (Options ["feat", "fix", "docs", "style", "refactor", "test", "chore"])
, Part "Scope" Line
, Part "Short Message" Line
, Part "Body" Lines
]
[ Named "Type"
, Literal " "
, Literal "("
, Named "Scope"
, Literal ")"
, Literal ":"
, Literal " "
, Named "Short Message"
, Literal "\n"
, Literal "\n"
, Named "Body"
, Literal "\n"
]

-- import Test.Tasty.HUnit
test_config :: TestTree
test_config =
testGroup
"Cmt.Parser.Config"
[ testCase
"basic"
(assertEqual "Gives back correct format" (Right basicConfig) (config basic))
, testCase
"angular"
(assertEqual "Gives back correct format" (Right angularConfig) (config angular))
, testCase
"comments"
(assertEqual "Gives back correct format" (Right angularConfig) (config comments))
]
1 change: 1 addition & 0 deletions test/Spec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{-# OPTIONS_GHC -F -pgmF tasty-discover #-}
5 changes: 5 additions & 0 deletions test/data/.cmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Week" = @
}

${Week}: ${*}
18 changes: 18 additions & 0 deletions test/data/.cmt-angular
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"Type" = [
"feat",
"fix",
"docs",
"style",
"refactor",
"test",
"chore"
]
"Scope" = @
"Short Message" = @
"Body" = !@
}

${Type} (${Scope}): ${Short Message}

${Body}
28 changes: 28 additions & 0 deletions test/data/.cmt-comments
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# The input parts
# Blah blah blah
#
# Blah blah blah

# Blah blah blah
{ # A comment
# A list of stuff
"Type" = [ # A list of options
"feat",
"fix",
"docs",
"style",
"refactor", ## A comment here too
"test",
"chore"
] # A comment
# The scope
"Scope" = @ # Another comment
"Short Message" = @ # All the comments all the time
"Body" = !@ # So many comments!
} # Another comment

# Blah blah blah
# Blah blah blah
${Type} (${Scope}): ${Short Message}

${Body}

0 comments on commit 27b0c0f

Please sign in to comment.