You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在创建Release时将Release description设置为必填项?

Great question! GitHub doesn’t have a built-in option to make the Release description a required field directly, but there are two reliable workarounds to enforce this requirement:

方法1:使用GitHub Actions自动校验

This is the easiest way for most teams—you can set up a workflow that checks every new Release and blocks (or cleans up) any that have an empty description.

  • In your repository, create a new workflow file at .github/workflows/require-release-description.yml
  • Paste the following YAML code into the file:
name: Require Release Description
on:
  release:
    types: [created]

jobs:
  check-description:
    runs-on: ubuntu-latest
    steps:
      - name: Validate Release Description
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          RELEASE_BODY: ${{ github.event.release.body }}
          RELEASE_ID: ${{ github.event.release.id }}
          REPO_FULL_NAME: ${{ github.repository }}
        run: |
          if [ -z "${RELEASE_BODY// }" ]; then
            echo "❌ Error: Release description cannot be empty!"
            # Optional: Auto-delete the invalid release (uncomment the lines below)
            # curl -X DELETE "https://api.github.com/repos/$REPO_FULL_NAME/releases/$RELEASE_ID" \
            #   -H "Authorization: token $GITHUB_TOKEN" \
            #   -H "Accept: application/vnd.github.v3+json"
            exit 1
          else
            echo "✅ Release description is valid!"
          fi
  • Commit and push the file to your repository.

How it works:

  • The workflow triggers immediately when a new Release is created
  • It checks if the Release description (the body field) is empty (including whitespace-only content)
  • If empty, it throws an error (which will show up in the Actions tab) and optionally deletes the invalid Release, forcing the user to re-create it with a proper description.
方法2:通过自定义脚本+GitHub API强制校验

If you want tighter control over your release process (e.g., integrating with an internal tool or CI pipeline), you can build a custom script that validates the description before sending the request to create the Release via the GitHub API.

Here’s a quick Python example:

import requests
from typing import Dict

def create_release(repo_owner: str, repo_name: str, tag_name: str, release_name: str, description: str, github_token: str) -> Dict:
    # First, validate the description
    if not description.strip():
        raise ValueError("Release description is required - cannot create a release without it!")
    
    # Call GitHub API to create the release
    api_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/releases"
    headers = {
        "Authorization": f"token {github_token}",
        "Accept": "application/vnd.github.v3+json"
    }
    payload = {
        "tag_name": tag_name,
        "name": release_name,
        "body": description,
        "draft": False,
        "prerelease": False
    }
    
    response = requests.post(api_url, json=payload, headers=headers)
    response.raise_for_status()  # Raise an error if the API call fails
    return response.json()

# Example usage
# create_release(
#     repo_owner="your-username",
#     repo_name="your-repo",
#     tag_name="v1.0.0",
#     release_name="Version 1.0.0",
#     description="Initial stable release with core features X, Y, Z.",
#     github_token="your-github-personal-access-token"
# )

How it works:

  • The script first checks if the description is empty (after stripping whitespace)
  • If validation passes, it sends the request to GitHub’s API to create the Release
  • If validation fails, it raises an error immediately, preventing the empty description from ever reaching GitHub.

For GitHub Enterprise users, you might also have access to admin-level plugins or settings that can enforce this requirement natively, but the above methods work for both public and private GitHub repositories.

内容的提问来源于stack exchange,提问作者Piotr Perak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 08:27:35