-
Notifications
You must be signed in to change notification settings - Fork 75
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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`. | ||
* @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 | ||
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. Could you please add the parameter description here? 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. 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) | ||
|
||
/** | ||
* 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) | ||
|
@@ -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. | ||
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. Could you please add the parameter description here? 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. 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) | ||
} |
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.
Could you please add the parameter description here?
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.
Done.