-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [#58] Make License type safer * Rename license types * Fix style * Fix lastT and style * Update choose * Remove forall * Refactor choose function * Fix choose function * Swap with whenNothing * Fix style * Fix 3 errors * Refactor Read instance * Fix style * Implement without read * Make choose more universal
- Loading branch information
Showing
8 changed files
with
106 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,78 @@ | ||
module Summoner.License | ||
( License (..) | ||
( LicenseName(..) | ||
, License(..) | ||
, customizeLicense | ||
, licenseNames | ||
, githubLicenseQueryNames | ||
, parseLicenseName | ||
) where | ||
|
||
import Relude | ||
import Relude.Extra.Enum (inverseMap) | ||
|
||
import Data.Aeson (FromJSON (..), withObject, (.:)) | ||
|
||
import qualified Data.Text as T | ||
import qualified Text.Show as TS | ||
|
||
---------------------------------------------------------------------------- | ||
-- License | ||
---------------------------------------------------------------------------- | ||
|
||
licenseNames :: [License] | ||
licenseNames = map fst githubLicenseQueryNames | ||
|
||
githubLicenseQueryNames :: [(License, Text)] | ||
githubLicenseQueryNames = | ||
[ ("MIT", "mit") | ||
, ("BSD2", "bsd-2-clause") | ||
, ("BSD3", "bsd-3-clause") | ||
, ("GPL-2", "gpl-2.0") | ||
, ("GPL-3", "gpl-3.0") | ||
, ("LGPL-2.1", "lgpl-2.1") | ||
, ("LGPL-3", "lgpl-3.0") | ||
, ("AGPL-3", "agpl-3.0") | ||
, ("Apache-2.0", "apache-2.0") | ||
, ("MPL-2.0", "mpl-2.0") | ||
] | ||
data LicenseName | ||
= MIT | ||
| BSD2 | ||
| BSD3 | ||
| GPL2 | ||
| GPL3 | ||
| LGPL21 | ||
| LGPL3 | ||
| AGPL3 | ||
| Apache20 | ||
| MPL20 | ||
deriving (Eq, Ord, Enum, Bounded, Generic) | ||
|
||
instance Show LicenseName where | ||
show MIT = "MIT" | ||
show BSD2 = "BSD2" | ||
show BSD3 = "BSD3" | ||
show GPL2 = "GPL-2" | ||
show GPL3 = "GPL-3" | ||
show LGPL21 = "LGPL-2.1" | ||
show LGPL3 = "LGPL-3" | ||
show AGPL3 = "AGPL-3" | ||
show Apache20 = "Apache-2.0" | ||
show MPL20 = "MPL-2.0" | ||
|
||
newtype License = License { unLicense :: Text } | ||
deriving (IsString, Eq, Ord, Show) | ||
deriving (IsString, Show, Generic) | ||
|
||
instance FromJSON License where | ||
parseJSON = withObject "License" $ \o -> License <$> o .: "body" | ||
|
||
customizeLicense :: Text -> Text -> Text -> Text -> Text | ||
githubLicenseQueryNames :: LicenseName -> Text | ||
githubLicenseQueryNames = \case | ||
MIT -> "mit" | ||
BSD2 -> "bsd-2-clause" | ||
BSD3 -> "bsd-3-clause" | ||
GPL2 -> "gpl-2.0" | ||
GPL3 -> "gpl-3.0" | ||
LGPL21 -> "lgpl-2.1" | ||
LGPL3 -> "lgpl-3.0" | ||
AGPL3 -> "agpl-3.0" | ||
Apache20 -> "apache-2.0" | ||
MPL20 -> "mpl-2.0" | ||
|
||
parseLicenseName :: Text -> Maybe LicenseName | ||
parseLicenseName = inverseMap show | ||
|
||
customizeLicense :: LicenseName -> Text -> Text -> Text -> Text | ||
customizeLicense l t nm year | ||
| l `elem` words "MIT BSD2 BSD3" = updateLicenseText | ||
| otherwise = t | ||
| l `elem` [MIT, BSD2, BSD3] = updateLicenseText | ||
| otherwise = t | ||
where | ||
updateLicenseText = | ||
let (beforeY, withY) = T.span (/= '[') t | ||
afterY = T.tail $ T.dropWhile (/= ']') withY | ||
afterY = T.tail $ T.dropWhile (/= ']') withY | ||
(beforeN, withN) = T.span (/= '[') afterY | ||
afterN = T.tail $ T.dropWhile (/= ']') withN | ||
in beforeY <> year <> beforeN <> nm <> afterN | ||
afterN = T.tail $ T.dropWhile (/= ']') withN | ||
in beforeY <> year <> beforeN <> nm <> afterN |
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