Skip to content

Commit

Permalink
feat: allow scopes using a regular expression (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
nielstenboom authored Feb 17, 2023
1 parent 2a58bd4 commit 6afef73
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
output.txt
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The generated changelog
with:
fetch-depth: 0

- uses: nielstenboom/semantic-changelog-generator@v1.0.1
- uses: nielstenboom/semantic-changelog-generator@v1
id: changelog
with:
base: v1.0.0
Expand All @@ -53,7 +53,7 @@ NOTE: if you want to enter branches with forward slashes in them, you should add
fetch-depth: 0

# point to branch with forward slashes with 'origin' prepended
- uses: nielstenboom/semantic-changelog-generator@v1.0.1
- uses: nielstenboom/semantic-changelog-generator@v1
id: changelog
with:
base: v1.0.0
Expand Down
19 changes: 16 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from pathlib import Path
import re
import subprocess
import sys

Expand All @@ -13,6 +14,18 @@ def run_command(command: str):

return result.stdout.decode("utf-8")

def is_semantic(prefix: str, line: str):
"""
Check if line is a semantic commit message of the form:
<commit hash> <prefix>(<scope>): <message>
examples of input lines:
12345678 feat(backend): add new feature
12345678 feat: add new feature
"""
return re.match(r"(.+)"+ prefix + r"(\(.+\))*\:.*", line) is not None

def main(base: str, head: str):
run_command("git config --global --add safe.directory /github/workspace")
result = run_command(f"git --no-pager log --oneline {base}...{head}")
Expand All @@ -25,11 +38,11 @@ def main(base: str, head: str):
for line in result.split("\n"):
if len(line) < COMMIT_HASH_LENGTH:
continue
elif "feat:" in line:
elif is_semantic("feat",line):
feat.append(line)
elif "fix:" in line:
elif is_semantic("fix",line):
fix.append(line)
elif "chore:" in line:
elif is_semantic("chore",line):
chore.append(line)
else:
other.append(line)
Expand Down

0 comments on commit 6afef73

Please sign in to comment.