Skip to content
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

Add pagination support for PullRequest ops #198

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions github4s/shared/src/main/scala/github4s/GithubAPIs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,7 @@ class GHIssues(accessToken: Option[String] = None)(implicit O: IssueOps[GitHub4s

class GHActivities(accessToken: Option[String] = None)(implicit O: ActivityOps[GitHub4s]) {

def setThreadSub(
id: Int,
subscribed: Boolean,
ignored: Boolean): GHIO[GHResponse[Subscription]] =
def setThreadSub(id: Int, subscribed: Boolean, ignored: Boolean): GHIO[GHResponse[Subscription]] =
O.setThreadSub(id, subscribed, ignored, accessToken)

def listStargazers(
Expand Down Expand Up @@ -334,16 +331,18 @@ class GHPullRequests(accessToken: Option[String] = None)(implicit O: PullRequest
def list(
owner: String,
repo: String,
filters: List[PRFilter] = Nil
filters: List[PRFilter] = Nil,
pagination: Option[Pagination] = None
): GHIO[GHResponse[List[PullRequest]]] =
O.listPullRequests(owner, repo, filters, accessToken)
O.listPullRequests(owner, repo, filters, accessToken, pagination)

def listFiles(
owner: String,
repo: String,
number: Int
number: Int,
pagination: Option[Pagination] = None
): GHIO[GHResponse[List[PullRequestFile]]] =
O.listPullRequestFiles(owner, repo, number, accessToken)
O.listPullRequestFiles(owner, repo, number, accessToken, pagination)

def create(
owner: String,
Expand All @@ -358,9 +357,10 @@ class GHPullRequests(accessToken: Option[String] = None)(implicit O: PullRequest
def listReviews(
owner: String,
repo: String,
pullRequest: Int
pullRequest: Int,
pagination: Option[Pagination] = None
): GHIO[GHResponse[List[PullRequestReview]]] =
O.listPullRequestReviews(owner, repo, pullRequest, accessToken)
O.listPullRequestReviews(owner, repo, pullRequest, accessToken, pagination)

def getReview(
owner: String,
Expand Down
201 changes: 107 additions & 94 deletions github4s/shared/src/main/scala/github4s/api/PullRequests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,87 +28,94 @@ import scala.language.higherKinds

/** Factory to encapsulate calls related to PullRequests operations */
class PullRequests[C, M[_]](
implicit urls: GithubApiUrls,
C: Capture[M],
httpClientImpl: HttpRequestBuilderExtension[C, M]) {
implicit urls: GithubApiUrls,
C: Capture[M],
httpClientImpl: HttpRequestBuilderExtension[C, M]) {

import Decoders._
import Encoders._

val httpClient = new HttpClient[C, M]

/**
* List pull requests for a repository
*
* @param accessToken to identify the authenticated user
* @param headers optional user headers to include in the request
* @param owner of the repo
* @param repo name of the repo
* @param filters define the filter list. Options are:
* - state: Either `open`, `closed`, or `all` to filter by state. Default: `open`
* - head: Filter pulls by head user and branch name in the format of `user:ref-name`.
* Example: `github:new-script-format`.
* - base: Filter pulls by base branch name. Example: `gh-pages`.
* - sort: What to sort results by. Can be either `created`, `updated`, `popularity` (comment count)
* or `long-running` (age, filtering by pulls updated in the last month). Default: `created`
* - direction: The direction of the sort. Can be either `asc` or `desc`.
* Default: `desc` when sort is created or sort is not specified, otherwise `asc`.
* @return a GHResponse with the pull request list.
*/
* List pull requests for a repository
*
* @param accessToken to identify the authenticated user
* @param headers optional user headers to include in the request
* @param owner of the repo
* @param repo name of the repo
* @param filters define the filter list. Options are:
* - state: Either `open`, `closed`, or `all` to filter by state. Default: `open`
* - head: Filter pulls by head user and branch name in the format of `user:ref-name`.
* Example: `github:new-script-format`.
* - base: Filter pulls by base branch name. Example: `gh-pages`.
* - sort: What to sort results by. Can be either `created`, `updated`, `popularity` (comment count)
* or `long-running` (age, filtering by pulls updated in the last month). Default: `created`
* - direction: The direction of the sort. Can be either `asc` or `desc`.
* Default: `desc` when sort is created or sort is not specified, otherwise `asc`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add the parameter description here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* @return a GHResponse with the pull request list.
*/
def list(
accessToken: Option[String] = None,
headers: Map[String, String] = Map(),
owner: String,
repo: String,
filters: List[PRFilter] = Nil): M[GHResponse[List[PullRequest]]] =
accessToken: Option[String] = None,
headers: Map[String, String] = Map(),
owner: String,
repo: String,
filters: List[PRFilter] = Nil,
pagination: Option[Pagination] = None): M[GHResponse[List[PullRequest]]] =
httpClient.get[List[PullRequest]](
accessToken,
s"repos/$owner/$repo/pulls",
headers,
filters.map(_.tupled).toMap)
filters.map(_.tupled).toMap,
pagination)

/**
* List files for a specific pull request
*
* @param accessToken to identify the authenticated user
* @param headers optional user headers to include in the request
* @param owner of the repo
* @param repo name of the repo
* @param number of the pull request for which we want to list the files
* @return a GHResponse with the list of files affected by the pull request identified by number.
*/
* List files for a specific pull request
*
* @param accessToken to identify the authenticated user
* @param headers optional user headers to include in the request
* @param owner of the repo
* @param repo name of the repo
* @param number of the pull request for which we want to list the files
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add the parameter description here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* @return a GHResponse with the list of files affected by the pull request identified by number.
*/
def listFiles(
accessToken: Option[String] = None,
headers: Map[String, String] = Map(),
owner: String,
repo: String,
number: Int): M[GHResponse[List[PullRequestFile]]] =
accessToken: Option[String] = None,
headers: Map[String, String] = Map(),
owner: String,
repo: String,
number: Int,
pagination: Option[Pagination] = None): M[GHResponse[List[PullRequestFile]]] =
httpClient
.get[List[PullRequestFile]](accessToken, s"repos/$owner/$repo/pulls/$number/files", headers)
.get[List[PullRequestFile]](
accessToken,
s"repos/$owner/$repo/pulls/$number/files",
headers,
pagination = pagination)
Copy link
Contributor

@BenFradet BenFradet Mar 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this scalafmt? the indent seems weird

Copy link
Contributor Author

@lloydmeta lloydmeta Mar 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

I stopped running Scalafmt because the repo was overall not well formatted; fixed this manually.


/**
* Create a pull request
*
* @param accessToken Token to identify the authenticated user
* @param headers Optional user headers to include in the request
* @param owner Owner of the repo
* @param repo Name of the repo
* @param newPullRequest The title and body parameters or the issue parameter
* @param head The name of the branch where your changes are implemented. For cross-repository pull
* requests in the same network, namespace head with a user like this: username:branch.
* @param base The name of the branch you want the changes pulled into. This should be an existing branch
* on the current repository. You cannot submit a pull request to one repository that
* @param maintainerCanModify Indicates whether maintainers can modify the pull request, Default:Some(true).
*/
* Create a pull request
*
* @param accessToken Token to identify the authenticated user
* @param headers Optional user headers to include in the request
* @param owner Owner of the repo
* @param repo Name of the repo
* @param newPullRequest The title and body parameters or the issue parameter
* @param head The name of the branch where your changes are implemented. For cross-repository pull
* requests in the same network, namespace head with a user like this: username:branch.
* @param base The name of the branch you want the changes pulled into. This should be an existing branch
* on the current repository. You cannot submit a pull request to one repository that
* @param maintainerCanModify Indicates whether maintainers can modify the pull request, Default:Some(true).
*/
def create(
accessToken: Option[String] = None,
headers: Map[String, String] = Map(),
owner: String,
repo: String,
newPullRequest: NewPullRequest,
head: String,
base: String,
maintainerCanModify: Option[Boolean] = Some(true)): M[GHResponse[PullRequest]] = {
accessToken: Option[String] = None,
headers: Map[String, String] = Map(),
owner: String,
repo: String,
newPullRequest: NewPullRequest,
head: String,
base: String,
maintainerCanModify: Option[Boolean] = Some(true)): M[GHResponse[PullRequest]] = {
val data: CreatePullRequest = newPullRequest match {
case NewPullRequestData(title, body) ⇒
CreatePullRequestData(title, head, base, body, maintainerCanModify)
Expand All @@ -120,40 +127,46 @@ class PullRequests[C, M[_]](
}

/**
* List pull request reviews.
*
* @param accessToken Token to identify the authenticated user
* @param headers Optional user header to include in the request
* @param owner Owner of the repo
* @param repo Name of the repo
* @param pullRequest ID number of the PR to get reviews for.
*/
* List pull request reviews.
*
* @param accessToken Token to identify the authenticated user
* @param headers Optional user header to include in the request
* @param owner Owner of the repo
* @param repo Name of the repo
* @param pullRequest ID number of the PR to get reviews for.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add the parameter description here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

*/
def listReviews(
accessToken: Option[String] = None,
headers: Map[String, String] = Map(),
owner: String,
repo: String,
pullRequest: Int): M[GHResponse[List[PullRequestReview]]] = {
httpClient.get[List[PullRequestReview]](accessToken, s"repos/$owner/$repo/pulls/$pullRequest/reviews", headers)
}
accessToken: Option[String] = None,
headers: Map[String, String] = Map(),
owner: String,
repo: String,
pullRequest: Int,
pagination: Option[Pagination] = None): M[GHResponse[List[PullRequestReview]]] =
httpClient.get[List[PullRequestReview]](
accessToken,
s"repos/$owner/$repo/pulls/$pullRequest/reviews",
headers,
pagination = pagination)

/**
* Get a specific pull request review.
*
* @param accessToken Token to identify the authenticated user
* @param headers Optional user header to include in the request
* @param owner Owner of the repo
* @param repo Name of the repo
* @param pullRequest ID number of the PR to get reviews for
* @param review ID number of the review to retrieve.
*/
* Get a specific pull request review.
*
* @param accessToken Token to identify the authenticated user
* @param headers Optional user header to include in the request
* @param owner Owner of the repo
* @param repo Name of the repo
* @param pullRequest ID number of the PR to get reviews for
* @param review ID number of the review to retrieve.
*/
def getReview(
accessToken: Option[String] = None,
headers: Map[String, String] = Map(),
owner: String,
repo: String,
pullRequest: Int,
review: Int): M[GHResponse[PullRequestReview]] = {
httpClient.get[PullRequestReview](accessToken, s"repos/$owner/$repo/pulls/$pullRequest/reviews/$review", headers)
}
accessToken: Option[String] = None,
headers: Map[String, String] = Map(),
owner: String,
repo: String,
pullRequest: Int,
review: Int): M[GHResponse[PullRequestReview]] =
httpClient.get[PullRequestReview](
accessToken,
s"repos/$owner/$repo/pulls/$pullRequest/reviews/$review",
headers)
}