Mirror of Awesome Self Hosted
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.1 KiB

  1. #!/usr/bin/env python3
  2. """ A script to find github repo links and last commit dates in a markdown file
  3. Requirements:
  4. - python3 github module (sudo apt install python3-github on Debian)
  5. - A personal access token (https://github.com/settings/tokens)
  6. Usage:
  7. - Run awesome_bot --allow-redirect -f README.md beforehand to detect any error(4xx, 5xx) that would
  8. cause the script to abort
  9. - Github API calls are limited to 5000 requests/hour https://developer.github.com/v3/#rate-limiting
  10. - Put the token in your environment variables:
  11. export GITHUB_TOKEN=18c45f8d8d556492d1d877998a5b311b368a76e4
  12. - The output is unsorted, just pipe it through 'sort' or paste it in your editor and sort from there
  13. - Put the script in your crontab or run it from time to time. It doesn't make sense to add this
  14. script to the CI job that runs every time something is pushed.
  15. - To detect no-commit related activity (repo metadata changes, wiki edits, ...), replace pushed_at
  16. with updated_at
  17. """
  18. from github import Github
  19. import sys
  20. import time
  21. import re
  22. import os
  23. __author__ = "nodiscc"
  24. __copyright__ = "Copyright 2019, nodiscc"
  25. __credits__ = ["https://github.com/awesome-selfhosted/awesome-selfhosted"]
  26. __license__ = "MIT"
  27. __version__ = "1.0"
  28. __maintainer__ = "nodiscc"
  29. __email__ = "nodiscc@gmail.com"
  30. __status__ = "Production"
  31. ###############################################################################
  32. access_token = os.environ['GITHUB_TOKEN']
  33. """ find all URLs of the form https://github.com/owner/repo """
  34. with open('README.md', encoding="utf8") as readme:
  35. data = readme.read()
  36. project_urls = re.findall('https://github.com/[A-z]*/[A-z|0-9|\-|_|\.]+', data)
  37. urls = sorted(set(project_urls))
  38. """ Uncomment this to debug the list of matched URLs """
  39. # print(str(urls))
  40. # exit(0)
  41. """ login to github API """
  42. g = Github(access_token)
  43. """ load project metadata, output last commit date and URL """
  44. for url in urls:
  45. project = re.sub('https://github.com/', '', url)
  46. repo = g.get_repo(project)
  47. print(str(repo.pushed_at) + ' https://github.com/' + project + ' archived:' + str((repo.archived)))