Skip to content

Commit a2eaf9c

Browse files
authored
Merge pull request #276 from contentstack/epic/DX-31560-branch-create-environments
feat(branch): optional environment list on branch create (DX-31560)
2 parents 8d00706 + 6a5e5d2 commit a2eaf9c

8 files changed

Lines changed: 577 additions & 3 deletions

File tree

‎changelog.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v1.16.0
4+
5+
### Oct 28, 2026
6+
7+
- Feat: Branch create accepts an optional `branch.publish_config.environments` list of environment names, so a branch can clone only the environments it needs. `[]` clones none; omitting `publish_config` clones all environments, as before. The list is sent unchanged, the SDK adds no length limit, and an unknown name (or a mix) returns the API's 422 error body unchanged with no branch created.
8+
39
## v1.15.0
410

511
### Oct 21, 2026

‎pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<artifactId>cms</artifactId>
88
<packaging>jar</packaging>
99
<name>contentstack-management-java</name>
10-
<version>1.15.0</version>
10+
<version>1.16.0</version>
1111
<description>Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an
1212
API-first approach
1313
</description>

‎src/main/java/com/contentstack/cms/stack/Branch.java‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,32 @@ public Call<ResponseBody> fetch() {
159159
/**
160160
* The Create a branch request creates a new branch in a particular stack of
161161
* your organization.
162+
* <p>
163+
* Optionally set {@code branch.publish_config.environments} to a list of
164+
* environment <b>names</b> (not UIDs) to choose which environments the branch
165+
* clones:
166+
* <ul>
167+
* <li>a list of names clones only those environments;</li>
168+
* <li>an empty list {@code []} clones none;</li>
169+
* <li>omitting {@code publish_config} clones all environments, as before.</li>
170+
* </ul>
171+
* The list is sent unchanged. The SDK does not validate the names or limit the
172+
* list length. An unknown name, or a mix of known and unknown names, is
173+
* rejected by the API with a 422; the API's error body is returned unchanged
174+
* and no branch is created.
175+
* <p>
176+
* Example body:
177+
* <pre>{@code
178+
* JSONObject publishConfig = new JSONObject();
179+
* publishConfig.put("environments", Arrays.asList("development", "staging"));
180+
* JSONObject branch = new JSONObject();
181+
* branch.put("uid", "branch_uid");
182+
* branch.put("source", "main");
183+
* branch.put("publish_config", publishConfig);
184+
* JSONObject body = new JSONObject();
185+
* body.put("branch", branch);
186+
* stack.branch().create(body).execute();
187+
* }</pre>
162188
*
163189
* @param body the request body
164190
* @return Call

‎src/test/java/com/contentstack/cms/TestClient.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public class TestClient {
3939
public static final String ENTRY_VARIANT_LOCALE =
4040
isBlank(env.get("entryVariantLocale")) ? "en-us" : env.get("entryVariantLocale").trim();
4141

42+
/** Login email for tests that log in with a real account (null when {@code EMAIL} is not set in {@code .env}). */
43+
public static final String EMAIL = env.get("EMAIL");
44+
45+
/** Login password for tests that log in with a real account (null when {@code PASSWORD} is not set in {@code .env}). */
46+
public static final String PASSWORD = env.get("PASSWORD");
47+
4248
/** {@code true} if {@code value} is null, empty, or whitespace-only. */
4349
private static boolean isBlank(String value) {
4450
return value == null || value.trim().isEmpty();
@@ -51,6 +57,11 @@ public static boolean isUsingDefaultStackCredentials() {
5157
return env.get("apiKey") == null || env.get("managementToken") == null;
5258
}
5359

60+
/** {@code true} when {@code apiKey} is set to a non-blank value in {@code .env}. */
61+
public static boolean isApiKeyConfigured() {
62+
return !isBlank(env.get("apiKey"));
63+
}
64+
5465
private static Contentstack instance;
5566
private static Stack stackInstance;
5667

‎src/test/java/com/contentstack/cms/UnitTestSuite.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.contentstack.cms.core.AuthInterceptorTest;
44
import com.contentstack.cms.core.EndpointTest;
55
import com.contentstack.cms.stack.AssetUnitTest;
6+
import com.contentstack.cms.stack.BranchUnitTest;
67
import com.contentstack.cms.stack.EntryVariantUnitTest;
78
import com.contentstack.cms.stack.EnvironmentUnitTest;
89
import com.contentstack.cms.stack.GlobalFieldUnitTests;
@@ -33,6 +34,7 @@
3334
AssetUnitTest.class,
3435
EntryVariantUnitTest.class,
3536
EnvironmentUnitTest.class,
37+
BranchUnitTest.class,
3638
GlobalFieldUnitTests.class,
3739
LocaleUnitTest.class,
3840
ReleaseUnitTest.class,

‎src/test/java/com/contentstack/cms/stack/APISanityTestSuite.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
EndpointAPITest.class,
1212
TaxonomyAPITest.class,
1313
AssetAPITest.class,
14+
BranchAPITest.class,
1415
ContentTypeAPITest.class,
1516
EntryFieldsAPITest.class,
1617
EnvironmentAPITest.class,

0 commit comments

Comments
 (0)