/JDOE/my-repo.git",
72 | "name": "ssh"
73 | }
74 | ],
75 | "self": [
76 | {
77 | "href": "http://link/to/repository"
78 | }
79 | ]
80 | }
81 | }
--------------------------------------------------------------------------------
/.github/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 |
2 | # How to contribute
3 |
4 | ## Getting Started
5 |
6 | * Make sure you have a [GitHub account](https://github.com/signup/free)
7 | * Submit a ticket for your issue, assuming one does not already exist.
8 | * Clearly describe the issue including steps to reproduce when it is a bug.
9 | * Make sure you fill in the earliest version that you know has the issue.
10 | * Fork the repository on GitHub
11 |
12 | ## Making Changes
13 |
14 | * Create a topic branch from where you want to base your work.
15 | * This is usually the master branch.
16 | * Only target release branches if you are certain your fix must be on that
17 | branch.
18 | * To quickly create a topic branch based on master; `git checkout -b
19 | fix/master/my_contribution master`. Please avoid working directly on the
20 | `master` branch.
21 | * Make commits of logical units.
22 | * Check for unnecessary whitespace with `git diff --check` before committing.
23 | * Make sure your commit messages are in the proper format:
24 |
25 | `ISSUE-1234: terse and to the point message describing change`
26 |
27 | * Make sure you have added the necessary tests for your changes.
28 | * Run _all_ the tests to assure nothing else was accidentally broken.
29 | * Make sure you've done a squash and rebase before submitting
30 |
31 | ## Submitting Changes
32 |
33 | * Push your changes to a topic branch in your fork of the repository.
34 | * Submit a pull request.
35 | * After feedback has been given we expect responses within two weeks. After two
36 | weeks we may close the pull request if it isn't showing any activity.
37 |
38 | # Additional Resources
39 |
40 | * [General GitHub documentation](https://help.github.com/)
41 | * [GitHub pull request documentation](https://help.github.com/send-pull-requests/)
42 | * [Squash and Rebase](https://github.com/ginatrapani/todo.txt-android/wiki/Squash-All-Commits-Related-to-a-Single-Issue-into-a-Single-Commit)
43 |
44 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/features/SystemApi.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.features;
19 |
20 | import com.cdancy.bitbucket.rest.annotations.Documentation;
21 | import jakarta.inject.Named;
22 | import jakarta.ws.rs.Consumes;
23 | import jakarta.ws.rs.GET;
24 | import jakarta.ws.rs.Path;
25 | import jakarta.ws.rs.Produces;
26 | import jakarta.ws.rs.core.MediaType;
27 |
28 | import org.jclouds.rest.annotations.RequestFilters;
29 |
30 | import com.cdancy.bitbucket.rest.domain.system.Version;
31 | import com.cdancy.bitbucket.rest.filters.BitbucketAuthenticationFilter;
32 |
33 | @Produces(MediaType.APPLICATION_JSON)
34 | @RequestFilters(BitbucketAuthenticationFilter.class)
35 | @Path("/rest/api/{jclouds.api-version}")
36 | @SuppressWarnings("PMD.AvoidDuplicateLiterals")
37 | public interface SystemApi {
38 |
39 | @Named("system:version")
40 | @Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/latest/bitbucket-rest.html"})
41 | @Consumes(MediaType.APPLICATION_JSON)
42 | @Path("/application-properties")
43 | @GET
44 | Version version();
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/exception/UnsupportedMediaTypeException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.exception;
19 |
20 | /**
21 | * The request entity has a Content-Type that the server does not support.
22 | * Almost all of the Bitbucket REST API accepts application/json format, but
23 | * check the individual resource documentation for more details. Additionally,
24 | * double-check that you are setting the Content-Type header correctly on your
25 | * request (e.g. using -H "Content-Type: application/json" in cURL).
26 | */
27 | public class UnsupportedMediaTypeException extends RuntimeException {
28 |
29 | private static final long serialVersionUID = 1L;
30 |
31 | public UnsupportedMediaTypeException() {
32 | super();
33 | }
34 |
35 | public UnsupportedMediaTypeException(final String arg0, final Throwable arg1) {
36 | super(arg0, arg1);
37 | }
38 |
39 | public UnsupportedMediaTypeException(final String arg0) {
40 | super(arg0);
41 | }
42 |
43 | public UnsupportedMediaTypeException(final Throwable arg0) {
44 | super(arg0);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/domain/common/RequestStatus.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.domain.common;
19 |
20 | import java.util.List;
21 |
22 | import org.jclouds.javax.annotation.Nullable;
23 | import org.jclouds.json.SerializedNames;
24 |
25 | import com.cdancy.bitbucket.rest.BitbucketUtils;
26 | import com.google.auto.value.AutoValue;
27 |
28 | /**
29 | * Generic response to be returned when an endpoint returns
30 | * no content (i.e. 204 response code).
31 | *
32 | * When the response code is valid the `value` parameter will
33 | * be set to true while a non-valid response has the `value` set to
34 | * false along with any potential `error` objects returned from Bitbucket.
35 | */
36 | @AutoValue
37 | public abstract class RequestStatus implements Value, ErrorsHolder {
38 |
39 | @SerializedNames({ "value", "errors" })
40 | public static RequestStatus create(@Nullable final Boolean value,
41 | final List errors) {
42 |
43 | return new AutoValue_RequestStatus(value,
44 | BitbucketUtils.nullToEmpty(errors));
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/domain/insights/AnnotationsResponse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.domain.insights;
19 |
20 | import com.cdancy.bitbucket.rest.BitbucketUtils;
21 | import com.cdancy.bitbucket.rest.domain.common.Error;
22 | import com.cdancy.bitbucket.rest.domain.common.ErrorsHolder;
23 | import com.google.auto.value.AutoValue;
24 | import org.jclouds.javax.annotation.Nullable;
25 | import org.jclouds.json.SerializedNames;
26 |
27 | import java.util.List;
28 |
29 | @AutoValue
30 | public abstract class AnnotationsResponse implements ErrorsHolder {
31 | public abstract int totalCount();
32 |
33 | @Nullable
34 | public abstract List annotations();
35 |
36 | @SerializedNames({"totalCount", "annotations", "errors"})
37 | public static AnnotationsResponse create(final int totalCount,
38 | final List annotations,
39 | final List errors) {
40 | return new AutoValue_AnnotationsResponse(BitbucketUtils.nullToEmpty(errors), totalCount, annotations);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/domain/project/ProjectPermissions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.domain.project;
19 |
20 | import com.cdancy.bitbucket.rest.domain.pullrequest.User;
21 | import com.cdancy.bitbucket.rest.domain.repository.Group;
22 | import com.google.auto.value.AutoValue;
23 | import org.jclouds.javax.annotation.Nullable;
24 | import org.jclouds.json.SerializedNames;
25 |
26 | @AutoValue
27 | public abstract class ProjectPermissions {
28 |
29 | public enum PermissionsType {
30 | PROJECT_ADMIN,
31 | PROJECT_WRITE,
32 | PROJECT_READ
33 | }
34 |
35 | @Nullable
36 | public abstract User user();
37 |
38 | @Nullable
39 | public abstract Group group();
40 |
41 | public abstract PermissionsType permission();
42 |
43 | @SerializedNames({"user", "group", "permission"})
44 | public static ProjectPermissions create(final User user,
45 | final Group group,
46 | final PermissionsType type) {
47 | return new AutoValue_ProjectPermissions(user, group, type);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/test/java/com/cdancy/bitbucket/rest/BitbucketApiMetadataTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest;
19 |
20 | import static org.assertj.core.api.Assertions.assertThat;
21 |
22 | import java.util.HashSet;
23 |
24 | import org.jclouds.View;
25 | import org.jclouds.apis.ApiMetadata;
26 | import org.jclouds.apis.Apis;
27 | import org.jclouds.apis.internal.BaseApiMetadataTest;
28 | import org.testng.annotations.Test;
29 |
30 | import com.google.common.reflect.TypeToken;
31 |
32 | /**
33 | * Unit tests for the {@link BitbucketApiMetadata} class.
34 | */
35 | @Test(groups = "unit", testName = "BitbucketApiMetadataTest")
36 | public class BitbucketApiMetadataTest extends BaseApiMetadataTest {
37 |
38 | public BitbucketApiMetadataTest() {
39 | super(new BitbucketApiMetadata(), new HashSet>());
40 | }
41 |
42 | public void testBitbucketApiRegistered() {
43 | final ApiMetadata api = Apis.withId("bitbucket");
44 |
45 | assertThat(api).isNotNull();
46 | assertThat(api instanceof BitbucketApiMetadata).isTrue();
47 | assertThat("bitbucket").isEqualTo(api.getId());
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/domain/file/FilesPage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.domain.file;
19 |
20 | import java.util.List;
21 |
22 | import org.jclouds.javax.annotation.Nullable;
23 | import org.jclouds.json.SerializedNames;
24 |
25 | import com.cdancy.bitbucket.rest.domain.common.Error;
26 | import com.cdancy.bitbucket.rest.domain.common.ErrorsHolder;
27 | import com.cdancy.bitbucket.rest.domain.common.Page;
28 | import com.cdancy.bitbucket.rest.BitbucketUtils;
29 | import com.google.auto.value.AutoValue;
30 |
31 | @AutoValue
32 | public abstract class FilesPage implements Page, ErrorsHolder {
33 |
34 | @SerializedNames({ "start", "limit", "size", "nextPageStart", "isLastPage", "values", "errors" })
35 | public static FilesPage create(final int start, final int limit, final int size, final int nextPageStart,
36 | final boolean isLastPage, @Nullable final List lines, @Nullable final List errors) {
37 | return new AutoValue_FilesPage(start, limit, size, nextPageStart, isLastPage,
38 | BitbucketUtils.nullToEmpty(lines), BitbucketUtils.nullToEmpty(errors));
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/domain/repository/MergeConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.domain.repository;
19 |
20 | import com.google.auto.value.AutoValue;
21 | import org.jclouds.javax.annotation.Nullable;
22 | import org.jclouds.json.SerializedNames;
23 |
24 | import java.util.List;
25 |
26 | @AutoValue
27 | public abstract class MergeConfig {
28 |
29 | public enum MergeConfigType {
30 | REPOSITORY,
31 | DEFAULT,
32 | PROJECT
33 | }
34 |
35 | public abstract MergeStrategy defaultStrategy();
36 |
37 | public abstract List strategies();
38 |
39 | public abstract MergeConfigType type();
40 |
41 | @Nullable
42 | public abstract Integer commitSummaries();
43 |
44 | @SerializedNames({ "defaultStrategy", "strategies", "type", "commitSummaries"})
45 | public static MergeConfig create(final MergeStrategy defaultStrategy,
46 | final List strategies,
47 | final MergeConfigType type,
48 | final Integer commitSummaries) {
49 |
50 | return new AutoValue_MergeConfig(defaultStrategy, strategies, type, commitSummaries);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/test/resources/last-modified.json:
--------------------------------------------------------------------------------
1 | {
2 | "files": {
3 | "pom.xml": {
4 | "id": "def0123abcdef4567abcdef8987abcdef6543abc",
5 | "displayId": "def0123abcd",
6 | "author": {
7 | "name": "charlie",
8 | "emailAddress": "charlie@example.com"
9 | },
10 | "authorTimestamp": 1549862602763,
11 | "committer": {
12 | "name": "charlie",
13 | "emailAddress": "charlie@example.com"
14 | },
15 | "committerTimestamp": 1549862602763,
16 | "message": "More work on feature 1",
17 | "parents": [
18 | {
19 | "id": "abcdef0123abcdef4567abcdef8987abcdef6543",
20 | "displayId": "abcdef0"
21 | }
22 | ]
23 | },
24 | "README.md": {
25 | "id": "abcdef0123abcdef4567abcdef8987abcdef6543",
26 | "displayId": "abcdef0123a",
27 | "author": {
28 | "name": "charlie",
29 | "emailAddress": "charlie@example.com"
30 | },
31 | "authorTimestamp": 1549862602763,
32 | "committer": {
33 | "name": "charlie",
34 | "emailAddress": "charlie@example.com"
35 | },
36 | "committerTimestamp": 1549862602763,
37 | "message": "WIP on feature 1",
38 | "parents": [
39 | {
40 | "id": "abcdef0123abcdef4567abcdef8987abcdef6543",
41 | "displayId": "abcdef0"
42 | }
43 | ]
44 | }
45 | },
46 | "latestCommit": {
47 | "id": "def0123abcdef4567abcdef8987abcdef6543abc",
48 | "displayId": "def0123abcd",
49 | "author": {
50 | "name": "charlie",
51 | "emailAddress": "charlie@example.com"
52 | },
53 | "authorTimestamp": 1549862602763,
54 | "committer": {
55 | "name": "charlie",
56 | "emailAddress": "charlie@example.com"
57 | },
58 | "committerTimestamp": 1549862602763,
59 | "message": "More work on feature 1",
60 | "parents": [
61 | {
62 | "id": "abcdef0123abcdef4567abcdef8987abcdef6543",
63 | "displayId": "abcdef0"
64 | }
65 | ]
66 | }
67 | }
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/domain/build/Status.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.domain.build;
19 |
20 | import com.google.auto.value.AutoValue;
21 | import org.jclouds.json.SerializedNames;
22 | import org.jclouds.javax.annotation.Nullable;
23 |
24 | @AutoValue
25 | public abstract class Status {
26 |
27 | public enum StatusState {
28 | SUCCESSFUL,
29 | FAILED,
30 | INPROGRESS
31 | }
32 |
33 | public abstract long dateAdded();
34 |
35 | @Nullable
36 | public abstract String description();
37 |
38 | public abstract String key();
39 |
40 | @Nullable
41 | public abstract String name();
42 |
43 | public abstract StatusState state();
44 |
45 | public abstract String url();
46 |
47 | @SerializedNames({"dateAdded", "description", "key", "name", "state", "url"})
48 | public static Status create(final long dateAdded,
49 | final String description,
50 | final String key,
51 | final String name,
52 | final StatusState state,
53 | final String url) {
54 | return new AutoValue_Status(dateAdded, description, key, name, state, url);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/domain/repository/Hook.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.domain.repository;
19 |
20 | import com.cdancy.bitbucket.rest.domain.common.Error;
21 | import com.cdancy.bitbucket.rest.domain.common.ErrorsHolder;
22 | import com.cdancy.bitbucket.rest.BitbucketUtils;
23 | import com.google.auto.value.AutoValue;
24 | import org.jclouds.javax.annotation.Nullable;
25 | import org.jclouds.json.SerializedNames;
26 |
27 | import java.util.List;
28 |
29 | @AutoValue
30 | public abstract class Hook implements ErrorsHolder {
31 |
32 | @Nullable
33 | public abstract HookDetails details();
34 |
35 | public abstract boolean enabled();
36 |
37 | public abstract boolean configured();
38 |
39 | @SerializedNames({ "details", "enabled", "configured", "errors" })
40 | public static Hook create(final HookDetails details,
41 | final boolean enabled,
42 | final boolean configured,
43 | @Nullable final List errors) {
44 |
45 | return new AutoValue_Hook(BitbucketUtils.nullToEmpty(errors),
46 | details,
47 | enabled,
48 | configured);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/domain/activities/ActivitiesPage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.domain.activities;
19 |
20 | import com.cdancy.bitbucket.rest.domain.common.Error;
21 | import com.cdancy.bitbucket.rest.domain.common.ErrorsHolder;
22 | import com.cdancy.bitbucket.rest.domain.common.Page;
23 | import com.cdancy.bitbucket.rest.BitbucketUtils;
24 | import com.google.auto.value.AutoValue;
25 | import org.jclouds.javax.annotation.Nullable;
26 | import org.jclouds.json.SerializedNames;
27 |
28 | import java.util.List;
29 |
30 | @AutoValue
31 | public abstract class ActivitiesPage implements Page, ErrorsHolder {
32 |
33 | @SerializedNames({ "start", "limit", "size", "nextPageStart", "isLastPage", "values", "errors" })
34 | public static ActivitiesPage create(final int start, final int limit,
35 | final int size, final int nextPageStart, final boolean isLastPage,
36 | @Nullable final List values, @Nullable final List errors) {
37 | return new AutoValue_ActivitiesPage(start, limit, size, nextPageStart, isLastPage,
38 | BitbucketUtils.nullToEmpty(values), BitbucketUtils.nullToEmpty(errors));
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/options/CreateParticipants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.options;
19 |
20 | import com.cdancy.bitbucket.rest.domain.participants.Participants;
21 | import com.cdancy.bitbucket.rest.domain.pullrequest.User;
22 | import com.google.auto.value.AutoValue;
23 | import org.jclouds.javax.annotation.Nullable;
24 | import org.jclouds.json.SerializedNames;
25 |
26 |
27 | @AutoValue
28 | public abstract class CreateParticipants {
29 |
30 | public abstract User user();
31 |
32 | @Nullable
33 | public abstract String lastReviewedCommit();
34 |
35 | public abstract Participants.Role role();
36 |
37 | public abstract boolean approved();
38 |
39 | public abstract Participants.Status status();
40 |
41 | @SerializedNames({"user", "lastReviewedCommit", "role", "approved", "status"})
42 | public static CreateParticipants create(final User user,
43 | final String lastReviewedCommit,
44 | final Participants.Role role,
45 | final boolean approved,
46 | final Participants.Status status) {
47 | return new AutoValue_CreateParticipants(user, lastReviewedCommit, role, approved, status);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/domain/file/LastModified.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.domain.file;
19 |
20 | import com.cdancy.bitbucket.rest.BitbucketUtils;
21 | import com.cdancy.bitbucket.rest.domain.commit.Commit;
22 | import com.cdancy.bitbucket.rest.domain.common.Error;
23 | import com.cdancy.bitbucket.rest.domain.common.ErrorsHolder;
24 | import com.google.auto.value.AutoValue;
25 | import org.jclouds.javax.annotation.Nullable;
26 | import org.jclouds.json.SerializedNames;
27 |
28 | import java.util.List;
29 | import java.util.Map;
30 |
31 | @AutoValue
32 | public abstract class LastModified implements ErrorsHolder {
33 |
34 | @Nullable
35 | public abstract Map files();
36 |
37 | @Nullable
38 | public abstract Commit latestCommit();
39 |
40 | LastModified() {
41 | }
42 |
43 | @SerializedNames({ "files", "latestCommit", "errors" })
44 | public static LastModified create(final Map files,
45 | final Commit latestCommit,
46 | final List errors) {
47 | return new AutoValue_LastModified(BitbucketUtils.nullToEmpty(errors),
48 | BitbucketUtils.nullToEmpty(files),
49 | latestCommit);
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/domain/repository/HookDetails.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.domain.repository;
19 |
20 | import com.google.auto.value.AutoValue;
21 | import org.jclouds.javax.annotation.Nullable;
22 | import org.jclouds.json.SerializedNames;
23 |
24 | @AutoValue
25 | public abstract class HookDetails {
26 |
27 | public abstract String key();
28 |
29 | public abstract String name();
30 |
31 | public abstract String type();
32 |
33 | public abstract String description();
34 |
35 | public abstract String version();
36 |
37 | @Nullable
38 | public abstract String configFormKey();
39 |
40 | @SerializedNames({ "key", "name", "type",
41 | "description", "version", "configFormKey" })
42 | public static HookDetails create(final String key,
43 | final String name,
44 | final String type,
45 | final String description,
46 | final String version,
47 | final String configFormKey) {
48 |
49 | return new AutoValue_HookDetails(key,
50 | name,
51 | type,
52 | description,
53 | version,
54 | configFormKey);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/filters/BitbucketAuthenticationFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.filters;
19 |
20 | import jakarta.inject.Inject;
21 | import jakarta.inject.Singleton;
22 |
23 | import com.cdancy.bitbucket.rest.BitbucketAuthentication;
24 | import com.cdancy.bitbucket.rest.auth.AuthenticationType;
25 |
26 | import org.jclouds.http.HttpException;
27 | import org.jclouds.http.HttpRequest;
28 | import org.jclouds.http.HttpRequestFilter;
29 | import com.google.common.net.HttpHeaders;
30 |
31 | @Singleton
32 | public class BitbucketAuthenticationFilter implements HttpRequestFilter {
33 | private final BitbucketAuthentication creds;
34 |
35 | @Inject
36 | BitbucketAuthenticationFilter(final BitbucketAuthentication creds) {
37 | this.creds = creds;
38 | }
39 |
40 | @Override
41 | public HttpRequest filter(final HttpRequest request) throws HttpException {
42 | if (creds.authType() == AuthenticationType.Anonymous) {
43 | return request;
44 | } else {
45 | final String authHeader = creds.authType() + " " + creds.authValue();
46 | return request.toBuilder().addHeader(HttpHeaders.AUTHORIZATION, authHeader).build();
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/gradle/release.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 | dependencies {
6 | classpath 'org.eclipse.jgit:org.eclipse.jgit:6.0.0.202111291000-r'
7 | }
8 | }
9 |
10 | import org.eclipse.jgit.api.Git
11 | import org.eclipse.jgit.api.DeleteTagCommand
12 | import org.eclipse.jgit.api.TagCommand
13 | import org.eclipse.jgit.api.PushCommand
14 | import org.eclipse.jgit.lib.Repository
15 | import org.eclipse.jgit.storage.file.FileRepositoryBuilder
16 | import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider
17 |
18 | File repoDir = new File("${projectDir}")
19 | FileRepositoryBuilder builder = new FileRepositoryBuilder()
20 | Repository repo = builder.findGitDir(repoDir).build()
21 | Git git = new Git(repo)
22 |
23 | task createTag {
24 | description = 'Creates repository tag with current project version.'
25 | ext.tagName = "v${project.version}"
26 |
27 | doLast {
28 | logger.quiet "Creating tag '$tagName'."
29 |
30 | // Remove potentially existing tag
31 | DeleteTagCommand delTag = git.tagDelete()
32 | delTag.setTags(tagName).call()
33 |
34 | // Create tag
35 | TagCommand tag = git.tag()
36 | tag.setName(tagName).setMessage("Version ${project.version}").call()
37 | }
38 | }
39 |
40 | task pushTag {
41 | description = 'Pushes tag to remote repository.'
42 | dependsOn createTag
43 |
44 | doLast {
45 | logger.quiet "Pushing tag '$createTag.tagName' to remote."
46 | PushCommand push = git.push()
47 | push.add(createTag.tagName)
48 | push.setCredentialsProvider(new UsernamePasswordCredentialsProvider(project.githubUsername, project.githubPassword))
49 | push.call()
50 | }
51 | }
52 |
53 | task tag {
54 | dependsOn pushTag
55 | mustRunAfter "publishToSonatype", "closeAndReleaseSonatypeStagingRepository"
56 | }
57 |
58 | task release {
59 | description = 'Publishes artifacts to Bintray and tags repository with current project version.'
60 | dependsOn assemble, "publishToSonatype", "closeAndReleaseSonatypeStagingRepository", tag
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/Path.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.domain.pullrequest;
19 |
20 | import java.util.List;
21 |
22 | import org.jclouds.javax.annotation.Nullable;
23 | import org.jclouds.json.SerializedNames;
24 |
25 | import com.cdancy.bitbucket.rest.BitbucketUtils;
26 | import com.google.auto.value.AutoValue;
27 |
28 | @AutoValue
29 | public abstract class Path {
30 |
31 | public abstract List components();
32 |
33 | public abstract String parent();
34 |
35 | public abstract String name();
36 |
37 | @Nullable
38 | public abstract String extension();
39 |
40 | public abstract String _toString();
41 |
42 | Path() {
43 | }
44 |
45 | @SerializedNames({ "components", "parent", "name",
46 | "extension", "toString" })
47 | public static Path create(final List components,
48 | final String parent,
49 | final String name,
50 | final String extension,
51 | final String _toString) {
52 |
53 | return new AutoValue_Path(BitbucketUtils.nullToEmpty(components),
54 | parent,
55 | name,
56 | extension,
57 | _toString);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/domain/pullrequest/MergeStatus.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.domain.pullrequest;
19 |
20 | import com.cdancy.bitbucket.rest.domain.common.Veto;
21 | import java.util.List;
22 |
23 | import org.jclouds.json.SerializedNames;
24 |
25 | import com.cdancy.bitbucket.rest.domain.common.Error;
26 | import com.cdancy.bitbucket.rest.domain.common.ErrorsHolder;
27 | import com.cdancy.bitbucket.rest.BitbucketUtils;
28 | import com.google.auto.value.AutoValue;
29 |
30 | @AutoValue
31 | public abstract class MergeStatus implements ErrorsHolder {
32 |
33 | public abstract boolean canMerge();
34 |
35 | public abstract boolean conflicted();
36 |
37 | public abstract List vetoes();
38 |
39 | MergeStatus() {
40 | }
41 |
42 | @SerializedNames({ "canMerge", "conflicted", "vetoes", "errors" })
43 | public static MergeStatus create(final boolean canMerge,
44 | final boolean conflicted,
45 | final List vetoes,
46 | final List errors) {
47 |
48 | return new AutoValue_MergeStatus(BitbucketUtils.nullToEmpty(errors),
49 | canMerge,
50 | conflicted,
51 | BitbucketUtils.nullToEmpty(vetoes));
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/domain/admin/UserPage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.domain.admin;
19 |
20 | import com.cdancy.bitbucket.rest.domain.common.Error;
21 | import com.cdancy.bitbucket.rest.domain.common.ErrorsHolder;
22 | import com.cdancy.bitbucket.rest.domain.common.Page;
23 | import com.cdancy.bitbucket.rest.domain.pullrequest.User;
24 | import com.cdancy.bitbucket.rest.BitbucketUtils;
25 | import com.google.auto.value.AutoValue;
26 | import org.jclouds.javax.annotation.Nullable;
27 | import org.jclouds.json.SerializedNames;
28 |
29 | import java.util.List;
30 |
31 | @AutoValue
32 | public abstract class UserPage implements Page, ErrorsHolder {
33 |
34 | @SerializedNames({ "start", "limit", "size", "nextPageStart", "isLastPage", "values", "errors" })
35 | public static UserPage create(final int start, final int limit,
36 | final int size, final int nextPageStart,
37 | final boolean isLastPage, @Nullable final List values,
38 | @Nullable final List errors) {
39 | return new AutoValue_UserPage(start, limit,
40 | size, nextPageStart,
41 | isLastPage, BitbucketUtils.nullToEmpty(values),
42 | BitbucketUtils.nullToEmpty(errors));
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/options/CreateBuildStatus.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.options;
19 |
20 | import com.google.auto.value.AutoValue;
21 | import org.jclouds.javax.annotation.Nullable;
22 | import org.jclouds.json.SerializedNames;
23 |
24 | @AutoValue
25 | public abstract class CreateBuildStatus {
26 |
27 | public enum STATE {
28 | SUCCESSFUL,
29 | FAILED,
30 | INPROGRESS
31 | }
32 |
33 | public abstract String state();
34 |
35 | public abstract String key();
36 |
37 | @Nullable
38 | public abstract String name();
39 |
40 | public abstract String url();
41 |
42 | @Nullable
43 | public abstract String description();
44 |
45 | CreateBuildStatus() {
46 | }
47 |
48 | @SerializedNames({ "state", "key", "name", "url", "description" })
49 | public static CreateBuildStatus create(final STATE state,
50 | final String key,
51 | final String name,
52 | final String url,
53 | final String description) {
54 |
55 | return new AutoValue_CreateBuildStatus(state != null ? state.toString() : null,
56 | key,
57 | name,
58 | url,
59 | description);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/domain/branch/BranchModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.domain.branch;
19 |
20 | import java.util.List;
21 |
22 | import org.jclouds.javax.annotation.Nullable;
23 | import org.jclouds.json.SerializedNames;
24 |
25 | import com.cdancy.bitbucket.rest.domain.common.Error;
26 | import com.cdancy.bitbucket.rest.domain.common.ErrorsHolder;
27 | import com.cdancy.bitbucket.rest.BitbucketUtils;
28 | import com.google.auto.value.AutoValue;
29 |
30 | @AutoValue
31 | public abstract class BranchModel implements ErrorsHolder {
32 |
33 | @Nullable
34 | public abstract Branch development();
35 |
36 | @Nullable
37 | public abstract Branch production();
38 |
39 | public abstract List types();
40 |
41 | BranchModel() {
42 | }
43 |
44 | @SerializedNames({ "development", "production", "types", "errors" })
45 | public static BranchModel create(final Branch development,
46 | final Branch production,
47 | final List types,
48 | final List errors) {
49 |
50 | return new AutoValue_BranchModel(BitbucketUtils.nullToEmpty(errors),
51 | development,
52 | production,
53 | BitbucketUtils.nullToEmpty(types));
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/parsers/DeleteRepositoryParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.parsers;
19 |
20 | import com.cdancy.bitbucket.rest.domain.common.RequestStatus;
21 | import com.google.common.base.Function;
22 | import jakarta.inject.Singleton;
23 | import org.jclouds.http.HttpResponse;
24 | import org.jclouds.rest.ResourceNotFoundException;
25 |
26 | /**
27 | * When deleting a repository, and it doesn't exist, Bitbucket will return a 204. To account
28 | * for this we need to implement a custom parser that handles success, not found (204),
29 | * and all other failures appropriately.
30 | */
31 | @Singleton
32 | public class DeleteRepositoryParser implements Function {
33 |
34 | @Override
35 | public RequestStatus apply(final HttpResponse input) {
36 | final int statusCode = input.getStatusCode();
37 | if (statusCode >= 200 && statusCode < 400) {
38 | if (statusCode == 204) {
39 | throw new ResourceNotFoundException("The repository does not exist in this project.");
40 | } else {
41 | return RequestStatus.create(true, null);
42 | }
43 | } else {
44 | throw new RuntimeException(input.getStatusLine());
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/cdancy/bitbucket/rest/domain/common/Error.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cdancy.bitbucket.rest.domain.common;
19 |
20 | import com.cdancy.bitbucket.rest.BitbucketUtils;
21 | import org.jclouds.javax.annotation.Nullable;
22 | import org.jclouds.json.SerializedNames;
23 |
24 | import com.google.auto.value.AutoValue;
25 | import java.util.List;
26 |
27 | @AutoValue
28 | public abstract class Error {
29 |
30 | @Nullable
31 | public abstract String context();
32 |
33 | @Nullable
34 | public abstract String message();
35 |
36 | @Nullable
37 | public abstract String exceptionName();
38 |
39 | public abstract boolean conflicted();
40 |
41 | public abstract List vetoes();
42 |
43 | Error() {
44 | }
45 |
46 | @SerializedNames({ "context", "message", "exceptionName", "conflicted", "vetoes" })
47 | public static Error create(final String context,
48 | final String message,
49 | final String exceptionName,
50 | final boolean conflicted,
51 | final List vetoes) {
52 |
53 | return new AutoValue_Error(context,
54 | message,
55 | exceptionName,
56 | conflicted,
57 | BitbucketUtils.nullToEmpty(vetoes));
58 | }
59 | }
60 |
--------------------------------------------------------------------------------