bitbucket-webhook
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
{-# LANGUAGE OverloadedStrings #-} | |
module Bitbucket ( | |
parseHook | |
) where | |
import Control.Applicative ((<$>)) | |
import Control.Lens | |
import Data.Aeson.Lens | |
import Data.List (nub) | |
import qualified Data.Text as DT | |
import qualified Data.ByteString.Lazy.Char8 as BS | |
data HookInfo = HookInfo { | |
hookProvider :: DT.Text, | |
hookRepository :: DT.Text, | |
hookBranch :: DT.Text | |
} deriving (Show,Eq) | |
stripSlashes :: DT.Text -> DT.Text | |
stripSlashes input = DT.reverse $ DT.drop 1 $ DT.reverse $ DT.drop 1 input | |
extractRepositoryName :: BS.ByteString -> DT.Text | |
extractRepositoryName str = str ^?! key "repository" . key "absolute_url" . _String | |
extractBranches :: BS.ByteString -> [DT.Text] | |
extractBranches str = str ^.. key "commits" . _Array . traverse . to (\o -> (o ^?! key "branch" . _String)) | |
parseHook :: FilePath -> IO [HookInfo] | |
parseHook file = do | |
contents <- BS.readFile file | |
let name = stripSlashes $ extractRepositoryName contents | |
branches = extractBranches contents | |
out = nub $ (\b -> HookInfo{hookProvider = "bitbucket", hookRepository = name, hookBranch = b}) <$> branches | |
return out |
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
{ | |
"canon_url": "https://bitbucket.org", | |
"commits": [ | |
{ | |
"author": "marcus", | |
"branch": "master", | |
"files": [ | |
{ | |
"file": "somefile.py", | |
"type": "modified" | |
} | |
], | |
"message": "Added some more things to somefile.py\n", | |
"node": "620ade18607a", | |
"parents": [ | |
"702c70160afc" | |
], | |
"raw_author": "Marcus Bertrand <marcus@somedomain.com>", | |
"raw_node": "620ade18607ac42d872b568bb92acaa9a28620e9", | |
"revision": null, | |
"size": -1, | |
"timestamp": "2012-05-30 05:58:56", | |
"utctimestamp": "2012-05-30 03:58:56+00:00" | |
}, | |
{ | |
"author": "marcus", | |
"branch": "test", | |
"files": [ | |
{ | |
"file": "somefile.py", | |
"type": "modified" | |
} | |
], | |
"message": "Added some more things to somefile.py\n", | |
"node": "620ade18607a", | |
"parents": [ | |
"702c70160afc" | |
], | |
"raw_author": "Marcus Bertrand <marcus@somedomain.com>", | |
"raw_node": "620ade18607ac42d872b568bb92acaa9a28620e9", | |
"revision": null, | |
"size": -1, | |
"timestamp": "2012-05-30 05:58:56", | |
"utctimestamp": "2012-05-30 03:58:56+00:00" | |
} | |
], | |
"repository": { | |
"absolute_url": "/marcus/project-x/", | |
"fork": false, | |
"is_private": true, | |
"name": "Project X", | |
"owner": "marcus", | |
"scm": "git", | |
"slug": "project-x", | |
"website": "https://atlassian.com/" | |
}, | |
"user": "marcus" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment