forked from haskell-github/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitData.hs
More file actions
312 lines (263 loc) · 7.76 KB
/
GitData.hs
File metadata and controls
312 lines (263 loc) · 7.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
module GitHub.Data.GitData where
import GitHub.Data.Definitions
import GitHub.Data.Name (Name)
import GitHub.Data.URL (URL)
import GitHub.Internal.Prelude
import Prelude ()
import qualified Data.Vector as V
-- | The options for querying commits.
data CommitQueryOption
= CommitQuerySha !Text
| CommitQueryPath !Text
| CommitQueryAuthor !Text
| CommitQuerySince !UTCTime
| CommitQueryUntil !UTCTime
deriving (Show, Eq, Ord, Generic, Data)
data Stats = Stats
{ statsAdditions :: !Int
, statsTotal :: !Int
, statsDeletions :: !Int
}
deriving (Show, Data, Eq, Ord, Generic)
instance NFData Stats
instance Binary Stats
data Commit = Commit
{ commitSha :: !(Name Commit)
, commitParents :: !(Vector Tree)
, commitUrl :: !URL
, commitGitCommit :: !GitCommit
, commitCommitter :: !(Maybe SimpleUser)
, commitAuthor :: !(Maybe SimpleUser)
, commitFiles :: !(Vector File)
, commitStats :: !(Maybe Stats)
}
deriving (Show, Data, Eq, Ord, Generic)
instance NFData Commit
instance Binary Commit
data Tree = Tree
{ treeSha :: !(Name Tree)
, treeUrl :: !URL
, treeGitTrees :: !(Vector GitTree)
}
deriving (Show, Data, Eq, Ord, Generic)
instance NFData Tree
instance Binary Tree
data GitTree = GitTree
{ gitTreeType :: !Text
, gitTreeSha :: !(Name GitTree)
-- Can be empty for submodule
, gitTreeUrl :: !(Maybe URL)
, gitTreeSize :: !(Maybe Int)
, gitTreePath :: !Text
, gitTreeMode :: !Text
}
deriving (Show, Data, Eq, Ord, Generic)
instance NFData GitTree
instance Binary GitTree
data GitCommit = GitCommit
{ gitCommitMessage :: !Text
, gitCommitUrl :: !URL
, gitCommitCommitter :: !GitUser
, gitCommitAuthor :: !GitUser
, gitCommitTree :: !Tree
, gitCommitSha :: !(Maybe (Name GitCommit))
, gitCommitParents :: !(Vector Tree)
}
deriving (Show, Data, Eq, Ord, Generic)
instance NFData GitCommit
instance Binary GitCommit
data Blob = Blob
{ blobUrl :: !URL
, blobEncoding :: !Text
, blobContent :: !Text
, blobSha :: !(Name Blob)
, blobSize :: !Int
}
deriving (Show, Data, Eq, Ord, Generic)
instance NFData Blob
instance Binary Blob
data Tag = Tag
{ tagName :: !Text
, tagZipballUrl :: !URL
, tagTarballUrl :: !URL
, tagCommit :: !BranchCommit
}
deriving (Show, Data, Eq, Ord, Generic)
instance NFData Tag
instance Binary Tag
data Branch = Branch
{ branchName :: !Text
, branchCommit :: !BranchCommit
}
deriving (Show, Data, Eq, Ord, Generic)
instance NFData Branch
data BranchCommit = BranchCommit
{ branchCommitSha :: !Text
, branchCommitUrl :: !URL
}
deriving (Show, Data, Eq, Ord, Generic)
instance NFData BranchCommit
instance Binary BranchCommit
data Diff = Diff
{ diffStatus :: !Text
, diffBehindBy :: !Int
, diffPatchUrl :: !URL
, diffUrl :: !URL
, diffBaseCommit :: !Commit
, diffCommits :: !(Vector Commit)
, diffTotalCommits :: !Int
, diffHtmlUrl :: !URL
, diffFiles :: !(Vector File)
, diffAheadBy :: !Int
, diffDiffUrl :: !URL
, diffPermalinkUrl :: !URL
}
deriving (Show, Data, Eq, Ord, Generic)
instance NFData Diff
instance Binary Diff
data NewGitReference = NewGitReference
{ newGitReferenceRef :: !Text
, newGitReferenceSha :: !Text
}
deriving (Show, Data, Eq, Ord, Generic)
instance NFData NewGitReference
instance Binary NewGitReference
data GitReference = GitReference
{ gitReferenceObject :: !GitObject
, gitReferenceUrl :: !URL
, gitReferenceRef :: !(Name GitReference)
}
deriving (Show, Data, Eq, Ord, Generic)
instance NFData GitReference
instance Binary GitReference
data GitObject = GitObject
{ gitObjectType :: !Text
, gitObjectSha :: !Text
, gitObjectUrl :: !URL
}
deriving (Show, Data, Eq, Ord, Generic)
instance NFData GitObject
instance Binary GitObject
data GitUser = GitUser
{ gitUserName :: !Text
, gitUserEmail :: !Text
, gitUserDate :: !UTCTime
}
deriving (Show, Data, Eq, Ord, Generic)
instance NFData GitUser
instance Binary GitUser
data File = File
{ fileBlobUrl :: !(Maybe URL)
, fileStatus :: !Text
, fileRawUrl :: !(Maybe URL)
, fileAdditions :: !Int
, fileSha :: !(Maybe Text)
, fileChanges :: !Int
, filePatch :: !(Maybe Text)
, fileFilename :: !Text
, fileDeletions :: !Int
}
deriving (Show, Data, Eq, Ord, Generic)
instance NFData File
instance Binary File
-- JSON instances
instance FromJSON Stats where
parseJSON = withObject "Stats" $ \o -> Stats
<$> o .: "additions"
<*> o .: "total"
<*> o .: "deletions"
instance FromJSON Commit where
parseJSON = withObject "Commit" $ \o -> Commit
<$> o .: "sha"
<*> o .: "parents"
<*> o .: "url"
<*> o .: "commit"
<*> (o .:? "committer" <|> pure Nothing)
<*> (o .:? "author" <|> pure Nothing)
<*> o .:? "files" .!= V.empty
<*> o .:? "stats"
instance FromJSON Tree where
parseJSON = withObject "Tree" $ \o -> Tree
<$> o .: "sha"
<*> o .: "url"
<*> o .:? "tree" .!= V.empty
instance FromJSON GitTree where
parseJSON = withObject "GitTree" $ \o -> GitTree
<$> o .: "type"
<*> o .: "sha"
<*> o .:? "url"
<*> o .:? "size"
<*> o .: "path"
<*> o .: "mode"
instance FromJSON GitCommit where
parseJSON = withObject "GitCommit" $ \o -> GitCommit
<$> o .: "message"
<*> o .: "url"
<*> o .: "committer"
<*> o .: "author"
<*> o .: "tree"
<*> o .:? "sha"
<*> o .:? "parents" .!= V.empty
instance FromJSON GitUser where
parseJSON = withObject "GitUser" $ \o -> GitUser
<$> o .: "name"
<*> o .: "email"
<*> o .: "date"
instance FromJSON File where
parseJSON = withObject "File" $ \o -> File
<$> o .:? "blob_url"
<*> o .: "status"
<*> o .:? "raw_url"
<*> o .: "additions"
<*> o .:? "sha"
<*> o .: "changes"
<*> o .:? "patch"
<*> o .: "filename"
<*> o .: "deletions"
instance ToJSON NewGitReference where
toJSON (NewGitReference r s) = object [ "ref" .= r, "sha" .= s ]
instance FromJSON GitReference where
parseJSON = withObject "GitReference" $ \o -> GitReference
<$> o .: "object"
<*> o .: "url"
<*> o .: "ref"
instance FromJSON GitObject where
parseJSON = withObject "GitObject" $ \o -> GitObject
<$> o .: "type"
<*> o .: "sha"
<*> o .: "url"
instance FromJSON Diff where
parseJSON = withObject "Diff" $ \o -> Diff
<$> o .: "status"
<*> o .: "behind_by"
<*> o .: "patch_url"
<*> o .: "url"
<*> o .: "base_commit"
<*> o .:? "commits" .!= V.empty
<*> o .: "total_commits"
<*> o .: "html_url"
<*> o .:? "files" .!= V.empty
<*> o .: "ahead_by"
<*> o .: "diff_url"
<*> o .: "permalink_url"
instance FromJSON Blob where
parseJSON = withObject "Blob" $ \o -> Blob
<$> o .: "url"
<*> o .: "encoding"
<*> o .: "content"
<*> o .: "sha"
<*> o .: "size"
instance FromJSON Tag where
parseJSON = withObject "Tag" $ \o -> Tag
<$> o .: "name"
<*> o .: "zipball_url"
<*> o .: "tarball_url"
<*> o .: "commit"
instance FromJSON Branch where
parseJSON = withObject "Branch" $ \o -> Branch
<$> o .: "name"
<*> o .: "commit"
instance FromJSON BranchCommit where
parseJSON = withObject "BranchCommit" $ \o -> BranchCommit
<$> o .: "sha"
<*> o .: "url"