Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse old metadata.xml for remote-ids #115

Open
hololeap opened this issue Aug 27, 2022 · 2 comments
Open

Parse old metadata.xml for remote-ids #115

hololeap opened this issue Aug 27, 2022 · 2 comments
Labels

Comments

@hololeap
Copy link
Member

-- | Extract the maintainer email and USE flags from a supplied XML 'Element'.
--
-- If we're parsing a blank 'Element' or otherwise empty @metadata.xml@:
-- >>> parseMetadata blank_element
-- Just (Metadata {metadataEmails = [], metadataUseFlags = fromList [], metadataRemoteIds = fromList []})
parseMetadata :: Element -> Maybe Metadata
parseMetadata xml =
return Metadata { metadataEmails = strContent <$> findElements (unqual "email") xml
, metadataUseFlags =
-- find the flag name
let x = findElement (unqual "use") xml
y = onlyElems $ concatMap elContent x
z = attrVal <$> concatMap elAttribs y
-- find the flag description
a = concatMap elContent y
b = cdData <$> onlyText a
in Map.fromList $ zip z b
-- TODO: Read remote-ids from existing metadata.xml
, metadataRemoteIds = S.empty
}

Old entries are ignored.

-- TODO: Read remote-ids from existing metadata.xml
, metadataRemoteIds = S.empty

@hololeap
Copy link
Member Author

This will allow us to add remote-ids by hand and have them be saved between bumps.

@hololeap
Copy link
Member Author

The XML needs to be translated to a set of these:

data RemoteId
= RemoteIdHackage String -- ^ Hackage package
| RemoteIdCRAN String -- ^ CRAN package
| RemoteIdCTAN String -- ^ CTAN package
| RemoteIdGentoo String -- ^ Gentoo project
| RemoteIdGithub String String -- ^ Github user and repo
| RemoteIdGitlab String String -- ^ Gitlab user and repo
| RemoteIdLaunchpad String -- ^ Launchpad project
| RemoteIdOSDN String -- ^ OSDN project
| RemoteIdPECL String -- ^ PECL package
| RemoteIdPyPI String -- ^ PyPI project
| RemoteIdRubygems String -- ^ Rubygems gem
| RemoteIdSourceforge String -- ^ Sourceforge project
| RemoteIdVim String -- ^ Vim script
deriving (Show, Eq, Ord)

The pretty-printer logic:

-- | Pretty print a single 'RemoteId'.
prettyPrintRemoteId :: RemoteId -> String
prettyPrintRemoteId = \case
RemoteIdHackage p -> pp "hackage" p
RemoteIdCRAN p -> pp "cran" p
RemoteIdCTAN p -> pp "ctan" p
RemoteIdGentoo p -> pp "gentoo" p
RemoteIdGithub u r -> pp "github" $ u ++ "/" ++ r
RemoteIdGitlab u r -> pp "gitlab" $ u ++ "/" ++ r
RemoteIdLaunchpad p -> pp "launchpad" p
RemoteIdOSDN p -> pp "osdn" p
RemoteIdPECL p -> pp "pecl" p
RemoteIdPyPI p -> pp "pypi" p
RemoteIdRubygems g -> pp "rubygems" g
RemoteIdSourceforge p -> pp "sourceforge" p
RemoteIdVim s -> pp "vim" s
where
pp t v = "\t\t<remote-id type=\"" ++ t ++ "\">" ++ v ++ "</remote-id>"

@hololeap hololeap added the bug label Sep 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant