Skip to content

Commit bd0180a

Browse files
committed
Merge pull request #170 from phadej/diffs
Fix #155. Fix diffs
2 parents fc83597 + 04e554b commit bd0180a

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

Github/Data.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ instance FromJSON File where
145145
<*> o .: "additions"
146146
<*> o .: "sha"
147147
<*> o .: "changes"
148-
<*> o .: "patch"
148+
<*> o .:? "patch"
149149
<*> o .: "filename"
150150
<*> o .: "deletions"
151151
parseJSON _ = fail "Could not build a File"

Github/Data/GitData.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module Github.Data.GitData where
44

55
import Github.Data.Definitions
6+
import Github.Data.Name (Name)
67

78
import Control.DeepSeq (NFData (..))
89
import Control.DeepSeq.Generics (genericRnf)
@@ -13,7 +14,7 @@ import Data.Vector (Vector)
1314
import GHC.Generics (Generic)
1415

1516
data Commit = Commit {
16-
commitSha :: !Text
17+
commitSha :: !(Name Commit)
1718
,commitParents :: !(Vector Tree)
1819
,commitUrl :: !Text
1920
,commitGitCommit :: !GitCommit
@@ -26,7 +27,7 @@ data Commit = Commit {
2627
instance NFData Commit where rnf = genericRnf
2728

2829
data Tree = Tree {
29-
treeSha :: !Text
30+
treeSha :: !(Name Tree)
3031
,treeUrl :: !Text
3132
,treeGitTrees :: !(Vector GitTree)
3233
} deriving (Show, Data, Typeable, Eq, Ord, Generic)
@@ -35,7 +36,7 @@ instance NFData Tree where rnf = genericRnf
3536

3637
data GitTree = GitTree {
3738
gitTreeType :: !Text
38-
,gitTreeSha :: !Text
39+
,gitTreeSha :: !(Name GitTree)
3940
-- Can be empty for submodule
4041
,gitTreeUrl :: !(Maybe Text)
4142
,gitTreeSize :: !(Maybe Int)
@@ -51,7 +52,7 @@ data GitCommit = GitCommit {
5152
,gitCommitCommitter :: !GitUser
5253
,gitCommitAuthor :: !GitUser
5354
,gitCommitTree :: !Tree
54-
,gitCommitSha :: !(Maybe Text)
55+
,gitCommitSha :: !(Maybe (Name GitCommit))
5556
,gitCommitParents :: !(Vector Tree)
5657
} deriving (Show, Data, Typeable, Eq, Ord, Generic)
5758

@@ -61,7 +62,7 @@ data Blob = Blob {
6162
blobUrl :: !Text
6263
,blobEncoding :: !Text
6364
,blobContent :: !Text
64-
,blobSha :: !Text
65+
,blobSha :: !(Name Blob)
6566
,blobSize :: !Int
6667
} deriving (Show, Data, Typeable, Eq, Ord, Generic)
6768

@@ -145,7 +146,7 @@ data File = File {
145146
,fileAdditions :: !Int
146147
,fileSha :: !Text
147148
,fileChanges :: !Int
148-
,filePatch :: !Text
149+
,filePatch :: !(Maybe Text)
149150
,fileFilename :: !Text
150151
,fileDeletions :: !Int
151152
} deriving (Show, Data, Typeable, Eq, Ord, Generic)

spec/Github/CommitsSpec.hs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
module Github.CommitsSpec where
44

55
import Github.Auth (GithubAuth (..))
6-
import Github.Repos.Commits (commitsFor', commitsForR)
6+
import Github.Repos.Commits (Commit, mkName, commitSha, commitsFor', commitsForR, diffR)
77
import Github.Request (executeRequest)
88

9-
-- import Data.Aeson.Compat (eitherDecodeStrict)
9+
import Control.Monad (forM_)
1010
import Data.Either.Compat (isRight)
11-
-- import Data.FileEmbed (embedFile)
11+
import Data.Proxy (Proxy (..))
1212
import System.Environment (lookupEnv)
1313
import Test.Hspec (Spec, describe, it, pendingWith, shouldSatisfy)
1414

@@ -38,3 +38,18 @@ spec = do
3838
cs <- executeRequest auth $ commitsForR "phadej" "github" (Just 40)
3939
cs `shouldSatisfy` isRight
4040
V.length (fromRightS cs) `shouldSatisfy` (< 70)
41+
42+
describe "diff" $ do
43+
it "works" $ withAuth $ \auth -> do
44+
cs <- executeRequest auth $ commitsForR "phadej" "github" (Just 30)
45+
cs `shouldSatisfy` isRight
46+
let commits = take 10 . V.toList . fromRightS $ cs
47+
let pairs = zip commits $ drop 1 commits
48+
forM_ pairs $ \(a, b) -> do
49+
d <- executeRequest auth $ diffR "phadej" "github" (commitSha a) (commitSha b)
50+
d `shouldSatisfy` isRight
51+
52+
it "issue #155" $ withAuth $ \auth -> do
53+
let mkCommitName = mkName (Proxy :: Proxy Commit)
54+
d <- executeRequest auth $ diffR "nomeata" "codespeed" (mkCommitName "ghc") (mkCommitName "tobami:master")
55+
d `shouldSatisfy` isRight

0 commit comments

Comments
 (0)