forked from smallhadroncollider/taskell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixes GitHub Project parsing when using automated cards #62
- Loading branch information
1 parent
7551f2a
commit ee0634d
Showing
6 changed files
with
122 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module IO.HTTP.GitHub.Issue | ||
( Issue(Issue) | ||
, issueToTask | ||
) where | ||
|
||
import ClassyPrelude | ||
|
||
import Control.Lens (makeLenses, (^.)) | ||
import Data.Text (replace) | ||
|
||
import qualified Data.Taskell.Task as T (Task, new, setDescription) | ||
import IO.HTTP.Aeson (deriveFromJSON) | ||
|
||
data Issue = Issue | ||
{ _title :: Text | ||
, _body :: Text | ||
} deriving (Eq, Show) | ||
|
||
-- strip underscores from field labels | ||
$(deriveFromJSON ''Issue) | ||
|
||
-- create lenses | ||
$(makeLenses ''Issue) | ||
|
||
-- operations | ||
issueToTask :: Issue -> T.Task | ||
issueToTask issue = T.setDescription (issue ^. body) task | ||
where | ||
task = T.new $ replace "\r" "" $ replace "\n" " " (issue ^. title) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module IO.GitHub.CardsTest | ||
( test_cards | ||
) where | ||
|
||
import ClassyPrelude | ||
|
||
import Test.Tasty | ||
import Test.Tasty.HUnit | ||
|
||
import Data.Aeson | ||
|
||
import IO.HTTP.GitHub.Card (MaybeCard (MaybeCard)) | ||
|
||
decodeCards :: Text -> Either String [MaybeCard] | ||
decodeCards txt = eitherDecodeStrict $ encodeUtf8 txt | ||
|
||
-- tests | ||
test_cards :: TestTree | ||
test_cards = | ||
testGroup | ||
"IO.HTTP.GitHub.Card" | ||
[ testCase | ||
"parses basic card" | ||
(assertEqual | ||
"Gives back card" | ||
(Right [MaybeCard (Just "blah") Nothing]) | ||
(decodeCards "[{\"note\": \"blah\"}]")) | ||
, testCase | ||
"parses basic card" | ||
(assertEqual | ||
"Gives back card" | ||
(Right | ||
[MaybeCard Nothing (Just "https://api.github.com/projects/columns/7850783")]) | ||
(decodeCards | ||
"[{\"note\": null, \"content_url\": \"https://api.github.com/projects/columns/7850783\"}]")) | ||
] |