Skip to content

Commit 2503b54

Browse files
sajidanower23phadej
authored andcommitted
Label description (haskell-github#418)
* Add description field to IssueLabel * Add types for Update and New label * Use NewIssueLabel and UpdateIssueLabel for generating requests
1 parent b7ee2b8 commit 2503b54

2 files changed

Lines changed: 61 additions & 13 deletions

File tree

src/GitHub/Data/Definitions.hs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ data IssueLabel = IssueLabel
268268
{ labelColor :: !Text
269269
, labelUrl :: !URL
270270
, labelName :: !(Name IssueLabel)
271+
, labelDesc :: !(Maybe Text)
271272
}
272273
deriving (Show, Data, Typeable, Eq, Ord, Generic)
273274

@@ -279,3 +280,57 @@ instance FromJSON IssueLabel where
279280
<$> o .: "color"
280281
<*> o .:? "url" .!= URL "" -- in events there aren't URL
281282
<*> o .: "name"
283+
<*> o .:? "description"
284+
285+
286+
-------------------------------------------------------------------------------
287+
-- NewIssueLabel
288+
-------------------------------------------------------------------------------
289+
290+
data NewIssueLabel = NewIssueLabel
291+
{ newLabelColor :: !Text
292+
, newLabelName :: !(Name NewIssueLabel)
293+
, newLabelDesc :: !(Maybe Text)
294+
}
295+
deriving (Show, Data, Typeable, Eq, Ord, Generic)
296+
297+
instance NFData NewIssueLabel where rnf = genericRnf
298+
instance Binary NewIssueLabel
299+
300+
301+
instance ToJSON NewIssueLabel where
302+
toJSON (NewIssueLabel color lblName lblDesc) = object $ filter notNull
303+
[ "name" .= lblName
304+
, "color" .= color
305+
, "description" .= lblDesc
306+
]
307+
where
308+
notNull (_, Null) = False
309+
notNull (_, _) = True
310+
311+
312+
313+
-------------------------------------------------------------------------------
314+
-- UpdateIssueLabel
315+
-------------------------------------------------------------------------------
316+
317+
data UpdateIssueLabel = UpdateIssueLabel
318+
{ updateLabelColor :: !Text
319+
, updateLabelName :: !(Name UpdateIssueLabel)
320+
, updateLabelDesc :: !(Maybe Text)
321+
}
322+
deriving (Show, Data, Typeable, Eq, Ord, Generic)
323+
324+
instance NFData UpdateIssueLabel where rnf = genericRnf
325+
instance Binary UpdateIssueLabel
326+
327+
328+
instance ToJSON UpdateIssueLabel where
329+
toJSON (UpdateIssueLabel color lblName lblDesc) = object $ filter notNull
330+
[ "new_name" .= lblName
331+
, "color" .= color
332+
, "description" .= lblDesc
333+
]
334+
where
335+
notNull (_, Null) = False
336+
notNull (_, _) = True

src/GitHub/Endpoints/Issues/Labels.hs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,19 @@ labelR user repo lbl =
3838

3939
-- | Create a label.
4040
-- See <https://developer.github.com/v3/issues/labels/#create-a-label>
41-
createLabelR :: Name Owner -> Name Repo -> Name IssueLabel -> String -> Request 'RW IssueLabel
42-
createLabelR user repo lbl color =
43-
command Post paths $ encode body
44-
where
45-
paths = ["repos", toPathPart user, toPathPart repo, "labels"]
46-
body = object ["name" .= untagName lbl, "color" .= color]
41+
createLabelR :: Name Owner -> Name Repo -> NewIssueLabel -> Request 'RW IssueLabel
42+
createLabelR user repo =
43+
command Post ["repos", toPathPart user, toPathPart repo, "labels"] . encode
4744

4845
-- | Update a label.
4946
-- See <https://developer.github.com/v3/issues/labels/#update-a-label>
5047
updateLabelR :: Name Owner
5148
-> Name Repo
5249
-> Name IssueLabel -- ^ old label name
53-
-> Name IssueLabel -- ^ new label name
54-
-> String -- ^ new color
50+
-> UpdateIssueLabel -- ^ new label
5551
-> Request 'RW IssueLabel
56-
updateLabelR user repo oldLbl newLbl color =
57-
command Patch paths (encode body)
58-
where
59-
paths = ["repos", toPathPart user, toPathPart repo, "labels", toPathPart oldLbl]
60-
body = object ["name" .= untagName newLbl, "color" .= color]
52+
updateLabelR user repo oldLbl =
53+
command Patch ["repos", toPathPart user, toPathPart repo, "labels", toPathPart oldLbl] . encode
6154

6255
-- | Delete a label.
6356
-- See <https://developer.github.com/v3/issues/labels/#delete-a-label>

0 commit comments

Comments
 (0)