Check for dead repositories

parent 7c06dae6
#!/usr/bin/env fish
# A Fish script to check for "dead" repositories
# This file is part of Oh My Fish's packages-main
# https://github.com/oh-my-fish/packages-main
# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2021, Fabian Homborg <FHomborg@gmail.com>
# Copyright (c) 2021, Pablo S. Blum de Aguiar <scorphus@gmail.com>
function read_repository -a user_repo
set -l url https://api.github.com/repos/$user_repo
test "$USERNAME:$TOKEN" != ":"
and curl -s -u $USERNAME:$TOKEN $url
or curl -s $url
end
set -l packages packages/*
set -l python_script (type -p read_repository | sed s/\\.fish\$/\\.py/)
set -l count 0
for package in $packages
set -l url (string replace -rf 'repository *= *(.*)' '$1' < $package)
or begin
echo $package has no repository line ❌
continue
end
set url (string replace -r '.git$' '' -- $url | string trim -c '/')
set package (string replace -r '.*/' '' $package)
set -l user_repo (string replace 'https://github.com/' '' $url)
or begin
echo $package is not on GitHub -- $url ⚠️
continue
end
read_repository $user_repo | python $python_script $package
set count (math $count + $status)
end
set -l total (ls $packages | wc -l)
if test $count -gt 0
echo Found $count/$total repositories with issues 💥
exit 1
end
echo No issues found in $total repositories 🤘
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# A Python script to check repositories statuses
# This file is part of Oh My Fish's packages-main
# https://github.com/oh-my-fish/packages-main
# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2021, Fabian Homborg <FHomborg@gmail.com>
# Copyright (c) 2021, Pablo S. Blum de Aguiar <scorphus@gmail.com>
import json
import logging
import os
import sys
logging.basicConfig(level=os.environ.get('LOG_LEVEL', 'warning').upper())
data = sys.stdin.read()
try:
repo = json.loads(data)
logging.debug("repo: %s", repo)
except:
logging.exception("error parsing response")
repo = None
if not repo:
logging.error("%s could not be read ❌", sys.argv[1])
elif "documentation_url" in repo:
logging.critical("rate limit exceeded when reading %s", sys.argv[1])
elif repo.get("message", "") == "Moved Permanently":
logging.error("%s has moved permanently ❌", sys.argv[1])
elif repo.get("message", "") == "Not Found":
logging.error("%s does not exist ❌", sys.argv[1])
elif repo.get("archived", False):
logging.error("%s has been archived ❌", sys.argv[1])
elif repo.get("has_issues") is False:
logging.error("%s has issues disabled ❌", sys.argv[1])
else:
logging.info("%s is okay ✅", sys.argv[1])
sys.exit(0)
sys.exit(1)
name: Check for dead repositories
on:
push:
pull_request:
schedule:
- cron: '30 5,17 * * *'
jobs:
check-dead-repos:
runs-on: ubuntu-latest
env:
HOME: /home/nemo
USERNAME: ${{ secrets.USERNAME }}
TOKEN: ${{ secrets.TOKEN }}
container: ohmyfish/ohmyfish
steps:
- name: Change current working directory owner and group
run: sudo chown -R nemo:nemo .
- uses: actions/checkout@v2
- name: Install dependencies
run: sudo apk add python3
- name: Check dead repositories
run: fish .github/workflows/check-dead-repos.fish
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment