Skip to content

Commit 3e768ad

Browse files
Thomas M. DuBuissonphadej
authored andcommitted
Add pullRequestPatchR
1 parent 1d1d6e0 commit 3e768ad

File tree

5 files changed

+65
-14
lines changed

5 files changed

+65
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
[#338](https://github.com/phadej/github/pull/338)
1919
- Allow multiple assignees in NewIssue and EditIssue
2020
[#336](https://github.com/phadej/github/pull/336)
21+
- Add `pullRequestPatchR` and `pullRequestDiffR`
2122

2223
## Changes for 0.20
2324

spec/GitHub/PullRequestsSpec.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Data.FileEmbed (embedFile)
1414
import Data.Foldable (for_)
1515
import Data.String (fromString)
1616
import qualified Data.Vector as V
17+
import qualified Data.ByteString.Lazy.Char8 as LBS8
1718
import System.Environment (lookupEnv)
1819
import Test.Hspec
1920
(Spec, describe, it, pendingWith, shouldBe, shouldSatisfy)
@@ -37,6 +38,12 @@ spec = do
3738
GitHub.pullRequestsForR owner repo opts GitHub.FetchAll
3839
cs `shouldSatisfy` isRight
3940

41+
describe "pullRequestPatchR" $
42+
it "works" $ withAuth $ \auth -> do
43+
Right patch <- GitHub.executeRequest auth $
44+
GitHub.pullRequestPatchR "phadej" "github" (GitHub.IssueNumber 349)
45+
head (LBS8.lines patch) `shouldBe` "From c0e4ad33811be82e1f72ee76116345c681703103 Mon Sep 17 00:00:00 2001"
46+
4047
describe "decoding pull request payloads" $ do
4148
it "decodes a pull request 'opened' payload" $ do
4249
V.length (GitHub.simplePullRequestRequestedReviewers simplePullRequestOpened)
@@ -62,7 +69,6 @@ spec = do
6269
repos =
6370
[ ("thoughtbot", "paperclip")
6471
, ("phadej", "github")
65-
, ("haskell", "cabal")
6672
]
6773
opts = GitHub.stateClosed
6874

src/GitHub.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ module GitHub (
193193
-- | See <https://developer.github.com/v3/pulls/>
194194
pullRequestsForR,
195195
pullRequestR,
196+
pullRequestPatchR,
197+
pullRequestDiffR,
196198
createPullRequestR,
197199
updatePullRequestR,
198200
pullRequestCommitsR,

src/GitHub/Data/PullRequests.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ data SimplePullRequest = SimplePullRequest
3232
, simplePullRequestUser :: !SimpleUser
3333
, simplePullRequestPatchUrl :: !URL
3434
, simplePullRequestState :: !IssueState
35-
, simplePullRequestNumber :: !Int
35+
, simplePullRequestNumber :: !IssueNumber
3636
, simplePullRequestHtmlUrl :: !URL
3737
, simplePullRequestUpdatedAt :: !UTCTime
3838
, simplePullRequestBody :: !(Maybe Text)
@@ -57,7 +57,7 @@ data PullRequest = PullRequest
5757
, pullRequestUser :: !SimpleUser
5858
, pullRequestPatchUrl :: !URL
5959
, pullRequestState :: !IssueState
60-
, pullRequestNumber :: !Int
60+
, pullRequestNumber :: !IssueNumber
6161
, pullRequestHtmlUrl :: !URL
6262
, pullRequestUpdatedAt :: !UTCTime
6363
, pullRequestBody :: !(Maybe Text)

src/GitHub/Endpoints/PullRequests.hs

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ module GitHub.Endpoints.PullRequests (
1212
pullRequest',
1313
pullRequest,
1414
pullRequestR,
15+
pullRequestDiff',
16+
pullRequestDiff,
17+
pullRequestDiffR,
18+
pullRequestPatch',
19+
pullRequestPatch,
20+
pullRequestPatchR,
1521
createPullRequest,
1622
createPullRequestR,
1723
updatePullRequest,
@@ -33,6 +39,7 @@ import GitHub.Data
3339
import GitHub.Internal.Prelude
3440
import GitHub.Request
3541
import Prelude ()
42+
import Data.ByteString.Lazy (ByteString)
3643

3744
-- | All open pull requests for the repo, by owner and repo name.
3845
--
@@ -60,25 +67,60 @@ pullRequestsForR user repo opts = pagedQuery
6067
["repos", toPathPart user, toPathPart repo, "pulls"]
6168
(prModToQueryString opts)
6269

70+
-- | Obtain the diff of a pull request
71+
-- See <https://developer.github.com/v3/pulls/#get-a-single-pull-request>
72+
pullRequestDiff' :: Maybe Auth -> Name Owner -> Name Repo -> IssueNumber -> IO (Either Error ByteString)
73+
pullRequestDiff' auth user repo prid =
74+
executeRequestMaybe auth $ pullRequestDiffR user repo prid
75+
76+
-- | Obtain the diff of a pull request
77+
-- See <https://developer.github.com/v3/pulls/#get-a-single-pull-request>
78+
pullRequestDiff :: Name Owner -> Name Repo -> IssueNumber -> IO (Either Error ByteString)
79+
pullRequestDiff = pullRequestDiff' Nothing
80+
81+
-- | Query a single pull request to obtain the diff
82+
-- See <https://developer.github.com/v3/pulls/#get-a-single-pull-request>
83+
pullRequestDiffR :: Name Owner -> Name Repo -> IssueNumber -> GenRequest 'MtDiff rw ByteString
84+
pullRequestDiffR user repo prid =
85+
Query ["repos", toPathPart user, toPathPart repo, "pulls", toPathPart prid] []
86+
87+
-- | Obtain the patch of a pull request
88+
--
89+
-- See <https://developer.github.com/v3/pulls/#get-a-single-pull-request>
90+
pullRequestPatch' :: Maybe Auth -> Name Owner -> Name Repo -> IssueNumber -> IO (Either Error ByteString)
91+
pullRequestPatch' auth user repo prid =
92+
executeRequestMaybe auth $ pullRequestPatchR user repo prid
93+
94+
-- | Obtain the patch of a pull request
95+
-- See <https://developer.github.com/v3/pulls/#get-a-single-pull-request>
96+
pullRequestPatch :: Name Owner -> Name Repo -> IssueNumber -> IO (Either Error ByteString)
97+
pullRequestPatch = pullRequestPatch' Nothing
98+
99+
-- | Query a single pull request to obtain the patch
100+
-- See <https://developer.github.com/v3/pulls/#get-a-single-pull-request>
101+
pullRequestPatchR :: Name Owner -> Name Repo -> IssueNumber -> GenRequest 'MtPatch rw ByteString
102+
pullRequestPatchR user repo prid =
103+
Query ["repos", toPathPart user, toPathPart repo, "pulls", toPathPart prid] []
104+
63105
-- | A detailed pull request, which has much more information. This takes the
64106
-- repo owner and name along with the number assigned to the pull request.
65107
-- With authentification.
66108
--
67109
-- > pullRequest' (Just ("github-username", "github-password")) "thoughtbot" "paperclip" 562
68-
pullRequest' :: Maybe Auth -> Name Owner -> Name Repo -> Id PullRequest -> IO (Either Error PullRequest)
110+
pullRequest' :: Maybe Auth -> Name Owner -> Name Repo -> IssueNumber -> IO (Either Error PullRequest)
69111
pullRequest' auth user repo prid =
70112
executeRequestMaybe auth $ pullRequestR user repo prid
71113

72114
-- | A detailed pull request, which has much more information. This takes the
73115
-- repo owner and name along with the number assigned to the pull request.
74116
--
75117
-- > pullRequest "thoughtbot" "paperclip" 562
76-
pullRequest :: Name Owner -> Name Repo -> Id PullRequest -> IO (Either Error PullRequest)
118+
pullRequest :: Name Owner -> Name Repo -> IssueNumber -> IO (Either Error PullRequest)
77119
pullRequest = pullRequest' Nothing
78120

79121
-- | Query a single pull request.
80122
-- See <https://developer.github.com/v3/pulls/#get-a-single-pull-request>
81-
pullRequestR :: Name Owner -> Name Repo -> Id PullRequest -> Request k PullRequest
123+
pullRequestR :: Name Owner -> Name Repo -> IssueNumber -> Request k PullRequest
82124
pullRequestR user repo prid =
83125
query ["repos", toPathPart user, toPathPart repo, "pulls", toPathPart prid] []
84126

@@ -100,15 +142,15 @@ createPullRequestR user repo cpr =
100142
command Post ["repos", toPathPart user, toPathPart repo, "pulls"] (encode cpr)
101143

102144
-- | Update a pull request
103-
updatePullRequest :: Auth -> Name Owner -> Name Repo -> Id PullRequest -> EditPullRequest -> IO (Either Error PullRequest)
145+
updatePullRequest :: Auth -> Name Owner -> Name Repo -> IssueNumber -> EditPullRequest -> IO (Either Error PullRequest)
104146
updatePullRequest auth user repo prid epr =
105147
executeRequest auth $ updatePullRequestR user repo prid epr
106148

107149
-- | Update a pull request.
108150
-- See <https://developer.github.com/v3/pulls/#update-a-pull-request>
109151
updatePullRequestR :: Name Owner
110152
-> Name Repo
111-
-> Id PullRequest
153+
-> IssueNumber
112154
-> EditPullRequest
113155
-> Request 'RW PullRequest
114156
updatePullRequestR user repo prid epr =
@@ -119,20 +161,20 @@ updatePullRequestR user repo prid epr =
119161
-- With authentification.
120162
--
121163
-- > pullRequestCommits' (Just ("github-username", "github-password")) "thoughtbot" "paperclip" 688
122-
pullRequestCommits' :: Maybe Auth -> Name Owner -> Name Repo -> Id PullRequest -> IO (Either Error (Vector Commit))
164+
pullRequestCommits' :: Maybe Auth -> Name Owner -> Name Repo -> IssueNumber -> IO (Either Error (Vector Commit))
123165
pullRequestCommits' auth user repo prid =
124166
executeRequestMaybe auth $ pullRequestCommitsR user repo prid FetchAll
125167

126168
-- | All the commits on a pull request, given the repo owner, repo name, and
127169
-- the number of the pull request.
128170
--
129171
-- > pullRequestCommits "thoughtbot" "paperclip" 688
130-
pullRequestCommitsIO :: Name Owner -> Name Repo -> Id PullRequest -> IO (Either Error (Vector Commit))
172+
pullRequestCommitsIO :: Name Owner -> Name Repo -> IssueNumber -> IO (Either Error (Vector Commit))
131173
pullRequestCommitsIO = pullRequestCommits' Nothing
132174

133175
-- | List commits on a pull request.
134176
-- See <https://developer.github.com/v3/pulls/#list-commits-on-a-pull-request>
135-
pullRequestCommitsR :: Name Owner -> Name Repo -> Id PullRequest -> FetchCount -> Request k (Vector Commit)
177+
pullRequestCommitsR :: Name Owner -> Name Repo -> IssueNumber -> FetchCount -> Request k (Vector Commit)
136178
pullRequestCommitsR user repo prid =
137179
pagedQuery ["repos", toPathPart user, toPathPart repo, "pulls", toPathPart prid, "commits"] []
138180

@@ -141,20 +183,20 @@ pullRequestCommitsR user repo prid =
141183
-- With authentification.
142184
--
143185
-- > pullRequestFiles' (Just ("github-username", "github-password")) "thoughtbot" "paperclip" 688
144-
pullRequestFiles' :: Maybe Auth -> Name Owner -> Name Repo -> Id PullRequest -> IO (Either Error (Vector File))
186+
pullRequestFiles' :: Maybe Auth -> Name Owner -> Name Repo -> IssueNumber -> IO (Either Error (Vector File))
145187
pullRequestFiles' auth user repo prid =
146188
executeRequestMaybe auth $ pullRequestFilesR user repo prid FetchAll
147189

148190
-- | The individual files that a pull request patches. Takes the repo owner and
149191
-- name, plus the number assigned to the pull request.
150192
--
151193
-- > pullRequestFiles "thoughtbot" "paperclip" 688
152-
pullRequestFiles :: Name Owner -> Name Repo -> Id PullRequest -> IO (Either Error (Vector File))
194+
pullRequestFiles :: Name Owner -> Name Repo -> IssueNumber -> IO (Either Error (Vector File))
153195
pullRequestFiles = pullRequestFiles' Nothing
154196

155197
-- | List pull requests files.
156198
-- See <https://developer.github.com/v3/pulls/#list-pull-requests-files>
157-
pullRequestFilesR :: Name Owner -> Name Repo -> Id PullRequest -> FetchCount -> Request k (Vector File)
199+
pullRequestFilesR :: Name Owner -> Name Repo -> IssueNumber -> FetchCount -> Request k (Vector File)
158200
pullRequestFilesR user repo prid =
159201
pagedQuery ["repos", toPathPart user, toPathPart repo, "pulls", toPathPart prid, "files"] []
160202

0 commit comments

Comments
 (0)