-
Notifications
You must be signed in to change notification settings - Fork 34
feat: Add WORKFLOW_SUMMARY_ENABLED flag to automatically output stale repo report to GitHub Actions workflow summary #362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
94c805b
Initial plan
Copilot b326c39
Add WORKFLOW_SUMMARY_ENABLED feature to output stale repo report to G…
Copilot aa8809d
Add documentation for WORKFLOW_SUMMARY_ENABLED feature and fix lintin…
Copilot 7f96dd6
Fix GitHub Actions workflow errors by updating super-linter to v6, up…
Copilot e550b45
fix: proper casing
zkoppert 0de76ac
Revert super-linter to hash-based reference for security
Copilot fdfd414
Split markdown functions into separate module as requested
Copilot e48061b
fix: Fix import ordering to resolve isort linting issues
Copilot 4fda04b
fix: Update isort config to include markdown module and fix import or…
Copilot 67ed2a2
feat: Run prettier on markdown files to improve formatting
Copilot 7a391bb
Merge branch 'main' into copilot/fix-226
zkoppert 53e2579
Update .github/workflows/linter.yaml
zkoppert 66238de
Update .github/workflows/use-action.yml
zkoppert ba5c343
Update .github/workflows/python-package.yml
zkoppert 2e5ec32
Update .github/workflows/python-package.yml
zkoppert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[settings] | ||
profile = black | ||
known_third_party = github3,dateutil,dotenv | ||
known_first_party = auth | ||
known_first_party = auth,markdown |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,3 +143,8 @@ cython_debug/ | |
|
||
# IDEA | ||
.idea/** | ||
|
||
# Node.js | ||
node_modules/ | ||
package-lock.json | ||
package.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
"""Markdown utilities for stale repository reporting.""" | ||
|
||
import os | ||
|
||
|
||
def write_to_markdown( | ||
inactive_repos, | ||
inactive_days_threshold, | ||
additional_metrics=None, | ||
workflow_summary_enabled=False, | ||
file=None, | ||
): | ||
"""Write the list of inactive repos to a markdown file. | ||
|
||
Args: | ||
inactive_repos: A list of dictionaries containing the repo, days inactive, | ||
the date of the last push, repository visibility (public/private), | ||
days since the last release, and days since the last pr | ||
inactive_days_threshold: The threshold (in days) for considering a repo as inactive. | ||
additional_metrics: A list of additional metrics to include in the report. | ||
workflow_summary_enabled: If True, adds the report to GitHub Actions workflow summary. | ||
file: A file object to write to. If None, a new file will be created. | ||
|
||
""" | ||
inactive_repos = sorted( | ||
inactive_repos, key=lambda x: x["days_inactive"], reverse=True | ||
) | ||
|
||
# Generate markdown content | ||
content = generate_markdown_content( | ||
inactive_repos, inactive_days_threshold, additional_metrics | ||
) | ||
|
||
# Write to file | ||
with file or open("stale_repos.md", "w", encoding="utf-8") as markdown_file: | ||
markdown_file.write(content) | ||
print("Wrote stale repos to stale_repos.md") | ||
|
||
# Write to GitHub step summary if enabled | ||
if workflow_summary_enabled and os.environ.get("GITHUB_STEP_SUMMARY"): | ||
with open( | ||
os.environ["GITHUB_STEP_SUMMARY"], "a", encoding="utf-8" | ||
) as summary_file: | ||
summary_file.write(content) | ||
print("Added stale repos to workflow summary") | ||
|
||
|
||
def generate_markdown_content( | ||
inactive_repos, inactive_days_threshold, additional_metrics=None | ||
): | ||
"""Generate markdown content for the inactive repos report. | ||
|
||
Args: | ||
inactive_repos: A list of dictionaries containing the repo, days inactive, | ||
the date of the last push, repository visibility (public/private), | ||
days since the last release, and days since the last pr | ||
inactive_days_threshold: The threshold (in days) for considering a repo as inactive. | ||
additional_metrics: A list of additional metrics to include in the report. | ||
|
||
Returns: | ||
str: The generated markdown content. | ||
""" | ||
content = "# Inactive Repositories\n\n" | ||
content += ( | ||
f"The following repos have not had a push event for more than " | ||
f"{inactive_days_threshold} days:\n\n" | ||
) | ||
content += "| Repository URL | Days Inactive | Last Push Date | Visibility |" | ||
|
||
# Include additional metrics columns if configured | ||
if additional_metrics: | ||
if "release" in additional_metrics: | ||
content += " Days Since Last Release |" | ||
if "pr" in additional_metrics: | ||
content += " Days Since Last PR |" | ||
content += "\n| --- | --- | --- | --- |" | ||
if additional_metrics: | ||
if "release" in additional_metrics: | ||
content += " --- |" | ||
if "pr" in additional_metrics: | ||
content += " --- |" | ||
content += "\n" | ||
|
||
for repo_data in inactive_repos: | ||
content += ( | ||
f"| {repo_data['url']} " | ||
f"| {repo_data['days_inactive']} " | ||
f"| {repo_data['last_push_date']} " | ||
f"| {repo_data['visibility']} |" | ||
) | ||
if additional_metrics: | ||
if "release" in additional_metrics: | ||
content += f" {repo_data['days_since_last_release']} |" | ||
if "pr" in additional_metrics: | ||
content += f" {repo_data['days_since_last_pr']} |" | ||
content += "\n" | ||
|
||
return content |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.