Skip to content

Commit

Permalink
feat: no-github input option for git-cliff-release (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
barjin authored Dec 18, 2024
1 parent 86e704a commit f05ba4e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
17 changes: 16 additions & 1 deletion git-cliff-release/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ inputs:
required: false
type: string
default: ${{ github.token }}
add-github-links:
description: If set to false, the action will not insert links to GitHub issues and PRs in the release notes and changelog.
required: false
type: boolean
default: true
outputs:
is_prerelease:
description: For convenience - was the action triggered with release_type = "prerelease"?
Expand Down Expand Up @@ -100,9 +105,15 @@ runs:
working-directory: ${{ github.action_path }}
run: |
set -x
enhance_context_args=()
if [[ ${{ inputs.add-github-links }} = false ]]; then
enhance_context_args+=(--no-github)
fi
echo 'release_notes<<EOF' >> $GITHUB_OUTPUT
git-cliff --tag "${{ steps.version_number.outputs.tag_name }}" --unreleased --context |
python enhance_context.py --repo $GITHUB_REPO --release-notes |
python enhance_context.py --repo $GITHUB_REPO --release-notes "${enhance_context_args[@]}" |
git-cliff --from-context - --strip all |
tee -a $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -135,6 +146,10 @@ runs:
print_changelog_args+=(--output "$out_file")
fi
if [[ ${{ inputs.add-github-links }} = false ]]; then
enhance_context_args+=(--no-github)
fi
if [[ ${{ inputs.release_type }} = prerelease ]]; then
enhance_context_args+=(--unreleased-version "${{ steps.version_number.outputs.tag_name }}")
else
Expand Down
8 changes: 4 additions & 4 deletions git-cliff-release/cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ body = """
{{ commit.message | escape | upper_first }}\
{% endif %}\
{% if commit.extra.commit_link %} ([{{ commit.id | truncate(length = 7, end = "") }}]({{ commit.extra.commit_link }})){% endif %}\
{% if commit.remote.username and extra.is_release_notes %}\
{{" "}}by @{{ commit.remote.username }}\
{% elif commit.remote.username %}\
{{" "}}by [@{{ commit.remote.username }}](https://github.com/{{ commit.remote.username }})\
{% if commit.extra.username and extra.is_release_notes %}\
{{" "}}by @{{ commit.extra.username }}\
{% elif commit.extra.username %}\
{{" "}}by [@{{ commit.extra.username }}](https://github.com/{{ commit.extra.username }})\
{% if commit.extra.closed_issue_links %}\
, closes {{ commit.extra.closed_issue_links | join(sep = ", ") }}\
{% endif %}\
Expand Down
18 changes: 13 additions & 5 deletions git-cliff-release/enhance_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ def enhance_release(


def enhance_commit(commit: dict[str, Any], pr_issues: dict[int, list[int]]) -> None:
pr_number = commit.get("remote", {}).get("pr_number")
commit_remote = commit.get("remote", {})

pr_number = commit_remote.get("pr_number")
username = commit_remote.get("username")

commit["extra"] = commit["extra"] or {}
commit["extra"]["commit_link"] = f"{repo_url}/commit/{commit['id']}"

if username:
commit["extra"]["username"] = username

if pr_number:
commit["extra"]["closed_issues"] = pr_issues.get(pr_number, [])

Expand All @@ -66,6 +72,7 @@ def enhance_commit(commit: dict[str, Any], pr_issues: dict[int, list[int]]) -> N
parser.add_argument("--repo", type=str, required=True)
parser.add_argument("--unreleased-version", nargs="?", default=None, type=str)
parser.add_argument("--release-notes", action=BooleanOptionalAction)
parser.add_argument("--no-github", default=False, action="store_true")


if __name__ == "__main__":
Expand All @@ -76,10 +83,11 @@ def enhance_commit(commit: dict[str, Any], pr_issues: dict[int, list[int]]) -> N
pr_issues = load_pr_issues(owner, repo)
context = json.load(sys.stdin)

for release in context:
enhance_release(release, args.release_notes, args.unreleased_version)
if not args.no_github:
for release in context:
enhance_release(release, args.release_notes, args.unreleased_version)

for commit in release["commits"]:
enhance_commit(commit, pr_issues)
for commit in release["commits"]:
enhance_commit(commit, pr_issues)

json.dump(context, sys.stdout)

0 comments on commit f05ba4e

Please sign in to comment.