Skip to content

Commit bd363a9

Browse files
committed
Addresses issue #71
1 parent 08f8b45 commit bd363a9

File tree

4 files changed

+255
-0
lines changed

4 files changed

+255
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.azd.enums;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
@JsonIgnoreProperties(ignoreUnknown = true)
7+
public enum PullRequestTimeRange {
8+
/**
9+
* The date when the pull request was closed (completed, abandoned, or merged externally).
10+
*/
11+
@JsonProperty("closed")
12+
CLOSED,
13+
/**
14+
*
15+
* The date when the pull request was created.
16+
*/
17+
@JsonProperty("created")
18+
CREATED,
19+
}

azd/src/main/java/org/azd/git/GitApi.java

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,42 @@ public GitPullRequest getPullRequest(String repositoryName, int pullRequestId) t
352352
return MAPPER.mapJsonResponse(r, GitPullRequest.class);
353353
}
354354

355+
/***
356+
* Retrieve a pull request.
357+
* @param repositoryName The repository name of the pull request's target branch.
358+
* @param pullRequestId The ID of the pull request to retrieve.
359+
* @param includeCommits If true, the pull request will be returned with the associated commits.
360+
* @throws AzDException Default Api Exception handler.
361+
* @return {@link GitPullRequest} object
362+
*/
363+
@Override
364+
public GitPullRequest getPullRequest(String repositoryName, int pullRequestId, boolean includeCommits) throws AzDException {
365+
String r = send(RequestMethod.GET, CONNECTION, GIT, CONNECTION.getProject(), AREA + "/repositories",
366+
repositoryName, "pullrequests/" + pullRequestId, ApiVersion.GIT, Map.of("includeCommits", includeCommits),
367+
null, null);
368+
369+
return MAPPER.mapJsonResponse(r, GitPullRequest.class);
370+
}
371+
372+
/***
373+
* Retrieve a pull request.
374+
* @param repositoryName The repository name of the pull request's target branch.
375+
* @param pullRequestId The ID of the pull request to retrieve.
376+
* @param includeCommits If true, the pull request will be returned with the associated commits.
377+
* @param includeWorkItemRefs If true, the pull request will be returned with the associated work item references.
378+
* @throws AzDException Default Api Exception handler.
379+
* @return {@link GitPullRequest} object
380+
*/
381+
@Override
382+
public GitPullRequest getPullRequest(String repositoryName, int pullRequestId, boolean includeCommits,
383+
boolean includeWorkItemRefs) throws AzDException {
384+
String r = send(RequestMethod.GET, CONNECTION, GIT, CONNECTION.getProject(), AREA + "/repositories",
385+
repositoryName, "pullrequests/" + pullRequestId, ApiVersion.GIT,
386+
Map.of("includeCommits", includeCommits, "includeWorkItemRefs", includeWorkItemRefs), null, null);
387+
388+
return MAPPER.mapJsonResponse(r, GitPullRequest.class);
389+
}
390+
355391
/***
356392
* Retrieve a pull request.
357393
* @param pullRequestId The ID of the pull request to retrieve.
@@ -380,6 +416,107 @@ public PullRequests getPullRequests(String repositoryName) throws AzDException {
380416
return MAPPER.mapJsonResponse(r, PullRequests.class);
381417
}
382418

419+
/***
420+
* Retrieve all pull requests from a repository
421+
* @param repositoryName specify the repository name
422+
* @param top The number of pull requests to retrieve.
423+
* @throws AzDException Default Api Exception handler.
424+
* @return {@link PullRequests} object
425+
*/
426+
@Override
427+
public PullRequests getPullRequests(String repositoryName, int top) throws AzDException {
428+
String r = send(RequestMethod.GET, CONNECTION, GIT, CONNECTION.getProject(), AREA + "/repositories",
429+
repositoryName, "pullrequests", ApiVersion.GIT, Map.of("$top", top), null, null);
430+
431+
return MAPPER.mapJsonResponse(r, PullRequests.class);
432+
}
433+
434+
/***
435+
* Retrieve all pull requests from a repository
436+
* @param repositoryName specify the repository name
437+
* @param top The number of pull requests to retrieve.
438+
* @param skip The number of pull requests to ignore. For example, to retrieve results 101-150, set top to 50 and skip to 100.
439+
* @throws AzDException Default Api Exception handler.
440+
* @return {@link PullRequests} object
441+
*/
442+
@Override
443+
public PullRequests getPullRequests(String repositoryName, int top, int skip) throws AzDException {
444+
String r = send(RequestMethod.GET, CONNECTION, GIT, CONNECTION.getProject(), AREA + "/repositories",
445+
repositoryName, "pullrequests", ApiVersion.GIT, Map.of("$top", top, "$skip", skip), null, null);
446+
447+
return MAPPER.mapJsonResponse(r, PullRequests.class);
448+
}
449+
450+
/***
451+
* Retrieve all pull requests from a repository
452+
* @param repositoryName specify the repository name
453+
* @param top The number of pull requests to retrieve.
454+
* @param skip The number of pull requests to ignore. For example, to retrieve results 101-150, set top to 50 and skip to 100.
455+
* @param creatorId If set, search for pull requests that were created by this identity.
456+
* @throws AzDException Default Api Exception handler.
457+
* @return {@link PullRequests} object
458+
*/
459+
@Override
460+
public PullRequests getPullRequests(String repositoryName, int top, int skip, String creatorId) throws AzDException {
461+
String r = send(RequestMethod.GET, CONNECTION, GIT, CONNECTION.getProject(), AREA + "/repositories",
462+
repositoryName, "pullrequests", ApiVersion.GIT,
463+
Map.of("$top", top, "$skip", skip, "searchCriteria.creatorId", creatorId), null, null);
464+
465+
return MAPPER.mapJsonResponse(r, PullRequests.class);
466+
}
467+
468+
/***
469+
* Retrieve all pull requests from a repository
470+
* @param repositoryName specify the repository name
471+
* @param includeLinks Whether to include the _links field on the shallow references.
472+
* @throws AzDException Default Api Exception handler.
473+
* @return {@link PullRequests} object
474+
*/
475+
@Override
476+
public PullRequests getPullRequests(String repositoryName, boolean includeLinks) throws AzDException {
477+
String r = send(RequestMethod.GET, CONNECTION, GIT, CONNECTION.getProject(), AREA + "/repositories",
478+
repositoryName, "pullrequests", ApiVersion.GIT,
479+
Map.of("searchCriteria.includeLinks", includeLinks), null, null);
480+
481+
return MAPPER.mapJsonResponse(r, PullRequests.class);
482+
}
483+
484+
/***
485+
* Retrieve all pull requests from a repository
486+
* @param repositoryName specify the repository name
487+
* @param status If set, search for pull requests that are in this state. Defaults to Active if unset.
488+
* @throws AzDException Default Api Exception handler.
489+
* @return {@link PullRequests} object
490+
*/
491+
@Override
492+
public PullRequests getPullRequests(String repositoryName, PullRequestStatus status) throws AzDException {
493+
String r = send(RequestMethod.GET, CONNECTION, GIT, CONNECTION.getProject(), AREA + "/repositories",
494+
repositoryName, "pullrequests", ApiVersion.GIT,
495+
Map.of("searchCriteria.status", status), null, null);
496+
497+
return MAPPER.mapJsonResponse(r, PullRequests.class);
498+
}
499+
500+
/***
501+
* Retrieve all pull requests from a repository
502+
* @param repositoryName specify the repository name
503+
* @param gitPullRequestQueryParameters Property bag of query parameters pertaining to the pull requests.
504+
* @throws AzDException Default Api Exception handler.
505+
* @return {@link PullRequests} object
506+
*/
507+
@Override
508+
public PullRequests getPullRequests(String repositoryName, GitPullRequestQueryParameters gitPullRequestQueryParameters)
509+
throws AzDException {
510+
String r = send(RequestMethod.GET, CONNECTION, GIT, CONNECTION.getProject(), AREA + "/repositories",
511+
repositoryName, "pullrequests", ApiVersion.GIT,
512+
gitPullRequestQueryParameters != null
513+
? gitPullRequestQueryParameters.get()
514+
: new GitPullRequestQueryParameters().get(),
515+
null, null);
516+
517+
return MAPPER.mapJsonResponse(r, PullRequests.class);
518+
}
519+
383520
/***
384521
* Gets all pull requests from a project. To get the pull requests from
385522
* non-default project you have to call setProject method from {@link Connection}.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package org.azd.git.types;
2+
3+
import org.azd.enums.PullRequestStatus;
4+
import org.azd.enums.PullRequestTimeRange;
5+
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
9+
public class GitPullRequestQueryParameters {
10+
/**
11+
* The number of pull requests to retrieve.
12+
*/
13+
public Number top;
14+
/**
15+
* The number of pull requests to ignore. For example, to retrieve results 101-150, set top to 50 and skip to 100.
16+
*/
17+
public Number skip;
18+
/**
19+
* If set, search for pull requests that were created by this identity.
20+
*/
21+
public String creatorId;
22+
/**
23+
* Whether to include the _links field on the shallow references
24+
*/
25+
public Boolean includeLinks = false;
26+
/**
27+
* If specified, filters pull requests that created/closed before this date based on the queryTimeRangeType specified.
28+
*/
29+
public String maxTime;
30+
/**
31+
* If specified, filters pull requests that created/closed after this date based on the queryTimeRangeType specified.
32+
*/
33+
public String minTime;
34+
/**
35+
* The type of time range which should be used for minTime and maxTime. Defaults to Created if unset.
36+
*/
37+
public PullRequestTimeRange queryTimeRangeType;
38+
/**
39+
* If set, search for pull requests whose target branch is in this repository.
40+
*/
41+
public String repositoryId;
42+
/**
43+
* If set, search for pull requests that have this identity as a reviewer.
44+
*/
45+
public String reviewerId;
46+
/**
47+
* If set, search for pull requests from this branch.
48+
*/
49+
public String sourceRefName;
50+
/**
51+
* If set, search for pull requests whose source branch is in this repository.
52+
*/
53+
public String sourceRepositoryId;
54+
/**
55+
* If set, search for pull requests that are in this state. Defaults to Active if unset.
56+
*/
57+
public PullRequestStatus status;
58+
/**
59+
* If set, search for pull requests into this branch.
60+
*/
61+
public String targetRefName;
62+
63+
public Map<String, Object> get() {
64+
var queryParams = new HashMap<String, Object>();
65+
if (top != null) queryParams.put("$top", top);
66+
if (skip != null) queryParams.put("$skip", skip);
67+
if (creatorId != null) queryParams.put("searchCriteria.creatorId", creatorId);
68+
if (includeLinks) queryParams.put("searchCriteria.includeLinks", true);
69+
if (maxTime != null) queryParams.put("searchCriteria.maxTime", maxTime);
70+
if (minTime != null) queryParams.put("searchCriteria.minTime", minTime);
71+
if (queryTimeRangeType != null) queryParams.put("searchCriteria.queryTimeRangeType", queryTimeRangeType);
72+
if (repositoryId != null) queryParams.put("searchCriteria.repositoryId", repositoryId);
73+
if (reviewerId != null) queryParams.put("searchCriteria.reviewerId", reviewerId);
74+
if (sourceRefName != null) queryParams.put("searchCriteria.sourceRefName", sourceRefName);
75+
if (sourceRepositoryId != null) queryParams.put("searchCriteria.sourceRepositoryId", sourceRepositoryId);
76+
if (status != null) queryParams.put("searchCriteria.status", status);
77+
if (targetRefName != null) queryParams.put("searchCriteria.targetRefName", targetRefName);
78+
return queryParams;
79+
}
80+
}

azd/src/main/java/org/azd/interfaces/GitDetails.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,29 @@ GitPullRequest createPullRequest(String repositoryId, String sourceRefName, Stri
4545

4646
GitPullRequest getPullRequest(String repositoryName, int pullRequestId) throws AzDException;
4747

48+
GitPullRequest getPullRequest(String repositoryName, int pullRequestId, boolean includeCommits) throws AzDException;
49+
50+
GitPullRequest getPullRequest(String repositoryName, int pullRequestId, boolean includeCommits, boolean includeWorkItemRefs)
51+
throws AzDException;
52+
4853
GitPullRequest getPullRequestById(int pullRequestId) throws AzDException;
4954

5055
PullRequests getPullRequests(String repositoryName) throws AzDException;
5156

57+
PullRequests getPullRequests(String repositoryName, int top) throws AzDException;
58+
59+
PullRequests getPullRequests(String repositoryName, int top, int skip) throws AzDException;
60+
61+
PullRequests getPullRequests(String repositoryName, int top, int skip, String creatorId)
62+
throws AzDException;
63+
64+
PullRequests getPullRequests(String repositoryName, boolean includeLinks) throws AzDException;
65+
66+
PullRequests getPullRequests(String repositoryName, PullRequestStatus status) throws AzDException;
67+
68+
PullRequests getPullRequests(String repositoryName, GitPullRequestQueryParameters gitPullRequestQueryParameters)
69+
throws AzDException;
70+
5271
PullRequests getPullRequestsByProject() throws AzDException;
5372

5473
PullRequests getPullRequestsByProject(int top) throws AzDException;

0 commit comments

Comments
 (0)