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
Merged
Show file tree
Hide file tree
Changes from 3 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,45 @@
/*
* 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.branch;

import com.cdancy.bitbucket.rest.domain.pullrequest.User;
import com.google.auto.value.AutoValue;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

import java.util.List;

@AutoValue
public abstract class BranchPermission {
@Nullable
public abstract Long id();

public abstract BranchPermissionEnumType type();

public abstract Matcher matcher();

public abstract List<User> users();

public abstract List<String> groups();

@SerializedNames({"id", "type", "matcher", "users", "groups"})
public static BranchPermission create(Long id, BranchPermissionEnumType type, Matcher matcher,
List<User> users, List<String> groups) {
return new AutoValue_BranchPermission(id, type, matcher, users, groups);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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.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)?

"prevents history rewrites on the specified branch(es) - for example by a force push or rebase."),
no_deletes("Deletion", "no-deletes", "prevents branch and tag deletion"),
pull_request_only("Changes without a pull request", "pull-request-only",
"prevents pushing changes directly to the specified branch(es); changes are allowed only with a pull request"),
read_only("All changes", "read-only",
"prevents pushes to the specified branch(es) and restricts creating new"
+ " branches matching the specified branch(es) or pattern");

private String name;
private String apiName;
private String description;

BranchPermissionEnumType(String name, String apiName, String description) {
this.name = name;
this.apiName = apiName;
this.description = description;
}

public String getName() {
return name;
}

public String getApiName() {
return apiName;
}

public String getDescription() {
return description;
}

/**
* Convert value from Api to enum.
*
* @param apiName ApiName
* @return value
*/
public static BranchPermissionEnumType fromValue(String apiName) {
for (BranchPermissionEnumType enumType : BranchPermissionEnumType.values()) {
if (enumType.getApiName().equals(apiName)) {
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

}

@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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.branch;

import com.cdancy.bitbucket.rest.domain.common.Error;
import com.cdancy.bitbucket.rest.domain.common.ErrorsHolder;
import com.cdancy.bitbucket.rest.domain.common.Page;
import com.cdancy.bitbucket.rest.utils.Utils;
import com.google.auto.value.AutoValue;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

import java.util.List;

@AutoValue
public abstract class BranchPermissionPage implements Page<BranchPermission>, ErrorsHolder {

@SerializedNames({ "start", "limit", "size", "nextPageStart", "isLastPage", "values", "errors" })
public static BranchPermissionPage create(int start, int limit, int size, int nextPageStart, boolean isLastPage,
@Nullable List<BranchPermission> values, @Nullable List<Error> errors) {
return new AutoValue_BranchPermissionPage(start, limit, size, nextPageStart, isLastPage,
Utils.nullToEmpty(values), Utils.nullToEmpty(errors));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.branch;

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

@AutoValue
public abstract class BranchPermissionType {
public abstract String id();

public abstract String name();

@SerializedNames({"id", "name"})
public static BranchPermissionType create(String id, String name) {
return new AutoValue_BranchPermissionType(id, name);
}

public static BranchPermissionType create(Matcher.MatcherId matcherId) {
return new AutoValue_BranchPermissionType(matcherId.getTypeId(), matcherId.getTypeName());
}
}
78 changes: 78 additions & 0 deletions src/main/java/com/cdancy/bitbucket/rest/domain/branch/Matcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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.branch;

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

@AutoValue
public abstract class Matcher {

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)?



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

private String id;
private String name;
private String typeId;
private String typeName;

MatcherId(String id, String name, String typeId, String typeName) {
this.id = id;
this.name = name;
this.typeId = typeId;
this.typeName = typeName;
}

public String getId() {
return id;
}

public String getName() {
return name;
}

public String getTypeId() {
return typeId;
}

public String getTypeName() {
return typeName;
}
}

public abstract String id();

public abstract String displayId();

public abstract BranchPermissionType type();

public abstract Boolean active();

@SerializedNames({"id", "displayId", "type", "active"})
public static Matcher create(String id, String displayId, BranchPermissionType type,
Boolean active) {
return new AutoValue_Matcher(id, displayId, type, active);
}

public static Matcher create(MatcherId matcherId, Boolean active) {
return new AutoValue_Matcher(matcherId.getId(), matcherId.getName(), BranchPermissionType.create(matcherId), active);
}
}
Loading