Skip to content

Commit

Permalink
#442: Pass preview flag on Azure Devops status requests
Browse files Browse the repository at this point in the history
Azure DevOps on-premise responds with an error if the `-preview` is not appended to the version number during the request to submit the pipeline status during Pull Request decoration. As the use of a preview version for this call does not seem to adversely affect invocation of this endpoint on Azure DevOps Cloud, the `-preview` flag has been unconditionally added to the status update, although it has not been added to any other invocations since they do not encounter the same error.
  • Loading branch information
mc1arke committed Oct 4, 2021
1 parent e657770 commit 46354b7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class AzureDevopsRestClient implements AzureDevopsClient {

private static final Logger LOGGER = Loggers.get(AzureDevopsRestClient.class);
private static final String API_VERSION = "4.1";
private static final String API_VERSION_PREVIEW = API_VERSION + "-preview";

private final String authToken;
private final String apiUrl;
Expand All @@ -65,7 +66,7 @@ public AzureDevopsRestClient(String apiUrl, String authToken, ObjectMapper objec

@Override
public void submitPullRequestStatus(String projectId, String repositoryName, int pullRequestId, GitPullRequestStatus status) throws IOException {
String url = String.format("%s/%s/_apis/git/repositories/%s/pullRequests/%s/statuses?api-version=%s", apiUrl, URLEncoder.encode(projectId, StandardCharsets.UTF_8), URLEncoder.encode(repositoryName, StandardCharsets.UTF_8), pullRequestId, API_VERSION);
String url = String.format("%s/%s/_apis/git/repositories/%s/pullRequests/%s/statuses?api-version=%s", apiUrl, URLEncoder.encode(projectId, StandardCharsets.UTF_8), URLEncoder.encode(repositoryName, StandardCharsets.UTF_8), pullRequestId, API_VERSION_PREVIEW);
execute(url, "post", objectMapper.writeValueAsString(status), null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ private void setupStubs() {
"}]}")));


wireMockRule.stubFor(post(urlEqualTo("/azure+Project/_apis/git/repositories/my+Repository/pullRequests/"+ pullRequestId +"/statuses?api-version=4.1"))
wireMockRule.stubFor(post(urlEqualTo("/azure+Project/_apis/git/repositories/my+Repository/pullRequests/"+ pullRequestId +"/statuses?api-version=4.1-preview"))
.withHeader("Content-Type", equalTo("application/json; charset=UTF-8"))
.withHeader("Authorization", equalTo(authHeader))
.withRequestBody(equalTo("{" +
Expand Down

0 comments on commit 46354b7

Please sign in to comment.