-
Notifications
You must be signed in to change notification settings - Fork 194
/
Copy pathGitData.hs
355 lines (297 loc) · 9.54 KB
/
GitData.hs
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
-----------------------------------------------------------------------------
-- |
-- License : BSD-3-Clause
-- Maintainer : Oleg Grenrus <[email protected]>
--
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, Typeable, Data)
data Stats = Stats
{ statsAdditions :: !Int
, statsTotal :: !Int
, statsDeletions :: !Int
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData Stats where rnf = genericRnf
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, Typeable, Eq, Ord, Generic)
instance NFData Commit where rnf = genericRnf
instance Binary Commit
data Tree = Tree
{ treeSha :: !(Name Tree)
, treeUrl :: !URL
, treeGitTrees :: !(Vector GitTree)
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData Tree where rnf = genericRnf
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, Typeable, Eq, Ord, Generic)
instance NFData GitTree where rnf = genericRnf
instance Binary GitTree
data NewTree = NewTree
{ newBaseTree :: !(Name Tree)
, newTreeGitTrees :: !(Vector NewGitTree)
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData NewTree where rnf = genericRnf
instance Binary NewTree
data NewGitTree = NewGitTree
{ newGitTreePath :: !Text
, newGitTreeMode :: !Text
, newGitTreeContent :: !Text
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData NewGitTree where rnf = genericRnf
instance Binary NewGitTree
data GitCommit = GitCommit
{ gitCommitMessage :: !Text
, gitCommitUrl :: !URL
, gitCommitCommitter :: !GitUser
, gitCommitAuthor :: !GitUser
, gitCommitTree :: !Tree
, gitCommitSha :: !(Maybe (Name GitCommit))
, gitCommitParents :: !(Vector Tree)
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData GitCommit where rnf = genericRnf
instance Binary GitCommit
data NewGitCommit = NewGitCommit
{ newGitCommitMessage :: !Text
, newGitCommitTree :: !(Name Tree)
, newGitCommitParents :: !(Vector (Name GitCommit))
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData NewGitCommit where rnf = genericRnf
instance Binary NewGitCommit
data Blob = Blob
{ blobUrl :: !URL
, blobEncoding :: !Text
, blobContent :: !Text
, blobSha :: !(Name Blob)
, blobSize :: !Int
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData Blob where rnf = genericRnf
instance Binary Blob
data Tag = Tag
{ tagName :: !Text
, tagZipballUrl :: !URL
, tagTarballUrl :: !URL
, tagCommit :: !BranchCommit
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData Tag where rnf = genericRnf
instance Binary Tag
data Branch = Branch
{ branchName :: !Text
, branchCommit :: !BranchCommit
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData Branch where rnf = genericRnf
data BranchCommit = BranchCommit
{ branchCommitSha :: !Text
, branchCommitUrl :: !URL
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData BranchCommit where rnf = genericRnf
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, Typeable, Eq, Ord, Generic)
instance NFData Diff where rnf = genericRnf
instance Binary Diff
data NewGitReference = NewGitReference
{ newGitReferenceRef :: !Text
, newGitReferenceSha :: !Text
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData NewGitReference where rnf = genericRnf
instance Binary NewGitReference
data GitReference = GitReference
{ gitReferenceObject :: !GitObject
, gitReferenceUrl :: !URL
, gitReferenceRef :: !Text
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData GitReference where rnf = genericRnf
instance Binary GitReference
data GitObject = GitObject
{ gitObjectType :: !Text
, gitObjectSha :: !Text
, gitObjectUrl :: !URL
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData GitObject where rnf = genericRnf
instance Binary GitObject
data GitUser = GitUser
{ gitUserName :: !Text
, gitUserEmail :: !Text
, gitUserDate :: !UTCTime
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData GitUser where rnf = genericRnf
instance Binary GitUser
data File = File
{ fileBlobUrl :: !(Maybe URL)
, fileStatus :: !Text
, fileRawUrl :: !(Maybe URL)
, fileAdditions :: !Int
, fileSha :: !Text
, fileChanges :: !Int
, filePatch :: !(Maybe Text)
, fileFilename :: !Text
, fileDeletions :: !Int
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData File where rnf = genericRnf
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"
<*> o .:? "author"
<*> o .:? "files" .!= V.empty
<*> o .:? "stats"
instance ToJSON NewGitCommit where
toJSON (NewGitCommit message tree parents) = object [ "message" .= message, "tree" .= tree, "parents" .= parents ]
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 ToJSON NewTree where
toJSON (NewTree b tree) = object [ "base_tree" .= b, "tree" .= tree ]
instance ToJSON NewGitTree where
toJSON (NewGitTree path mode content) = object [ "path" .= path, "mode" .= mode, "content" .= content ]
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"