-
Notifications
You must be signed in to change notification settings - Fork 194
fix the PullRequest object so it can parse #285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
7b61960
6e92ab7
e76f68e
d067056
7fd8baa
71dabfc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,14 @@ module GitHub.Data.PullRequests ( | |
|
||
import GitHub.Data.Definitions | ||
import GitHub.Data.Id (Id) | ||
import GitHub.Data.Options (IssueState (..), MergeableState (..)) | ||
import GitHub.Data.Options (IssueState (..)) | ||
import GitHub.Data.Repos (Repo) | ||
import GitHub.Data.Request (StatusMap) | ||
import GitHub.Data.URL (URL) | ||
import GitHub.Internal.Prelude | ||
import Data.Vector as V (elem, snoc) | ||
import Data.Aeson.Types (Parser) | ||
import qualified Data.Text as T | ||
import Prelude () | ||
|
||
data SimplePullRequest = SimplePullRequest | ||
|
@@ -36,7 +39,7 @@ data SimplePullRequest = SimplePullRequest | |
, simplePullRequestHtmlUrl :: !URL | ||
, simplePullRequestUpdatedAt :: !UTCTime | ||
, simplePullRequestBody :: !(Maybe Text) | ||
, simplePullRequestAssignees :: (Vector SimpleUser) | ||
, simplePullRequestAssignees :: !(Vector SimpleUser) | ||
, simplePullRequestIssueUrl :: !URL | ||
, simplePullRequestDiffUrl :: !URL | ||
, simplePullRequestUrl :: !URL | ||
|
@@ -60,7 +63,7 @@ data PullRequest = PullRequest | |
, pullRequestHtmlUrl :: !URL | ||
, pullRequestUpdatedAt :: !UTCTime | ||
, pullRequestBody :: !(Maybe Text) | ||
, pullRequestAssignees :: (Vector SimpleUser) | ||
, pullRequestAssignees :: !(Vector SimpleUser) | ||
, pullRequestIssueUrl :: !URL | ||
, pullRequestDiffUrl :: !URL | ||
, pullRequestUrl :: !URL | ||
|
@@ -74,12 +77,10 @@ data PullRequest = PullRequest | |
, pullRequestComments :: !Count | ||
, pullRequestDeletions :: !Count | ||
, pullRequestAdditions :: !Count | ||
, pullRequestReviewComments :: !Count | ||
, pullRequestBase :: !PullRequestCommit | ||
, pullRequestCommits :: !Count | ||
, pullRequestMerged :: !Bool | ||
, pullRequestMergeable :: !(Maybe Bool) | ||
, pullRequestMergeableState :: !MergeableState | ||
} | ||
deriving (Show, Data, Typeable, Eq, Ord, Generic) | ||
|
||
|
@@ -160,6 +161,9 @@ data PullRequestEventType | |
| PullRequestUnassigned | ||
| PullRequestLabeled | ||
| PullRequestUnlabeled | ||
| PullRequestReviewRequested | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added these because the API docs list them. Not sure if it makes sense to make a catch-all |
||
| PullRequestReviewRequestRemoved | ||
| PullRequestEdited | ||
deriving (Show, Data, Typeable, Eq, Ord, Generic) | ||
|
||
instance NFData PullRequestEventType where rnf = genericRnf | ||
|
@@ -180,8 +184,22 @@ instance Binary PullRequestReference | |
-- JSON instances | ||
------------------------------------------------------------------------------- | ||
|
||
-- | Helper function, reads either the "assignee" OR "assigneed" OR | ||
-- both from a JSON object. | ||
getAssignees :: Object -> Parser (Vector SimpleUser) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd trust there's always There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this example has an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But its current variant https://api.github.com/repos/octocat/Hello-World/pulls does have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a downside to including both? If we include both then it will work either way. You yourself earlier posted an example which contained both keys (as does the one in that link). I'm fine removing it but this seems like the way to accommodate all configurations which are likely to appear. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @phadej if it's a dealbreaker for getting this merged then I can remove the |
||
getAssignees o = do | ||
assignees <- o .:? "assignees" .!= mempty | ||
maybeAssignee <- o .:? "assignee" | ||
pure $ case maybeAssignee of | ||
Nothing -> assignees | ||
Just assignee | assignee `V.elem` assignees -> assignees | ||
| otherwise -> assignees `V.snoc` assignee | ||
|
||
instance FromJSON SimplePullRequest where | ||
parseJSON = withObject "SimplePullRequest" $ \o -> SimplePullRequest | ||
parseJSON = withObject "SimplePullRequest" $ \o -> do | ||
-- | Either key, or both, might be present, and might contain | ||
-- redundant information. Take both keys and uniquify the list. | ||
SimplePullRequest | ||
<$> o .:? "closed_at" | ||
<*> o .: "created_at" | ||
<*> o .: "user" | ||
|
@@ -191,7 +209,7 @@ instance FromJSON SimplePullRequest where | |
<*> o .: "html_url" | ||
<*> o .: "updated_at" | ||
<*> o .:? "body" | ||
<*> o .: "assignees" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm 100% sure that API returns a list, and GitHub docs are wrong. You can have multiple assignees for PR/Issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check: https://api.github.com/repos/phadej/github/pulls/285, there are both keys "assignee" and "assignees" |
||
<*> getAssignees o | ||
<*> o .: "issue_url" | ||
<*> o .: "diff_url" | ||
<*> o .: "url" | ||
|
@@ -231,7 +249,7 @@ instance FromJSON PullRequest where | |
<*> o .: "html_url" | ||
<*> o .: "updated_at" | ||
<*> o .:? "body" | ||
<*> o .: "assignees" | ||
<*> getAssignees o | ||
<*> o .: "issue_url" | ||
<*> o .: "diff_url" | ||
<*> o .: "url" | ||
|
@@ -245,12 +263,10 @@ instance FromJSON PullRequest where | |
<*> o .: "comments" | ||
<*> o .: "deletions" | ||
<*> o .: "additions" | ||
<*> o .: "review_comments" | ||
<*> o .: "base" | ||
<*> o .: "commits" | ||
<*> o .: "merged" | ||
<*> o .:? "mergeable" | ||
<*> o .: "mergeable_state" | ||
|
||
instance FromJSON PullRequestLinks where | ||
parseJSON = withObject "PullRequestLinks" $ \o -> PullRequestLinks | ||
|
@@ -284,6 +300,10 @@ instance FromJSON PullRequestEventType where | |
parseJSON (String "unassigned") = pure PullRequestUnassigned | ||
parseJSON (String "labeled") = pure PullRequestLabeled | ||
parseJSON (String "unlabeled") = pure PullRequestUnlabeled | ||
parseJSON (String "review_requested") = pure PullRequestReviewRequested | ||
parseJSON (String "review_request_removed") = pure PullRequestReviewRequestRemoved | ||
parseJSON (String "edited") = pure PullRequestEdited | ||
parseJSON (String s) = fail $ "Unknown action type " <> T.unpack s | ||
parseJSON v = typeMismatch "Could not build a PullRequestEventType" v | ||
|
||
instance FromJSON PullRequestReference where | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this is removed? (and review comments?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah sorry, that was due to my confusion between pull request / pull request event. I'll put it back in