Closed bigswede74 closed 4 months ago
@bigswede74 Thanks for opening this one! I'll take a look at reproducing now.
Is it accurate to say that this is failing silently or is the program halting?
Is it accurate to say that this is failing silently or is the program halting?
@zkoppert Correct, the action finishes however the stale repo is not identified.
Starting stale repo search...
Exempt topics: ['reserved']
https://github.com/{org}/maintenance is exempt from stale repo check
Found 0 stale repos in {org}
No stale repos found
I'm unable to reproduce this on my first try. Take a look at what i've done below and see if that makes sense or if I should be trying something different. Alternatively, if you could find an open source repo that this fails on so I can test and debug there or if you'd like to pair, I can send you a link to schedule some time to walk through this together. Let me know what you think!
ENV:
INACTIVE_DAYS=7
ORGANIZATION='github'
EXEMPT_TOPICS='keep, hide, run-away'
ACTIVITY_METHOD='default_branch_updated'
RELEVANT CODE FROM stale_repos.py
:
days_inactive = (datetime.now(timezone.utc) - active_date).days
visibility = "private" if repo.private else "public"
if days_inactive > int(inactive_days_threshold):
inactive_repos.append(
(repo.html_url, days_inactive, active_date_disp, visibility)
)
print(f"{repo.html_url}: {days_inactive} days inactive") # type: ignore
and
def get_active_date(repo):
"""Get the last activity date of the repository.
Args:
repo: A Github repository object.
Returns:
A date object representing the last activity date of the repository.
"""
activity_method = os.getenv("ACTIVITY_METHOD", "pushed").lower()
try:
if activity_method == "default_branch_updated":
commit = repo.branch(repo.default_branch).commit
active_date = parse(commit.commit.as_dict()["committer"]["date"])
elif activity_method == "pushed":
last_push_str = repo.pushed_at # type: ignored
if last_push_str is None:
return None
active_date = parse(last_push_str)
else:
raise ValueError(
f"""
ACTIVITY_METHOD environment variable has unsupported value: '{activity_method}'.
Allowed values are: 'pushed' and 'default_branch_updated'
"""
)
except github3.exceptions.GitHubException:
print(f"{repo.html_url} had an exception trying to get the activity date.")
return None
return active_date
I stepped through with a debugger and observed that it
OUTPUT:
https://github.com/github/github_cards: 5614 days inactive
https://github.com/github/github-flavored-markdown: 3589 days inactive
https://github.com/github/version_sorter: 57 days inactive
output of github_cards matches the gh api query given in this issue
zkoppert@Zacherys-MBP ~ % gh api repos/github/github_cards/commits | jq -r '.[0] | "\(.sha) \(.commit.message) \(.commit.author.name) \(.commit.author.date)"'
8350db1e4f3a9946568d391e058633933f709b25 first ********* 2009-01-13T23:04:40Z
I will try to pull the repo into our org and add some logging.
Thanks! I really appreciate it!
I found the issue, I was using the defalut ${{ secrets.GITHUB_TOKEN }}
which only has access to the repository the workflows is running under. I generated a new access token and it works now. Sorry for the trouble.
No problem! Glad you've got it!
Describe the bug
When
ACTIVITY_METHOD = default_branch_updated
repos with the last commit date outside of theINACTIVE_DAYS
are not returned as stale repos.To Reproduce
Expected behavior
Any repository with the last commit date outside of the
INACTIVE_DAYS
should be returned as a stale repo.Screenshots
No response
Additional context
My repos have the visibility of
Internal
but after looking in the code for this action this does not seem to matter.