Skip to content

Commit ef9ea4d

Browse files
committed
Github.PullReqests.pullRequestReviewComments . Change the Comment record to handle this, adding another Maybe where there was once a String (commentHtmlUrl).
1 parent 0d8ed5b commit ef9ea4d

File tree

7 files changed

+34
-5
lines changed

7 files changed

+34
-5
lines changed

Github/Data.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ instance FromJSON Comment where
104104
<*> o .: "body"
105105
<*> o .: "commit_id"
106106
<*> o .: "updated_at"
107-
<*> o .: "html_url"
107+
<*> o .:? "html_url"
108108
<*> o .: "url"
109109
<*> o .: "created_at"
110110
<*> o .: "path"

Github/Data/Definitions.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ data Comment = Comment {
9292
,commentBody :: String
9393
,commentCommitId :: String
9494
,commentUpdatedAt :: UTCTime
95-
,commentHtmlUrl :: String
95+
,commentHtmlUrl :: Maybe String
9696
,commentUrl :: String
9797
,commentCreatedAt :: UTCTime
9898
,commentPath :: Maybe String

Github/PullRequests.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Github.PullRequests (
33
,pullRequest
44
,pullRequestCommits
55
,pullRequestFiles
6+
,pullRequestReviewComments
67
,module Github.Data
78
) where
89

@@ -24,3 +25,7 @@ pullRequestCommits userName repoName number =
2425
pullRequestFiles :: String -> String -> Int -> IO (Either Error [File])
2526
pullRequestFiles userName repoName number =
2627
githubGet ["repos", userName, repoName, "pulls", show number, "files"]
28+
29+
pullRequestReviewComments :: String -> String -> Int -> IO (Either Error [Comment])
30+
pullRequestReviewComments userName repoName number =
31+
githubGet ["repos", userName, repoName, "pulls", show number, "comments"]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module ListComments where
2+
3+
import qualified Github.PullRequests as Github
4+
import Data.List
5+
6+
main = do
7+
possiblePullRequestComments <- Github.pullRequestReviewComments "thoughtbot" "factory_girl" 256
8+
case possiblePullRequestComments of
9+
(Left error) -> putStrLn $ "Error: " ++ (show error)
10+
(Right comments) -> putStrLn $ intercalate "\n\n" $ map formatComment comments
11+
12+
formatComment :: Github.Comment -> String
13+
formatComment comment =
14+
"Author: " ++ (formatAuthor $ Github.commentUser comment) ++
15+
"\nUpdated: " ++ (show $ Github.commentUpdatedAt comment) ++
16+
(maybe "" ("\nURL: "++) $ Github.commentHtmlUrl comment) ++
17+
"\n\n" ++ (Github.commentBody comment)
18+
19+
formatAuthor :: Github.GithubUser -> String
20+
formatAuthor user =
21+
(Github.githubUserLogin user) ++ " (" ++ (Github.githubUserUrl user) ++ ")"

samples/Repos/Commits/CommitComment.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module CommitComment where
22

33
import qualified Github.Repos.Commits as Github
4+
import Data.Maybe (maybe)
45

56
main = do
67
possibleComment <- Github.commitCommentFor "thoughtbot" "paperclip" "669575"
@@ -12,7 +13,7 @@ formatComment :: Github.Comment -> String
1213
formatComment comment =
1314
"Author: " ++ (formatAuthor $ Github.commentUser comment) ++
1415
"\nUpdated: " ++ (show $ Github.commentUpdatedAt comment) ++
15-
"\nURL: " ++ (Github.commentHtmlUrl comment) ++
16+
(maybe "" ("\nURL: "++) $ Github.commentHtmlUrl comment) ++
1617
"\n\n" ++ (Github.commentBody comment)
1718

1819
formatAuthor :: Github.GithubUser -> String

samples/Repos/Commits/CommitComments.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module CommitComments where
22

33
import qualified Github.Repos.Commits as Github
44
import Data.List
5+
import Data.Maybe (maybe)
56

67
main = do
78
possibleComments <- Github.commitCommentsFor "thoughtbot" "paperclip" "41f685f6e01396936bb8cd98e7cca517e2c7d96b"
@@ -13,7 +14,7 @@ formatComment :: Github.Comment -> String
1314
formatComment comment =
1415
"Author: " ++ (formatAuthor $ Github.commentUser comment) ++
1516
"\nUpdated: " ++ (show $ Github.commentUpdatedAt comment) ++
16-
"\nURL: " ++ (Github.commentHtmlUrl comment) ++
17+
(maybe "" ("\nURL: "++) $ Github.commentHtmlUrl comment) ++
1718
"\n\n" ++ (Github.commentBody comment)
1819

1920
formatAuthor :: Github.GithubUser -> String

samples/Repos/Commits/RepoComments.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module RepoComments where
22

33
import qualified Github.Repos.Commits as Github
44
import Data.List
5+
import Data.Maybe (maybe)
56

67
main = do
78
possibleComments <- Github.commentsFor "thoughtbot" "paperclip"
@@ -13,7 +14,7 @@ formatComment :: Github.Comment -> String
1314
formatComment comment =
1415
"Author: " ++ (formatAuthor $ Github.commentUser comment) ++
1516
"\nUpdated: " ++ (show $ Github.commentUpdatedAt comment) ++
16-
"\nURL: " ++ (Github.commentHtmlUrl comment) ++
17+
(maybe "" ("\nURL: "++) $ Github.commentHtmlUrl comment) ++
1718
"\n\n" ++ (Github.commentBody comment)
1819

1920
formatAuthor :: Github.GithubUser -> String

0 commit comments

Comments
 (0)