Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
54 changes: 54 additions & 0 deletions .github/workflows/back-merge-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Back-merge master to development

on:
push:
branches:
- master
workflow_dispatch:

permissions:
contents: read
pull-requests: write

jobs:
open-back-merge-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Open back-merge PR if needed
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
BASE_BRANCH="development"
SOURCE_BRANCH="master"

git fetch origin "$BASE_BRANCH" "$SOURCE_BRANCH"

if ! git show-ref --verify --quiet "refs/remotes/origin/$BASE_BRANCH"; then
echo "Base branch '$BASE_BRANCH' does not exist on origin; skipping."
exit 0
fi

SOURCE_SHA=$(git rev-parse "origin/$SOURCE_BRANCH")
BASE_SHA=$(git rev-parse "origin/$BASE_BRANCH")

if [ "$SOURCE_SHA" = "$BASE_SHA" ]; then
echo "$SOURCE_BRANCH and $BASE_BRANCH are at the same commit; nothing to back-merge."
exit 0
fi

EXISTING=$(gh pr list --repo "${{ github.repository }}" --base "$BASE_BRANCH" --head "$SOURCE_BRANCH" --state open --json number --jq 'length')

if [ "$EXISTING" -gt 0 ]; then
echo "An open PR from $SOURCE_BRANCH to $BASE_BRANCH already exists; skipping."
exit 0
fi

gh pr create --repo "${{ github.repository }}" --base "$BASE_BRANCH" --head "$SOURCE_BRANCH" --title "chore: back-merge $SOURCE_BRANCH into $BASE_BRANCH" --body "Automated back-merge after changes landed on \\`$SOURCE_BRANCH\\`. Review and merge to keep \\`$BASE_BRANCH\\` in sync."

echo "Created back-merge PR $SOURCE_BRANCH -> $BASE_BRANCH."
20 changes: 0 additions & 20 deletions .github/workflows/check-branch.yml

This file was deleted.

86 changes: 86 additions & 0 deletions .github/workflows/check-version-bump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Check Version Bump

on:
pull_request:

jobs:
version-bump:
name: Version & Changelog bump
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Detect changed files and version bump
id: detect
run: |
if git rev-parse HEAD^2 >/dev/null 2>&1; then
FILES=$(git diff --name-only HEAD^1 HEAD^2)
else
FILES=$(git diff --name-only HEAD~1 HEAD)
fi
VERSION_FILES_CHANGED=false
echo "$FILES" | grep -qx 'package.json' && VERSION_FILES_CHANGED=true
echo "$FILES" | grep -qx 'CHANGELOG.md' && VERSION_FILES_CHANGED=true
echo "version_files_changed=$VERSION_FILES_CHANGED" >> $GITHUB_OUTPUT
# Only lib/, webpack/, dist/, package.json count as release-affecting; .github/ and test/ do not
CODE_CHANGED=false
echo "$FILES" | grep -qE '^lib/|^webpack/|^dist/' && CODE_CHANGED=true
echo "$FILES" | grep -qx 'package.json' && CODE_CHANGED=true
echo "code_changed=$CODE_CHANGED" >> $GITHUB_OUTPUT

- name: Skip when only test/docs/.github changed
if: steps.detect.outputs.code_changed != 'true'
run: |
echo "No release-affecting files changed (e.g. only test/docs/.github). Skipping version-bump check."
exit 0

- name: Fail when version bump was missed
if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed != 'true'
run: |
echo "::error::This PR has code changes but no version bump. Please bump the version in package.json and add an entry in CHANGELOG.md."
exit 1

- name: Setup Node
if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed == 'true'
uses: actions/setup-node@v4
with:
node-version: '22.x'

- name: Check version bump
if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed == 'true'
run: |
set -e
PKG_VERSION=$(node -p "require('./package.json').version.replace(/^v/, '')")
if [ -z "$PKG_VERSION" ]; then
echo "::error::Could not read version from package.json"
exit 1
fi
git fetch --tags --force 2>/dev/null || true
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || true)
if [ -z "$LATEST_TAG" ]; then
echo "No existing tags found. Skipping version-bump check (first release)."
exit 0
fi
LATEST_VERSION="${LATEST_TAG#v}"
LATEST_VERSION="${LATEST_VERSION%%-*}"
if [ "$(printf '%s\n' "$LATEST_VERSION" "$PKG_VERSION" | sort -V | tail -1)" != "$PKG_VERSION" ]; then
echo "::error::Version bump required: package.json version ($PKG_VERSION) is not greater than latest tag ($LATEST_TAG). Please bump the version in package.json."
exit 1
fi
if [ "$PKG_VERSION" = "$LATEST_VERSION" ]; then
echo "::error::Version bump required: package.json version ($PKG_VERSION) equals latest tag ($LATEST_TAG). Please bump the version in package.json."
exit 1
fi
CHANGELOG_VERSION=$(sed -nE 's/^## \[v?([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' CHANGELOG.md | head -1)
if [ -z "$CHANGELOG_VERSION" ]; then
echo "::error::Could not find a version entry in CHANGELOG.md (expected line like '## [v1.0.0](...)')."
exit 1
fi
if [ "$CHANGELOG_VERSION" != "$PKG_VERSION" ]; then
echo "::error::CHANGELOG version mismatch: CHANGELOG.md top version ($CHANGELOG_VERSION) does not match package.json version ($PKG_VERSION). Please add or update the CHANGELOG entry for $PKG_VERSION."
exit 1
fi
echo "Version bump check passed: package.json and CHANGELOG.md are at $PKG_VERSION (latest tag: $LATEST_TAG)."
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,4 @@ venv.bak/
.mypy_cache/
.idea/
.vscode/
*/assets/regions.json
25 changes: 14 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# CHANGELOG

## _v2.5.3_

### **Date: 08-June-2026**

- Fixed security issues.

## _v2.5.2_

### **Date: 18-May-2026**

- Bumped urllib3 in development requirements to address reported vulnerabilities.
## _v2.6.0_

### **Date: 22-June-2026**

- Dynamic endpoint resolution via new `Endpoint` class.
- Region-to-URL mapping is now loaded from a bundled `regions.json` (sourced from `artifacts.contentstack.com`) instead of hardcoded `if/elif` chains.
- Added `Endpoint.get_contentstack_endpoint(region, service, omit_https)` — resolves any supported region to its `contentDelivery`, `contentManagement`, or other service URL.
- Added `contentstack.get_contentstack_endpoint()` module-level proxy.
- `Stack` now auto-resolves `host` and `live_preview` management host via `Endpoint` on initialization.
- Bundled `contentstack/assets/regions.json` included in `package_data` — always present after `pip install`.
- `setup.py` auto-refreshes `regions.json` at build time via a custom `BuildPyWithRegions` command; network failures warn but never block the build.
- Runtime fallback: if `regions.json` is absent, the SDK downloads it live on the first `Endpoint` call.
- Added `refresh_regions()` utility to programmatically download the latest regions manifest from the Contentstack CDN and overwrite the bundled `assets/regions.json` (`from contentstack import refresh_regions`).
- Added `python3 -m contentstack.region_refresh` CLI command for refreshing the registry after `pip install` (source-tree script `scripts/download_regions.py` is for contributors only).

## _v2.5.1_

Expand Down
24 changes: 22 additions & 2 deletions contentstack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,43 @@
from .entry import Entry
from .asset import Asset
from .contenttype import ContentType
from .endpoint import Endpoint
from .https_connection import HTTPSConnection
from contentstack.stack import Stack
from .utility import Utils
from .region_refresh import refresh_regions

__all__ = (
"Entry",
"Asset",
"ContentType",
"Endpoint",
"HTTPSConnection",
"Stack",
"Utils"
"Utils",
"refresh_regions",
)


def get_contentstack_endpoint(region='us', service='', omit_https=False):
"""
Resolve a Contentstack service endpoint URL for a given region.

Proxy to :class:`Endpoint.get_contentstack_endpoint` for convenience —
mirrors ``Contentstack::getContentstackEndpoint()`` in the PHP SDK.

:param region: Region ID or alias ('us', 'eu', 'azure-na', 'gcp-eu', ...).
:param service: Service key ('contentDelivery', 'contentManagement', ...).
When empty, returns a dict of all endpoints for the region.
:param omit_https: When True, strips 'https://' from the returned URL(s).
:returns: str when service is provided, dict[str,str] otherwise.
"""
return Endpoint.get_contentstack_endpoint(region, service, omit_https)

__title__ = 'contentstack-delivery-python'
__author__ = 'contentstack'
__status__ = 'debug'
__version__ = 'v2.5.3'
__version__ = 'v2.6.0'
__endpoint__ = 'cdn.contentstack.io'
__email__ = 'support@contentstack.com'
__developer_email__ = 'mobile@contentstack.com'
Expand Down
1 change: 1 addition & 0 deletions contentstack/contenttype.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# ************* Module ContentType **************
# Your code has been rated at 10.00/10 by pylint
from __future__ import annotations
import json
import logging
from urllib import parse
Expand Down
Loading
Loading