{"action":"created","comment":{"url":"https://api.github.com/repos/phadej/stack-yaml/pulls/comments/52588533","id":52588533,"diff_hunk":"@@ -0,0 +1,81 @@\n+{-# LANGUAGE OverloadedStrings #-}\n+{-# LANGUAGE RecordWildCards   #-}\n+module StackYaml.Transformations.UpdateExtraDeps\n+    ( transformation\n+    ) where\n+\n+import Control.Applicative         (many)\n+import Control.Exception           (IOException, catch)\n+import Control.Lens\n+import Data.Aeson.Lens\n+import Data.Char                   (isDigit)\n+import Data.Function               ((&))\n+import Data.List                   (intersperse)\n+import Data.Monoid                 ((<>))\n+import Data.Text                   (Text, pack)\n+import Data.Yaml                   (Value)\n+import System.Exit                 (exitFailure)\n+import System.IO                   (hPutStrLn, stderr)\n+import Text.Regex.Applicative.Text (anySym, few, match, psym, sym)\n+\n+import           Distribution.Package  (PackageIdentifier (..),\n+                                        PackageName (..))\n+import qualified Distribution.PackDeps as PackDeps\n+import           Distribution.Version  (Version (..))\n+\n+transformation :: Value -> IO Value\n+transformation value = do\n+    newest <- catch PackDeps.loadNewest\n+                    (\\e -> hPutStrLn stderr (failedToLoad e) *> exitFailure)\n+    traverseOf\n+      (key \"extra-deps\" . values . _String)\n+      (updateExtraDep newest)\n+      value\n+  where\n+    failedToLoad :: IOException -> String\n+    failedToLoad err =\n+      unlines\n+        [ show err\n+        , \"Failed to read package database. Doing 'cabal update' might help.\"\n+        ]\n+\n+    updateExtraDep :: PackDeps.Newest -> Text -> IO Text\n+    updateExtraDep newest dep =\n+        (pkgName <$> parsePackageIdentifier dep)\n+           & maybe\n+               (dep <$ hPutStrLn\n+                         stderr\n+                         (\"Ignoring invalid extra-deps entry \" <> show dep))\n+               (\\name ->\n+                   newestPackageId newest name\n+                     & maybe\n+                         (dep <$ hPutStrLn\n+                                   stderr\n+                                   (\"Ignoring extra-deps entry \"\n+                                       <> show dep\n+                                       <> \" as it refers to unknown package \"\n+                                       <> show (unPackageName name)))\n+                         (pure . pPrintPackageIdentifier))\n+\n+parsePackageIdentifier :: Text -> Maybe PackageIdentifier\n+parsePackageIdentifier = match pkgIdentifierRe\n+  where\n+    pkgIdentifierRe =\n+      PackageIdentifier\n+        <$> (PackageName <$> few anySym <* sym '-')\n+        <*> pkgVersionRe\n+\n+    pkgVersionRe = flip Version [] <$> ((:) <$> num <*> many (sym '.' *> num))\n+      where\n+        num = read <$> many (psym isDigit)\n+\n+pPrintPackageIdentifier :: PackageIdentifier -> Text\n+pPrintPackageIdentifier PackageIdentifier{..} =\n+    pack (unPackageName pkgName) <> \"-\" <> pPrintVersion pkgVersion\n+\n+pPrintVersion :: Version -> Text","path":"src/StackYaml/Transformations/UpdateExtraDeps.hs","position":null,"original_position":76,"commit_id":"0b92b900b899a636e5b8e64b24e76e895b211139","original_commit_id":"a18156b3aaca6108b673024f29f76af6e2c9f8a9","user":{"login":"zudov","id":2613966,"avatar_url":"https://avatars.githubusercontent.com/u/2613966?v=3","gravatar_id":"","url":"https://api.github.com/users/zudov","html_url":"https://github.com/zudov","followers_url":"https://api.github.com/users/zudov/followers","following_url":"https://api.github.com/users/zudov/following{/other_user}","gists_url":"https://api.github.com/users/zudov/gists{/gist_id}","starred_url":"https://api.github.com/users/zudov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zudov/subscriptions","organizations_url":"https://api.github.com/users/zudov/orgs","repos_url":"https://api.github.com/users/zudov/repos","events_url":"https://api.github.com/users/zudov/events{/privacy}","received_events_url":"https://api.github.com/users/zudov/received_events","type":"User","site_admin":false},"body":"Fixed.","created_at":"2016-02-11T11:19:16Z","updated_at":"2016-02-11T11:19:16Z","html_url":"https://github.com/phadej/stack-yaml/pull/2#discussion_r52588533","pull_request_url":"https://api.github.com/repos/phadej/stack-yaml/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/phadej/stack-yaml/pulls/comments/52588533"},"html":{"href":"https://github.com/phadej/stack-yaml/pull/2#discussion_r52588533"},"pull_request":{"href":"https://api.github.com/repos/phadej/stack-yaml/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/phadej/stack-yaml/pulls/2","id":58994485,"html_url":"https://github.com/phadej/stack-yaml/pull/2","diff_url":"https://github.com/phadej/stack-yaml/pull/2.diff","patch_url":"https://github.com/phadej/stack-yaml/pull/2.patch","issue_url":"https://api.github.com/repos/phadej/stack-yaml/issues/2","number":2,"state":"open","locked":false,"title":"WIP: update-extra-deps","user":{"login":"zudov","id":2613966,"avatar_url":"https://avatars.githubusercontent.com/u/2613966?v=3","gravatar_id":"","url":"https://api.github.com/users/zudov","html_url":"https://github.com/zudov","followers_url":"https://api.github.com/users/zudov/followers","following_url":"https://api.github.com/users/zudov/following{/other_user}","gists_url":"https://api.github.com/users/zudov/gists{/gist_id}","starred_url":"https://api.github.com/users/zudov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zudov/subscriptions","organizations_url":"https://api.github.com/users/zudov/orgs","repos_url":"https://api.github.com/users/zudov/repos","events_url":"https://api.github.com/users/zudov/events{/privacy}","received_events_url":"https://api.github.com/users/zudov/received_events","type":"User","site_admin":false},"body":"Already works, but dirty and slow #1","created_at":"2016-02-11T06:01:06Z","updated_at":"2016-02-11T11:19:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"11afbd70bccab4d7516812a5611e475f2c0e0a77","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/phadej/stack-yaml/pulls/2/commits","review_comments_url":"https://api.github.com/repos/phadej/stack-yaml/pulls/2/comments","review_comment_url":"https://api.github.com/repos/phadej/stack-yaml/pulls/comments{/number}","comments_url":"https://api.github.com/repos/phadej/stack-yaml/issues/2/comments","statuses_url":"https://api.github.com/repos/phadej/stack-yaml/statuses/0b92b900b899a636e5b8e64b24e76e895b211139","head":{"label":"zudov:update-extra-deps","ref":"update-extra-deps","sha":"0b92b900b899a636e5b8e64b24e76e895b211139","user":{"login":"zudov","id":2613966,"avatar_url":"https://avatars.githubusercontent.com/u/2613966?v=3","gravatar_id":"","url":"https://api.github.com/users/zudov","html_url":"https://github.com/zudov","followers_url":"https://api.github.com/users/zudov/followers","following_url":"https://api.github.com/users/zudov/following{/other_user}","gists_url":"https://api.github.com/users/zudov/gists{/gist_id}","starred_url":"https://api.github.com/users/zudov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zudov/subscriptions","organizations_url":"https://api.github.com/users/zudov/orgs","repos_url":"https://api.github.com/users/zudov/repos","events_url":"https://api.github.com/users/zudov/events{/privacy}","received_events_url":"https://api.github.com/users/zudov/received_events","type":"User","site_admin":false},"repo":{"id":51496954,"name":"stack-yaml","full_name":"zudov/stack-yaml","owner":{"login":"zudov","id":2613966,"avatar_url":"https://avatars.githubusercontent.com/u/2613966?v=3","gravatar_id":"","url":"https://api.github.com/users/zudov","html_url":"https://github.com/zudov","followers_url":"https://api.github.com/users/zudov/followers","following_url":"https://api.github.com/users/zudov/following{/other_user}","gists_url":"https://api.github.com/users/zudov/gists{/gist_id}","starred_url":"https://api.github.com/users/zudov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zudov/subscriptions","organizations_url":"https://api.github.com/users/zudov/orgs","repos_url":"https://api.github.com/users/zudov/repos","events_url":"https://api.github.com/users/zudov/events{/privacy}","received_events_url":"https://api.github.com/users/zudov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zudov/stack-yaml","description":"Helper tool to modify stack-yaml","fork":true,"url":"https://api.github.com/repos/zudov/stack-yaml","forks_url":"https://api.github.com/repos/zudov/stack-yaml/forks","keys_url":"https://api.github.com/repos/zudov/stack-yaml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zudov/stack-yaml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zudov/stack-yaml/teams","hooks_url":"https://api.github.com/repos/zudov/stack-yaml/hooks","issue_events_url":"https://api.github.com/repos/zudov/stack-yaml/issues/events{/number}","events_url":"https://api.github.com/repos/zudov/stack-yaml/events","assignees_url":"https://api.github.com/repos/zudov/stack-yaml/assignees{/user}","branches_url":"https://api.github.com/repos/zudov/stack-yaml/branches{/branch}","tags_url":"https://api.github.com/repos/zudov/stack-yaml/tags","blobs_url":"https://api.github.com/repos/zudov/stack-yaml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zudov/stack-yaml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zudov/stack-yaml/git/refs{/sha}","trees_url":"https://api.github.com/repos/zudov/stack-yaml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zudov/stack-yaml/statuses/{sha}","languages_url":"https://api.github.com/repos/zudov/stack-yaml/languages","stargazers_url":"https://api.github.com/repos/zudov/stack-yaml/stargazers","contributors_url":"https://api.github.com/repos/zudov/stack-yaml/contributors","subscribers_url":"https://api.github.com/repos/zudov/stack-yaml/subscribers","subscription_url":"https://api.github.com/repos/zudov/stack-yaml/subscription","commits_url":"https://api.github.com/repos/zudov/stack-yaml/commits{/sha}","git_commits_url":"https://api.github.com/repos/zudov/stack-yaml/git/commits{/sha}","comments_url":"https://api.github.com/repos/zudov/stack-yaml/comments{/number}","issue_comment_url":"https://api.github.com/repos/zudov/stack-yaml/issues/comments{/number}","contents_url":"https://api.github.com/repos/zudov/stack-yaml/contents/{+path}","compare_url":"https://api.github.com/repos/zudov/stack-yaml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zudov/stack-yaml/merges","archive_url":"https://api.github.com/repos/zudov/stack-yaml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zudov/stack-yaml/downloads","issues_url":"https://api.github.com/repos/zudov/stack-yaml/issues{/number}","pulls_url":"https://api.github.com/repos/zudov/stack-yaml/pulls{/number}","milestones_url":"https://api.github.com/repos/zudov/stack-yaml/milestones{/number}","notifications_url":"https://api.github.com/repos/zudov/stack-yaml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zudov/stack-yaml/labels{/name}","releases_url":"https://api.github.com/repos/zudov/stack-yaml/releases{/id}","deployments_url":"https://api.github.com/repos/zudov/stack-yaml/deployments","created_at":"2016-02-11T05:55:39Z","updated_at":"2016-02-11T05:55:40Z","pushed_at":"2016-02-11T11:19:01Z","git_url":"git://github.com/zudov/stack-yaml.git","ssh_url":"git@github.com:zudov/stack-yaml.git","clone_url":"https://github.com/zudov/stack-yaml.git","svn_url":"https://github.com/zudov/stack-yaml","homepage":null,"size":20,"stargazers_count":0,"watchers_count":0,"language":"Haskell","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"phadej:master","ref":"master","sha":"3226f8337cf9f0bb8bfb87824596e0fae9dd9c57","user":{"login":"phadej","id":51087,"avatar_url":"https://avatars.githubusercontent.com/u/51087?v=3","gravatar_id":"","url":"https://api.github.com/users/phadej","html_url":"https://github.com/phadej","followers_url":"https://api.github.com/users/phadej/followers","following_url":"https://api.github.com/users/phadej/following{/other_user}","gists_url":"https://api.github.com/users/phadej/gists{/gist_id}","starred_url":"https://api.github.com/users/phadej/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phadej/subscriptions","organizations_url":"https://api.github.com/users/phadej/orgs","repos_url":"https://api.github.com/users/phadej/repos","events_url":"https://api.github.com/users/phadej/events{/privacy}","received_events_url":"https://api.github.com/users/phadej/received_events","type":"User","site_admin":false},"repo":{"id":51068154,"name":"stack-yaml","full_name":"phadej/stack-yaml","owner":{"login":"phadej","id":51087,"avatar_url":"https://avatars.githubusercontent.com/u/51087?v=3","gravatar_id":"","url":"https://api.github.com/users/phadej","html_url":"https://github.com/phadej","followers_url":"https://api.github.com/users/phadej/followers","following_url":"https://api.github.com/users/phadej/following{/other_user}","gists_url":"https://api.github.com/users/phadej/gists{/gist_id}","starred_url":"https://api.github.com/users/phadej/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phadej/subscriptions","organizations_url":"https://api.github.com/users/phadej/orgs","repos_url":"https://api.github.com/users/phadej/repos","events_url":"https://api.github.com/users/phadej/events{/privacy}","received_events_url":"https://api.github.com/users/phadej/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/phadej/stack-yaml","description":"Helper tool to modify stack-yaml","fork":false,"url":"https://api.github.com/repos/phadej/stack-yaml","forks_url":"https://api.github.com/repos/phadej/stack-yaml/forks","keys_url":"https://api.github.com/repos/phadej/stack-yaml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/phadej/stack-yaml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/phadej/stack-yaml/teams","hooks_url":"https://api.github.com/repos/phadej/stack-yaml/hooks","issue_events_url":"https://api.github.com/repos/phadej/stack-yaml/issues/events{/number}","events_url":"https://api.github.com/repos/phadej/stack-yaml/events","assignees_url":"https://api.github.com/repos/phadej/stack-yaml/assignees{/user}","branches_url":"https://api.github.com/repos/phadej/stack-yaml/branches{/branch}","tags_url":"https://api.github.com/repos/phadej/stack-yaml/tags","blobs_url":"https://api.github.com/repos/phadej/stack-yaml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/phadej/stack-yaml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/phadej/stack-yaml/git/refs{/sha}","trees_url":"https://api.github.com/repos/phadej/stack-yaml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/phadej/stack-yaml/statuses/{sha}","languages_url":"https://api.github.com/repos/phadej/stack-yaml/languages","stargazers_url":"https://api.github.com/repos/phadej/stack-yaml/stargazers","contributors_url":"https://api.github.com/repos/phadej/stack-yaml/contributors","subscribers_url":"https://api.github.com/repos/phadej/stack-yaml/subscribers","subscription_url":"https://api.github.com/repos/phadej/stack-yaml/subscription","commits_url":"https://api.github.com/repos/phadej/stack-yaml/commits{/sha}","git_commits_url":"https://api.github.com/repos/phadej/stack-yaml/git/commits{/sha}","comments_url":"https://api.github.com/repos/phadej/stack-yaml/comments{/number}","issue_comment_url":"https://api.github.com/repos/phadej/stack-yaml/issues/comments{/number}","contents_url":"https://api.github.com/repos/phadej/stack-yaml/contents/{+path}","compare_url":"https://api.github.com/repos/phadej/stack-yaml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/phadej/stack-yaml/merges","archive_url":"https://api.github.com/repos/phadej/stack-yaml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/phadej/stack-yaml/downloads","issues_url":"https://api.github.com/repos/phadej/stack-yaml/issues{/number}","pulls_url":"https://api.github.com/repos/phadej/stack-yaml/pulls{/number}","milestones_url":"https://api.github.com/repos/phadej/stack-yaml/milestones{/number}","notifications_url":"https://api.github.com/repos/phadej/stack-yaml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/phadej/stack-yaml/labels{/name}","releases_url":"https://api.github.com/repos/phadej/stack-yaml/releases{/id}","deployments_url":"https://api.github.com/repos/phadej/stack-yaml/deployments","created_at":"2016-02-04T10:20:52Z","updated_at":"2016-02-04T10:23:35Z","pushed_at":"2016-02-11T11:19:02Z","git_url":"git://github.com/phadej/stack-yaml.git","ssh_url":"git@github.com:phadej/stack-yaml.git","clone_url":"https://github.com/phadej/stack-yaml.git","svn_url":"https://github.com/phadej/stack-yaml","homepage":null,"size":5,"stargazers_count":0,"watchers_count":0,"language":"Haskell","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/phadej/stack-yaml/pulls/2"},"html":{"href":"https://github.com/phadej/stack-yaml/pull/2"},"issue":{"href":"https://api.github.com/repos/phadej/stack-yaml/issues/2"},"comments":{"href":"https://api.github.com/repos/phadej/stack-yaml/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/phadej/stack-yaml/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/phadej/stack-yaml/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/phadej/stack-yaml/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/phadej/stack-yaml/statuses/0b92b900b899a636e5b8e64b24e76e895b211139"}}}}