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

Add possibility to delete branch Model Condition #70

Merged
merged 27 commits into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e2e10aa
Initial commit of branchModel
j0nathan33 May 23, 2017
796b972
Add FallBacks error for BranchModel
j0nathan33 May 23, 2017
2743b5c
Add mockTest + LiveTest
j0nathan33 May 23, 2017
afc4c7f
First commit of BranchModel update
j0nathan33 May 23, 2017
ba3dbfe
Fix build
j0nathan33 May 23, 2017
61156b5
Merge branch 'branchModel-list' into branchModel-Update
j0nathan33 May 23, 2017
a0796de
First commit of branch model condition for delete
j0nathan33 May 23, 2017
b41030f
Fix build
j0nathan33 May 23, 2017
a1ffd3b
Merge branch 'master' of https://github.com/cdancy/bitbucket-rest int…
j0nathan33 May 24, 2017
413b87a
Merge branch 'branchModel-list' into branchModel-Update
j0nathan33 May 24, 2017
193ac27
Merge branch 'branchModel-Update' into branchModel-delete
j0nathan33 May 24, 2017
8b48dea
Edit code after codeReview
j0nathan33 May 25, 2017
4243a25
Merge branch 'branchModel-list' into branchModel-Update
j0nathan33 May 25, 2017
0b643a6
Fix live Test
j0nathan33 May 25, 2017
95c7b5d
Merge branch 'branchModel-list' into branchModel-delete
j0nathan33 May 25, 2017
ec29dc1
Merge branch 'branchModel-Update' into branchModel-delete
j0nathan33 May 25, 2017
6fa0729
Remove duplicate Test
j0nathan33 May 25, 2017
d269843
Fix Test
j0nathan33 May 25, 2017
7b3eccd
Fix build
j0nathan33 May 25, 2017
c3d32ac
Merge branch 'master' of https://github.com/cdancy/bitbucket-rest int…
j0nathan33 May 26, 2017
413a1ce
Merge branch 'branchModel-Update' into branchModel-delete
j0nathan33 May 26, 2017
c100016
Merge branch 'master' of https://github.com/cdancy/bitbucket-rest int…
j0nathan33 May 29, 2017
83bc6b0
Change gitAttribute for windows
j0nathan33 May 29, 2017
2b1b803
Fix build
May 29, 2017
e2ec092
Remove line don't work in some enviromnent
May 29, 2017
b8069f4
Revert "Change gitAttribute for windows"
May 29, 2017
a441fe9
Add annotation Documentation
May 29, 2017
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
Expand Up @@ -17,16 +17,15 @@

package com.cdancy.bitbucket.rest;

import java.net.URI;
import java.util.Properties;

import org.jclouds.apis.ApiMetadata;
import org.jclouds.rest.internal.BaseHttpApiMetadata;

import com.cdancy.bitbucket.rest.config.BitbucketHttpApiModule;
import com.google.auto.service.AutoService;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.rest.internal.BaseHttpApiMetadata;

import java.net.URI;
import java.util.Properties;

@AutoService(ApiMetadata.class)
public class BitbucketApiMetadata extends BaseHttpApiMetadata<BitbucketApi> {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/cdancy/bitbucket/rest/features/BranchApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ BranchModel model(@PathParam("project") String project,
@PathParam("repo") String repo);

@Named("branch:get-model-configuration")
@Documentation({"https://jira.atlassian.com/browse/BSERV-5411"})
@Consumes(MediaType.APPLICATION_JSON)
@Path("/branch-utils/{jclouds.api-version}/projects/{project}/repos/{repo}/branchmodel/configuration")
@Fallback(BitbucketFallbacks.BranchModelConfigurationOnError.class)
Expand All @@ -128,6 +129,7 @@ BranchModelConfiguration getModelConfiguration(@PathParam("project") String proj
@PathParam("repo") String repo);

@Named("branch:get-model-configuration")
@Documentation({"https://jira.atlassian.com/browse/BSERV-5411"})
@Consumes(MediaType.APPLICATION_JSON)
@Path("/branch-utils/{jclouds.api-version}/projects/{project}/repos/{repo}/branchmodel/configuration")
@Fallback(BitbucketFallbacks.BranchModelConfigurationOnError.class)
Expand All @@ -136,6 +138,15 @@ BranchModelConfiguration updateModelConfiguration(@PathParam("project") String p
@PathParam("repo") String repo,
@BinderParam(BindToJsonPayload.class) CreateBranchModelConfiguration config);

@Named("branch:delete-model-configuration")
@Documentation({"https://jira.atlassian.com/browse/BSERV-5411"})
@Consumes(MediaType.APPLICATION_JSON)
@Path("/branch-utils/{jclouds.api-version}/projects/{project}/repos/{repo}/branchmodel/configuration")
@Fallback(BitbucketFallbacks.FalseOnError.class)
@DELETE
boolean deleteModelConfiguration(@PathParam("project") String project,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@documentation annotation for this? Searched online and couldn't find anything

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, this endpoint isn't in documentation.

Source : https://jira.atlassian.com/browse/BSERV-5411

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@j0nathan33 can you add the Documentation annotation and use that jira ISSUE?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I will do it.

@PathParam("repo") String repo);

@Named("branch:list-branch-permission")
@Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/4.14.1/bitbucket-ref-restriction-rest.html#idm45354011023456"})
@Consumes(MediaType.APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,20 @@ public void testUpdateBranchModelConfiguration() {
}
}

@Test(dependsOnMethods = {"testCreateBranch", "testListBranches"})
@Test(dependsOnMethods = {"testGetBranchModelConfiguration", "testCreateBranch", "testListBranches", "testUpdateBranchModelConfiguration"})
public void testDeleteBranchModelConfiguration() {
boolean success = api().deleteModelConfiguration(projectKey, repoKey);
assertThat(success).isTrue();
}

@Test(dependsOnMethods = {"testDeleteBranchModelConfiguration", "testGetBranchModelConfiguration", "testCreateBranch",
"testListBranches", "testUpdateBranchModelConfiguration"})
public void testGetBranchModelConfigurationOnError() {
BranchModelConfiguration configuration = api().getModelConfiguration(projectKey, "12345");
assertThat(configuration.errors()).isNotEmpty();
assertThat(configuration.development()).isNull();
assertThat(configuration.production()).isNull();
BranchModelConfiguration configuration = api().getModelConfiguration(projectKey, repoKey);
assertThat(configuration.types()).isEmpty();
assertThat(configuration.production()).isNull();
assertThat(configuration.development()).isNull();
assertThat(configuration.errors()).isNotEmpty();
}

private void checkDefaultBranchConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,42 @@ public void testUpdateBranchModelConfigurationOnError() throws Exception {
server.shutdown();
}
}

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

server.enqueue(new MockResponse().setResponseCode(204));
BitbucketApi baseApi = api(server.getUrl("/"));
BranchApi api = baseApi.branchApi();
try {
String projectKey = "PRJ";
String repoKey = "myrepo";
boolean success = api.deleteModelConfiguration(projectKey, repoKey);
assertThat(success).isTrue();
assertSent(server, "DELETE", "/rest/branch-utils/" + BitbucketApiMetadata.API_VERSION
+ "/projects/" + projectKey + "/repos/" + repoKey + "/branchmodel/configuration");
} finally {
baseApi.close();
server.shutdown();
}
}

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

server.enqueue(new MockResponse().setBody(payloadFromResource("/repository-not-exist.json")).setResponseCode(404));
BitbucketApi baseApi = api(server.getUrl("/"));
BranchApi api = baseApi.branchApi();
try {
String projectKey = "PRJ";
String repoKey = "myrepo";
boolean success = api.deleteModelConfiguration(projectKey, repoKey);
assertThat(success).isFalse();
assertSent(server, "DELETE", "/rest/branch-utils/" + BitbucketApiMetadata.API_VERSION
+ "/projects/" + projectKey + "/repos/" + repoKey + "/branchmodel/configuration");
} finally {
baseApi.close();
server.shutdown();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public void testEnableHookOnError() {
assertThat(hook.enabled()).isFalse();
}

@Test(dependsOnMethods = {"testGetRepository", "testCreateRepository", "testListHook", "testGetHook", "testCreateHook"})
@Test(dependsOnMethods = {"testGetRepository", "testCreateRepository", "testListHook", "testGetHook", "testEnableHook"})
public void testDisableHook() {
Hook hook = api().disableHook(projectKey, repoKey, hookKey);
assertThat(hook).isNotNull();
Expand Down