|
1 | 1 | package org.azd.git; |
2 | 2 |
|
3 | 3 | import org.azd.common.ApiVersion; |
| 4 | +import org.azd.common.types.JsonPatchDocument; |
4 | 5 | import org.azd.connection.Connection; |
5 | 6 | import org.azd.enums.*; |
6 | 7 | import org.azd.exceptions.AzDException; |
@@ -1650,6 +1651,122 @@ public GitPushes getPushes(String repositoryId) throws AzDException { |
1650 | 1651 | return MAPPER.mapJsonResponse(r, GitPushes.class); |
1651 | 1652 | } |
1652 | 1653 |
|
| 1654 | + /** |
| 1655 | + * Create a pull request status. |
| 1656 | + * The only required field for the status is Context.Name that uniquely identifies the status. |
| 1657 | + * Note that you can specify iterationId in the request body to post the status on the iteration. |
| 1658 | + * |
| 1659 | + * @param pullRequestId ID of the pull request. |
| 1660 | + * @param repositoryId The repository ID of the pull request’s target branch. |
| 1661 | + * @param gitPullRequestStatus Request body to create a new pull request status. |
| 1662 | + * @return GitStatus Object {@link GitStatus} |
| 1663 | + * @throws AzDException Default Api Exception handler. |
| 1664 | + **/ |
| 1665 | + @Override |
| 1666 | + public GitStatus createPullRequestStatus(int pullRequestId, String repositoryId, GitStatus gitPullRequestStatus) throws AzDException { |
| 1667 | + var resource = "pullRequests/" + pullRequestId + "/statuses"; |
| 1668 | + String r = send(RequestMethod.POST, CONNECTION, GIT, CONNECTION.getProject(), AREA + "/repositories", |
| 1669 | + repositoryId, resource, ApiVersion.GIT, null, gitPullRequestStatus, CustomHeader.JSON_CONTENT_TYPE); |
| 1670 | + |
| 1671 | + return MAPPER.mapJsonResponse(r, GitStatus.class); |
| 1672 | + } |
| 1673 | + |
| 1674 | + /** |
| 1675 | + * Delete pull request status. You can remove multiple statuses in one call by using Update operation. |
| 1676 | + * |
| 1677 | + * @param pullRequestId ID of the pull request. |
| 1678 | + * @param repositoryId The repository ID of the pull request’s target branch. |
| 1679 | + * @param statusId ID of the pull request status. |
| 1680 | + * @throws AzDException Default Api Exception handler. |
| 1681 | + **/ |
| 1682 | + @Override |
| 1683 | + public Void deletePullRequestStatus(int pullRequestId, String repositoryId, int statusId) throws AzDException { |
| 1684 | + try { |
| 1685 | + var resource = "pullRequests/" + pullRequestId + "/statuses/" + statusId; |
| 1686 | + String r = send(RequestMethod.DELETE, CONNECTION, GIT, CONNECTION.getProject(), AREA + "/repositories", |
| 1687 | + repositoryId, resource, ApiVersion.GIT, null, null, null); |
| 1688 | + if (!r.isEmpty()) MAPPER.mapJsonResponse(r, Map.class); |
| 1689 | + } catch (AzDException e) { |
| 1690 | + throw e; |
| 1691 | + } |
| 1692 | + return null; |
| 1693 | + } |
| 1694 | + |
| 1695 | + /** |
| 1696 | + * Get the specific pull request status by ID. The status ID is unique within the pull request across all iterations. |
| 1697 | + * |
| 1698 | + * @param pullRequestId ID of the pull request. |
| 1699 | + * @param repositoryId The repository ID of the pull request’s target branch. |
| 1700 | + * @param statusId ID of the pull request status. |
| 1701 | + * @return GitStatus Object {@link GitStatus} |
| 1702 | + * @throws AzDException Default Api Exception handler. |
| 1703 | + **/ |
| 1704 | + @Override |
| 1705 | + public GitStatus getPullRequestStatus(int pullRequestId, String repositoryId, int statusId) throws AzDException { |
| 1706 | + var resource = "pullRequests/" + pullRequestId + "/statuses/" + statusId; |
| 1707 | + |
| 1708 | + String r = send(RequestMethod.GET, CONNECTION, GIT, CONNECTION.getProject(), AREA + "/repositories", |
| 1709 | + repositoryId, resource, ApiVersion.GIT, null, null, null); |
| 1710 | + |
| 1711 | + return MAPPER.mapJsonResponse(r, GitStatus.class); |
| 1712 | + } |
| 1713 | + |
| 1714 | + /** |
| 1715 | + * Get all the statuses associated with a pull request. |
| 1716 | + * |
| 1717 | + * @param pullRequestId ID of the pull request. |
| 1718 | + * @param repositoryId The repository ID of the pull request’s target branch. |
| 1719 | + * @return GitStatuses Object {@link GitStatuses} |
| 1720 | + * @throws AzDException Default Api Exception handler. |
| 1721 | + **/ |
| 1722 | + @Override |
| 1723 | + public GitStatuses getPullRequestStatuses(int pullRequestId, String repositoryId) throws AzDException { |
| 1724 | + var resource = "pullRequests/" + pullRequestId + "/statuses"; |
| 1725 | + |
| 1726 | + String r = send(RequestMethod.GET, CONNECTION, GIT, CONNECTION.getProject(), AREA + "/repositories", |
| 1727 | + repositoryId, resource, ApiVersion.GIT, null, null, null); |
| 1728 | + |
| 1729 | + return MAPPER.mapJsonResponse(r, GitStatuses.class); |
| 1730 | + } |
| 1731 | + |
| 1732 | + /** |
| 1733 | + * Update pull request statuses collection. The only supported operation type is remove. |
| 1734 | + * This operation allows to delete multiple statuses in one call. |
| 1735 | + * The path of the remove operation should refer to the ID of the pull request status. |
| 1736 | + * For example path="/1" refers to the pull request status with ID 1. |
| 1737 | + * |
| 1738 | + * @param pullRequestId ID of the pull request. |
| 1739 | + * @param repositoryId The repository ID of the pull request’s target branch. |
| 1740 | + * @param propertiesToUpdate Collection of properties to update. |
| 1741 | + * E.g., [ |
| 1742 | + * { |
| 1743 | + * "op": "remove", |
| 1744 | + * "path": "/1", |
| 1745 | + * "from": null, |
| 1746 | + * "value": null |
| 1747 | + * }, |
| 1748 | + * { |
| 1749 | + * "op": "remove", |
| 1750 | + * "path": "/2", |
| 1751 | + * "from": null, |
| 1752 | + * "value": null |
| 1753 | + * } |
| 1754 | + * ] |
| 1755 | + * @throws AzDException Default Api Exception handler. |
| 1756 | + **/ |
| 1757 | + @Override |
| 1758 | + public Void updatePullRequestStatuses(int pullRequestId, String repositoryId, List<JsonPatchDocument> propertiesToUpdate) throws AzDException { |
| 1759 | + try { |
| 1760 | + var resource = "pullRequests/" + pullRequestId + "/statuses"; |
| 1761 | + String r = send(RequestMethod.PATCH, CONNECTION, GIT, CONNECTION.getProject(), AREA + "/repositories", |
| 1762 | + repositoryId, resource, ApiVersion.GIT, null, propertiesToUpdate, CustomHeader.JSON_PATCH); |
| 1763 | + if (!r.isEmpty()) MAPPER.mapJsonResponse(r, Map.class); |
| 1764 | + } catch (AzDException e) { |
| 1765 | + throw e; |
| 1766 | + } |
| 1767 | + return null; |
| 1768 | + } |
| 1769 | + |
1653 | 1770 | /** |
1654 | 1771 | * Create a fork of a parent repository |
1655 | 1772 | * |
|
0 commit comments