Skip to content

Commit 75ccfe3

Browse files
authored
Merge pull request #166 from consideRatio/pr/default-since
Default --since to latest GitHub Release's tag instead of publication date
2 parents 29258eb + 04844ff commit 75ccfe3

1 file changed

Lines changed: 24 additions & 14 deletions

File tree

github_activity/github_activity.py

Lines changed: 24 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,32 @@ 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 GitHub Release associated tag for a given
956+
repository."""
957+
cmd = [
958+
"gh",
959+
"release",
960+
"view",
961+
"-R",
962+
f"{org}/{repo}",
963+
"--json",
964+
"tagName,name,publishedAt",
965+
]
966+
print(f"Auto-detecting latest release tag for: {org}/{repo}")
958967
print(f"Running command: {' '.join(cmd)}")
959968
out = run(cmd, stdout=PIPE)
960969
try:
961970
json = out.stdout.decode()
962971
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"]
972+
tag = release_data["tagName"]
973+
release = release_data["name"]
974+
published_at = release_data["publishedAt"]
975+
print(f"Using tag {tag} from release {release} published at {published_at}")
976+
return tag
967977
except Exception as e:
968-
print(f"Error getting latest release date for {org}/{repo}: {e}")
969-
print("Reverting to using latest git tag...")
978+
print(f"Error getting latest release tag for {org}/{repo}: {e}")
979+
print("Reverting to using latest local git tag...")
970980
out = run("git describe --tags".split(), stdout=PIPE)
971981
tag = out.stdout.decode().rsplit("-", 2)[0]
972982
return tag

0 commit comments

Comments
 (0)