Skip to content

Commit ddc9403

Browse files
committed
feat: add auto check for broken links [#1]
1 parent d67d03e commit ddc9403

3 files changed

Lines changed: 145 additions & 2 deletions

File tree

.github/workflows/checker.yaml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Check YouTube Links
2+
3+
on:
4+
schedule:
5+
- cron: "0 15 * * 1" # Every Monday at 8:00 AM PDT (15:00 UTC)
6+
workflow_dispatch:
7+
8+
jobs:
9+
check-youtube-links:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Python with uv
16+
uses: astral-sh/setup-uv@v6
17+
18+
- name: Set up Python
19+
run: uv python install
20+
21+
- name: Install package
22+
run: uv sync && uv pip install -e .
23+
24+
- name: Extract and check YouTube links
25+
id: check_links
26+
run: |
27+
mkdir -p broken
28+
29+
# Extract the list of URLs from Python constant
30+
python -c "from fastapi_spam.constants import TEN_HOURS_OF_FUN; print('\n'.join(TEN_HOURS_OF_FUN))" > links.txt
31+
32+
# Check each URL using curl and grep
33+
while read -r url; do
34+
echo "Checking: $url"
35+
if curl -s "$url" | grep -q "Video unavailable"; then
36+
echo "Broken: $url"
37+
echo "$url" >> broken/urls.txt
38+
else
39+
echo "Valid: $url"
40+
fi
41+
done < links.txt
42+
43+
- name: Open issues for broken links
44+
if: success()
45+
uses: actions/github-script@v7
46+
with:
47+
github-token: ${{ secrets.GITHUB_TOKEN }}
48+
script: |
49+
const fs = require('fs');
50+
const urlsPath = './broken/urls.txt';
51+
52+
if (!fs.existsSync(urlsPath)) {
53+
console.log("No broken URLs found.");
54+
return;
55+
}
56+
57+
const urls = fs.readFileSync(urlsPath, 'utf8').split('\n').filter(Boolean);
58+
59+
const issues = await github.rest.issues.listForRepo({
60+
owner: context.repo.owner,
61+
repo: context.repo.repo,
62+
state: "open"
63+
});
64+
65+
for (const url of urls) {
66+
const alreadyExists = issues.data.some(issue =>
67+
issue.title.includes(url) || issue.body.includes(url)
68+
);
69+
70+
if (!alreadyExists) {
71+
await github.rest.issues.create({
72+
owner: context.repo.owner,
73+
repo: context.repo.repo,
74+
title: `Broken YouTube link detected: ${url}`,
75+
body: `The following YouTube video appears to be unavailable:\n\n${url}\n\nPlease review and update or remove it.`,
76+
});
77+
console.log(`Created issue for ${url}`);
78+
} else {
79+
console.log(`Issue already exists for ${url}`);
80+
}
81+
}

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "fastapi-spam"
3-
version = "0.0.1"
3+
version = "0.0.2"
44
description = "FastAPI middleware to redirect spam requests to a random 10 hours of video"
55
readme = "README.md"
66
requires-python = ">=3.12"
@@ -38,6 +38,7 @@ dev = [
3838
"ruff==0.12.2",
3939
"httpx==0.28.1",
4040
"fastapi==0.116.1",
41+
"requests==2.32.4",
4142
]
4243

4344
[project.urls]

uv.lock

Lines changed: 62 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)