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 new api call for BranchPermission #51

Merged
merged 8 commits into from
Mar 13, 2017

Conversation

j0nathan33
Copy link
Contributor

No description provided.

@cdancy cdancy self-assigned this Mar 8, 2017
@cdancy cdancy added this to the v0.0.14 milestone Mar 8, 2017
package com.cdancy.bitbucket.rest.domain.branch;

public enum BranchPermissionEnumType {
fast_forward_only("Rewriting history", "fast-forward-only",
Copy link
Owner

Choose a reason for hiding this comment

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

Can we do all CAPS for enum types (e.g. fast_forward_only to FAST_FORWARD_ONLY)?

@Override
public String toString() {
return this.getApiName();
}
Copy link
Owner

Choose a reason for hiding this comment

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

Is this necessary and/or being used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's need for update or create BranchPermission because Gson use toString() for conversion value before send to bitbucket

develop("development", "Development", "MODEL_BRANCH", "Branching model branch"),
master("production", "Production", "MODEL_BRANCH", "Branching model branch");


Copy link
Owner

Choose a reason for hiding this comment

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

remove extra line break

public enum MatcherId {
release("RELEASE", "Release", "MODEL_CATEGORY", "Branching model category"),
develop("development", "Development", "MODEL_BRANCH", "Branching model branch"),
master("production", "Production", "MODEL_BRANCH", "Branching model branch");
Copy link
Owner

Choose a reason for hiding this comment

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

Caps for enum names. Was it intentional to put RELEASE in call caps and then development not in all caps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not error. In Bitbucket, the brancing model for release is uppercase and for develop/master is lowercase.

Copy link
Owner

Choose a reason for hiding this comment

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

Fair enough. Can we also change the enum name to match the release name (e.g. RELEASE, DEVELOPMENT, MASTER)?

@Path("/branch-permissions/2.0/projects/{project}/repos/{repo}/restrictions")
@Fallback(BitbucketFallbacks.BranchPermissionPageOnError.class)
@GET
BranchPermissionPage getBranchPermission(@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.

Lets change to listBranchPermission to keep in line with naming standards already set.

@@ -114,4 +119,35 @@ Branch getDefault(@PathParam("project") String project,
@GET
BranchModel model(@PathParam("project") String project,
@PathParam("repo") String repo);

@Named("branch:get-BranchPermission")
Copy link
Owner

Choose a reason for hiding this comment

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

Change to branch:list-branch-permission

@Nullable @QueryParam("start") Integer start,
@Nullable @QueryParam("limit") Integer limit);

@Named("branch:update-BranchPermission")
Copy link
Owner

Choose a reason for hiding this comment

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

Change to branch:update-branch-permission

@PathParam("repo") String repo,
@BinderParam(BindToJsonPayload.class) List<BranchPermission> listBranchPermission);

@Named("branch:get-BranchPermission")
Copy link
Owner

Choose a reason for hiding this comment

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

Change to branch:delete-branch-permission

@Named("branch:update-BranchPermission")
@Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/4.14.1/bitbucket-ref-restriction-rest.html#idm45354011023456"})
@Path("/branch-permissions/2.0/projects/{project}/repos/{repo}/restrictions")
@Produces("application/vnd.atl.bitbucket.bulk+json")
Copy link
Owner

Choose a reason for hiding this comment

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

Any particular reason to need to override the default json?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes because Bitbucket need for update. If, I don't put it, bitbucket return this error : "Can not deserialize instance of com.atlassian.stash.internal.repository.ref.restriction.rest.RestRestrictionRequest out of START_ARRAY token\n at [Source: com.atlassian.stash.internal.web.util.web.CountingServletInputStream@68f4c6d2; line: 1, column: 1]""

@DELETE
boolean deleteBranchPermission(@PathParam("project") String project,
@PathParam("repo") String repo,
@PathParam("id") Long id);
Copy link
Owner

Choose a reason for hiding this comment

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

Since id is not optional lets use long instead of boxed version.

@cdancy
Copy link
Owner

cdancy commented Mar 8, 2017

@j0nathan33 thanks for PR! Added some intial comments to address. Looks Ok so far.

FYI: I would need mock and integration tests prior to merging. If you need help writing these feel free to scream my way ;)

@j0nathan33
Copy link
Contributor Author

Ok, I will try to add some mock and integration tests :).

return enumType;
}
}
throw new IllegalArgumentException("Value not Found");
Copy link
Owner

Choose a reason for hiding this comment

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

Can we do something more descriptive? Maybe "Value " + apiName + " is not a legal BranchPermission"

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 change it

@Named("branch:update-branch-permission")
@Documentation({"https://developer.atlassian.com/static/rest/bitbucket-server/4.14.1/bitbucket-ref-restriction-rest.html#idm45354011023456"})
@Path("/branch-permissions/2.0/projects/{project}/repos/{repo}/restrictions")
@Produces("application/vnd.atl.bitbucket.bulk+json")
Copy link
Owner

Choose a reason for hiding this comment

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

Is this content-type required? Will the already defined @Produces(MediaType.APPLICATION_JSON) not work?

Copy link
Owner

Choose a reason for hiding this comment

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

Looking at the documentation appears so. Ok lets keep it.

@cdancy
Copy link
Owner

cdancy commented Mar 9, 2017

@j0nathan33
Copy link
Contributor Author

Right now, it's not possible to add new attribute "accessKeys", because my bitbucket server have old version but I will try to add It

@cdancy
Copy link
Owner

cdancy commented Mar 10, 2017

@j0nathan33 what version of bitbucket are you on?

@cdancy
Copy link
Owner

cdancy commented Mar 10, 2017

Response looks like this:

{
    "id": 2,
    "type": "read-only",
    "matcher": {
        "id": "release*",
        "displayId": "release*",
        "type": {
            "id": "PATTERN",
            "name": "Pattern"
        },
        "active": true
    },
    "users": [
        {
            "name": "jcitizen",
            "emailAddress": "jane@example.com",
            "id": 101,
            "displayName": "Jane Citizen",
            "active": true,
            "slug": "jcitizen",
            "type": "NORMAL"
        }
    ],
    "groups": [
        "bitbucket-users"
    ],
    "accessKeys": [
        {
            "key": {
                "id": 1,
                "text": "ssh-rsa AAAAAA... me@atlassian.com",
                "label": "me@atlassian.com"
            }
        }
    ]
}

@cdancy
Copy link
Owner

cdancy commented Mar 10, 2017

While request looks like this:

{
    "type": "read-only",
    "matcher": {
        "id": "refs/tags/**",
        "displayId": "refs/tags/**",
        "type": {
            "id": "PATTERN",
            "name": "Pattern"
        },
        "active": true
    },
    "users": [
        "bman",
        "tstark",
        "hulk"
    ],
    "groups": [
        "bitbucket-users"
    ],
    "accessKeys": [
        1,
        2,
        3
    ]
}

@cdancy
Copy link
Owner

cdancy commented Mar 10, 2017

They look optional in both cases so to speak.

@cdancy
Copy link
Owner

cdancy commented Mar 13, 2017

@j0nathan33 integration tests pass as expected. Pulling this in as I'd like to get a release out today. As the endpoints don't require accessKeys to be present on request or response we can circle back at some later point and add them.

Thanks for the PR @j0nathan33!

@cdancy cdancy merged commit 62af03e into cdancy:master Mar 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants