Skip to content

Commit c6e278f

Browse files
authored
[ENH] Use latest github release first instead of github tag (#125)
* Use latest github release first instead of github tag * flake
1 parent a9d85f4 commit c6e278f

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

github_activity/github_activity.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import subprocess
77
import sys
88
import urllib
9+
from json import loads
910
from pathlib import Path
1011
from subprocess import CalledProcessError
1112
from subprocess import PIPE
@@ -404,7 +405,7 @@ def generate_activity_md(
404405
# using the _local_ git repostory
405406
# TODO: Check that local repo matches org/repo
406407
if since is None:
407-
since = _get_latest_tag()
408+
since = _get_latest_release_date(org, repo)
408409

409410
# Grab the data according to our query
410411
data = get_activity(
@@ -792,8 +793,22 @@ def _get_datetime_from_git_ref(org, repo, ref, token):
792793
return dateutil.parser.parse(response.json()["commit"]["committer"]["date"])
793794

794795

795-
def _get_latest_tag():
796-
"""Return the latest tag name for a given repository by querying the local repo."""
797-
out = run("git describe --tags".split(), stdout=PIPE)
798-
tag = out.stdout.decode().rsplit("-", 2)[0]
799-
return tag
796+
def _get_latest_release_date(org, repo):
797+
"""Return the latest release date for a given repository by querying the local repo."""
798+
cmd = ["gh", "release", "view", "-R", f"{org}/{repo}", "--json", "name,publishedAt"]
799+
print(f"Auto-detecting latest release date for: {org}/{repo}")
800+
print(f"Running command: {' '.join(cmd)}")
801+
out = run(cmd, stdout=PIPE)
802+
try:
803+
json = out.stdout.decode()
804+
release_data = loads(json)
805+
print(
806+
f"Using release date for release {release_data['name']} on {release_data['publishedAt']}"
807+
)
808+
return release_data["publishedAt"]
809+
except Exception as e:
810+
print(f"Error getting latest release date for {org}/{repo}: {e}")
811+
print("Reverting to using latest git tag...")
812+
out = run("git describe --tags".split(), stdout=PIPE)
813+
tag = out.stdout.decode().rsplit("-", 2)[0]
814+
return tag

0 commit comments

Comments
 (0)