Skip to content

Commit f05ba4e

Browse files
authored
feat: no-github input option for git-cliff-release (#165)
1 parent 86e704a commit f05ba4e

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

git-cliff-release/action.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ inputs:
3333
required: false
3434
type: string
3535
default: ${{ github.token }}
36+
add-github-links:
37+
description: If set to false, the action will not insert links to GitHub issues and PRs in the release notes and changelog.
38+
required: false
39+
type: boolean
40+
default: true
3641
outputs:
3742
is_prerelease:
3843
description: For convenience - was the action triggered with release_type = "prerelease"?
@@ -100,9 +105,15 @@ runs:
100105
working-directory: ${{ github.action_path }}
101106
run: |
102107
set -x
108+
enhance_context_args=()
109+
110+
if [[ ${{ inputs.add-github-links }} = false ]]; then
111+
enhance_context_args+=(--no-github)
112+
fi
113+
103114
echo 'release_notes<<EOF' >> $GITHUB_OUTPUT
104115
git-cliff --tag "${{ steps.version_number.outputs.tag_name }}" --unreleased --context |
105-
python enhance_context.py --repo $GITHUB_REPO --release-notes |
116+
python enhance_context.py --repo $GITHUB_REPO --release-notes "${enhance_context_args[@]}" |
106117
git-cliff --from-context - --strip all |
107118
tee -a $GITHUB_OUTPUT
108119
echo 'EOF' >> $GITHUB_OUTPUT
@@ -135,6 +146,10 @@ runs:
135146
print_changelog_args+=(--output "$out_file")
136147
fi
137148
149+
if [[ ${{ inputs.add-github-links }} = false ]]; then
150+
enhance_context_args+=(--no-github)
151+
fi
152+
138153
if [[ ${{ inputs.release_type }} = prerelease ]]; then
139154
enhance_context_args+=(--unreleased-version "${{ steps.version_number.outputs.tag_name }}")
140155
else

git-cliff-release/cliff.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ body = """
3636
{{ commit.message | escape | upper_first }}\
3737
{% endif %}\
3838
{% if commit.extra.commit_link %} ([{{ commit.id | truncate(length = 7, end = "") }}]({{ commit.extra.commit_link }})){% endif %}\
39-
{% if commit.remote.username and extra.is_release_notes %}\
40-
{{" "}}by @{{ commit.remote.username }}\
41-
{% elif commit.remote.username %}\
42-
{{" "}}by [@{{ commit.remote.username }}](https://github.com/{{ commit.remote.username }})\
39+
{% if commit.extra.username and extra.is_release_notes %}\
40+
{{" "}}by @{{ commit.extra.username }}\
41+
{% elif commit.extra.username %}\
42+
{{" "}}by [@{{ commit.extra.username }}](https://github.com/{{ commit.extra.username }})\
4343
{% if commit.extra.closed_issue_links %}\
4444
, closes {{ commit.extra.closed_issue_links | join(sep = ", ") }}\
4545
{% endif %}\

git-cliff-release/enhance_context.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,17 @@ def enhance_release(
4444

4545

4646
def enhance_commit(commit: dict[str, Any], pr_issues: dict[int, list[int]]) -> None:
47-
pr_number = commit.get("remote", {}).get("pr_number")
47+
commit_remote = commit.get("remote", {})
48+
49+
pr_number = commit_remote.get("pr_number")
50+
username = commit_remote.get("username")
4851

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

55+
if username:
56+
commit["extra"]["username"] = username
57+
5258
if pr_number:
5359
commit["extra"]["closed_issues"] = pr_issues.get(pr_number, [])
5460

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

7077

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

79-
for release in context:
80-
enhance_release(release, args.release_notes, args.unreleased_version)
86+
if not args.no_github:
87+
for release in context:
88+
enhance_release(release, args.release_notes, args.unreleased_version)
8189

82-
for commit in release["commits"]:
83-
enhance_commit(commit, pr_issues)
90+
for commit in release["commits"]:
91+
enhance_commit(commit, pr_issues)
8492

8593
json.dump(context, sys.stdout)

0 commit comments

Comments
 (0)