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

ADDED: endpoint PullRequest.changes #15

Merged
merged 1 commit into from
Aug 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.cdancy.bitbucket.rest.domain.pullrequest;

import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

import com.google.auto.value.AutoValue;

@AutoValue
public abstract class Change {

public abstract String contentId();

@Nullable
public abstract String fromContentId();

public abstract Path path();

public abstract boolean executable();

public abstract int percentUnchanged();

@Nullable
public abstract String type();

@Nullable
public abstract String nodeType();

@Nullable
public abstract Path srcPath();

public abstract boolean srcExecutable();

@Nullable
public abstract Links links();

Change() {
}

@SerializedNames({ "contentId", "fromContentId", "path", "executable",
"percentUnchanged", "type", "nodeType", "srcPath",
"srcExecutable", "links" })
public static Change create(String contentId, String fromContentId, Path path,
boolean executable, int percentUnchanged, String type,
String nodeType, Path srcPath, boolean srcExecutable,
Links links) {
return new AutoValue_Change(contentId, fromContentId, path, executable,
percentUnchanged, type, nodeType, srcPath, srcExecutable, links);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.cdancy.bitbucket.rest.domain.pullrequest;

import com.cdancy.bitbucket.rest.error.Error;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

import java.util.List;

@AutoValue
public abstract class PagedChangeResponse {

public abstract int size();

public abstract int limit();

public abstract boolean isLastPage();

public abstract List<Change> values();

public abstract int start();

@Nullable
public abstract String filter();

public abstract int nextPageStart();

@Nullable
public abstract List<Error> errors();

public PagedChangeResponse() {
}

@SerializedNames({ "size", "limit", "isLastPage", "values", "start", "filter", "nextPageStart", "errors" })
public static PagedChangeResponse create(int size, int limit, boolean isLastPage, List<Change> values,
int start, String filter, int nextPageStart, List<Error> errors) {
return new AutoValue_PagedChangeResponse(size, limit, isLastPage,
values != null ? ImmutableList.copyOf(values) : ImmutableList.<Change>of(),
start,
filter,
nextPageStart,
errors != null ? ImmutableList.copyOf(errors) : ImmutableList.<Error> of());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.cdancy.bitbucket.rest.domain.pullrequest;

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import org.jclouds.json.SerializedNames;

import java.util.List;

@AutoValue
public abstract class Path {

public abstract List<String> components();

public abstract String parent();

public abstract String name();

public abstract String extension();

public abstract String _toString();

Path() {
}

@SerializedNames({ "components", "parent", "name", "extension", "toString" })
public static Path create(List<String> components, String parent, String name,
String extension, String _toString) {
List<String> comp = (components != null) ? ImmutableList.copyOf(components) : ImmutableList.<String>of();
return new AutoValue_Path(comp,
parent,
name,
extension,
_toString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,23 @@
import javax.ws.rs.core.MediaType;

import com.cdancy.bitbucket.rest.domain.pullrequest.MergeStatus;
import com.cdancy.bitbucket.rest.domain.pullrequest.PagedChangeResponse;
import com.cdancy.bitbucket.rest.options.CreatePullRequest;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.RequestFilters;

import com.cdancy.bitbucket.rest.domain.pullrequest.Change;
import com.cdancy.bitbucket.rest.domain.pullrequest.PullRequest;
import com.cdancy.bitbucket.rest.fallbacks.BitbucketFallbacks.PullRequestOnError;
import com.cdancy.bitbucket.rest.fallbacks.BitbucketFallbacks.MergeStatusOnError;
import com.cdancy.bitbucket.rest.filters.BitbucketAuthentication;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.binders.BindToJsonPayload;

import java.util.List;

@Produces(MediaType.APPLICATION_JSON)
@RequestFilters(BitbucketAuthentication.class)
@Path("/rest/api/{jclouds.api-version}/projects")
Expand Down Expand Up @@ -102,4 +108,15 @@ PullRequest reopen(@PathParam("project") String project,
@PathParam("repo") String repo,
@PathParam("pullRequestId") int pullRequestId,
@QueryParam("version") int version);

@Named("pull-request:changes")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{project}/repos/{repo}/pull-requests/{pullRequestId}/changes")
@Fallback(PullRequestOnError.class)
@GET
PagedChangeResponse changes(@PathParam("project") String project,
@PathParam("repo") String repo,
@PathParam("pullRequestId") int pullRequestId,
@Nullable @QueryParam("withComments") Boolean withComments,
@Nullable @QueryParam("limit") Integer limit);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import com.cdancy.bitbucket.rest.domain.pullrequest.MinimalRepository;
import com.cdancy.bitbucket.rest.domain.pullrequest.MergeStatus;
import com.cdancy.bitbucket.rest.domain.pullrequest.PagedChangeResponse;
import com.cdancy.bitbucket.rest.domain.pullrequest.ProjectKey;
import com.cdancy.bitbucket.rest.domain.pullrequest.PullRequest;
import com.cdancy.bitbucket.rest.domain.pullrequest.Reference;
Expand Down Expand Up @@ -69,6 +70,14 @@ public void testGetPullRequest() {
}

@Test (dependsOnMethods = "testGetPullRequest")
public void testGetPullRequestChanges() {
PagedChangeResponse pr = api().changes(project, repo, prId, null, null);
assertNotNull(pr);
assertTrue(pr.errors().size() == 0);
assertTrue(pr.values().size() > 0);
}

@Test (dependsOnMethods = "testGetPullRequestChanges")
public void testDeclinePullRequest() {
PullRequest pr = api().decline(project, repo, prId, version);
assertNotNull(pr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

import com.cdancy.bitbucket.rest.domain.pullrequest.MinimalRepository;
import com.cdancy.bitbucket.rest.domain.pullrequest.PagedChangeResponse;
import org.testng.annotations.Test;

import com.cdancy.bitbucket.rest.BitbucketApi;
import com.cdancy.bitbucket.rest.BitbucketApiMetadata;
import com.cdancy.bitbucket.rest.domain.pullrequest.MergeStatus;
import com.cdancy.bitbucket.rest.domain.pullrequest.MinimalRepository;
import com.cdancy.bitbucket.rest.domain.pullrequest.ProjectKey;
import com.cdancy.bitbucket.rest.domain.pullrequest.PullRequest;
import com.cdancy.bitbucket.rest.domain.pullrequest.Reference;

import com.cdancy.bitbucket.rest.options.CreatePullRequest;
import org.testng.annotations.Test;

import com.cdancy.bitbucket.rest.BitbucketApi;
import com.cdancy.bitbucket.rest.BitbucketApiMetadata;
import com.cdancy.bitbucket.rest.internal.BaseBitbucketMockTest;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
Expand Down Expand Up @@ -221,4 +223,27 @@ public void testGetPullRequestNonExistent() throws Exception {
server.shutdown();
}
}

public void testGetPullRequestChanges() throws Exception {
MockWebServer server = mockEtcdJavaWebServer();

server.enqueue(new MockResponse().setBody(payloadFromResource("/pull-request-changes.json"))
.setResponseCode(200));
BitbucketApi baseApi = api(server.getUrl("/"));
PullRequestApi api = baseApi.pullRequestApi();
try {

PagedChangeResponse pr = api.changes("PRJ", "my-repo", 101, true, 12);
assertNotNull(pr);
assertTrue(pr.errors().size() == 0);
assertTrue(pr.values().size() == 1);
assertNotNull(pr);
assertSent(server, "GET", "/rest/api/" + BitbucketApiMetadata.API_VERSION
+ "/projects/PRJ/repos/my-repo/pull-requests/101/changes?withComments=true&limit=12");

} finally {
baseApi.close();
server.shutdown();
}
}
}
47 changes: 47 additions & 0 deletions src/test/resources/pull-request-changes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"size": 1,
"limit": 25,
"isLastPage": true,
"values": [
{
"contentId": "abcdef0123abcdef4567abcdef8987abcdef6543",
"fromContentId": "bcdef0123abcdef4567abcdef8987abcdef6543a",
"path": {
"components": [
"new",
"path",
"to",
"file.txt"
],
"parent": "new/path/to",
"name": "file.txt",
"extension": "txt",
"toString": "new/path/to/file.txt"
},
"executable": false,
"percentUnchanged": 98,
"type": "MOVE",
"nodeType": "FILE",
"srcPath": {
"components": [
"path",
"to",
"file.txt"
],
"parent": "path/to",
"name": "file.txt",
"extension": "txt",
"toString": "path/to/file.txt"
},
"srcExecutable": false,
"links": {
"self": [
{
"href": "http://link/to/restchange"
}
]
}
}
],
"start": 0
}