Skip to content

Commit

Permalink
Fix markdown link checker for external PRs (#3333)
Browse files Browse the repository at this point in the history
* Fix markdown link checker for external PRs

* Rename file
  • Loading branch information
schustmi authored Jan 31, 2025
1 parent 94161bf commit 87fee34
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check-markdown-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ jobs:
- name: Install dependencies
run: pip install PyGithub
- name: Run markdown link checker
run: ./scripts/check_and_comment.sh docs
run: ./scripts/check_broken_links.sh docs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ github.event.pull_request.head.repo.fork == false && secrets.GITHUB_TOKEN || '' }}
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,10 @@ def main():
broken_links = check_markdown_links(directory)

# If running in GitHub Actions, handle PR comment
if "GITHUB_TOKEN" in os.environ:
if token := os.environ.get("GITHUB_TOKEN"):
# Only import github when needed
from github import Github

token = os.environ.get("GITHUB_TOKEN")
if not token:
print("Error: GITHUB_TOKEN not set")
sys.exit(1)

with open(os.environ["GITHUB_EVENT_PATH"]) as f:
event = json.load(f)

Expand All @@ -181,7 +176,7 @@ def main():
if existing_comment:
existing_comment.edit(comment_body)
print("Updated existing broken links report comment")
else:
elif broken_links:
pr.create_issue_comment(comment_body)
print("Created new broken links report comment")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,5 @@ if [ ! -d "$CHECK_DIR" ]; then
exit 1
fi

# Only install PyGithub if we're running in GitHub Actions
if [ -n "$GITHUB_TOKEN" ]; then
pip install PyGithub
fi

# Run the Python script
python "$SCRIPT_DIR/check_and_comment.py" "$CHECK_DIR"
python "$SCRIPT_DIR/check_broken_links.py" "$CHECK_DIR"

0 comments on commit 87fee34

Please sign in to comment.