Skip to content

Commit 7063e1f

Browse files
committed
Default --since to latest GitHub Release's tag instead of publication date
1 parent 29258eb commit 7063e1f

1 file changed

Lines changed: 23 additions & 14 deletions

File tree

github_activity/github_activity.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def generate_activity_md(
413413
repository will be used. Can also be a URL to a GitHub org or repo.
414414
since : string | None
415415
Return issues/PRs with activity since this date or git reference. Can be
416-
any string that is parsed with dateutil.parser.parse. If None, the date
416+
any string that is parsed with dateutil.parser.parse. If None, the tag
417417
of the latest release will be used.
418418
until : string | None
419419
Return issues/PRs with activity until this date or git reference. Can be
@@ -452,11 +452,11 @@ def generate_activity_md(
452452
"""
453453
org, repo = _parse_target(target)
454454

455-
# If no since parameter is given, find the name of the latest release
456-
# using the _local_ git repostory
455+
# If no since parameter is given, default to the tag of the latest GitHub
456+
# release, and otherwise fallback to the latest _local_ git tag.
457457
# TODO: Check that local repo matches org/repo
458458
if since is None:
459-
since = _get_latest_release_date(org, repo)
459+
since = _get_latest_release_tag(org, repo)
460460

461461
# Grab the data according to our query
462462
data = get_activity(
@@ -951,22 +951,31 @@ def _get_datetime_from_git_ref(org, repo, ref, token):
951951
return dateutil.parser.parse(response.json()["commit"]["committer"]["date"])
952952

953953

954-
def _get_latest_release_date(org, repo):
955-
"""Return the latest release date for a given repository by querying the local repo."""
956-
cmd = ["gh", "release", "view", "-R", f"{org}/{repo}", "--json", "name,publishedAt"]
957-
print(f"Auto-detecting latest release date for: {org}/{repo}")
954+
def _get_latest_release_tag(org, repo):
955+
"""Return the latest release tag for a given repository."""
956+
cmd = [
957+
"gh",
958+
"release",
959+
"view",
960+
"-R",
961+
f"{org}/{repo}",
962+
"--json",
963+
"tagName,name,publishedAt",
964+
]
965+
print(f"Auto-detecting latest release tag for: {org}/{repo}")
958966
print(f"Running command: {' '.join(cmd)}")
959967
out = run(cmd, stdout=PIPE)
960968
try:
961969
json = out.stdout.decode()
962970
release_data = loads(json)
963-
print(
964-
f"Using release date for release {release_data['name']} on {release_data['publishedAt']}"
965-
)
966-
return release_data["publishedAt"]
971+
tag = release_data["tagName"]
972+
release = release_data["name"]
973+
published_at = release_data["publishedAt"]
974+
print(f"Using tag {tag} from release {release} published at {published_at}")
975+
return tag
967976
except Exception as e:
968-
print(f"Error getting latest release date for {org}/{repo}: {e}")
969-
print("Reverting to using latest git tag...")
977+
print(f"Error getting latest release tag for {org}/{repo}: {e}")
978+
print("Reverting to using latest local git tag...")
970979
out = run("git describe --tags".split(), stdout=PIPE)
971980
tag = out.stdout.decode().rsplit("-", 2)[0]
972981
return tag

0 commit comments

Comments
 (0)