repoupload.py 1.4 KB

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env python
  2. import requests
  3. from requests.auth import HTTPBasicAuth
  4. import os
  5. import argparse
  6. def get_arguments():
  7. parser = argparse.ArgumentParser(description='repoupload.py upload to an organization repos downloaded')
  8. parser.add_argument('-u', '--username', type=str, metavar='USER', help='Username for your account on gitea site')
  9. parser.add_argument('-p', '--password', type=str, metavar='PASSWORD', help='Password for your account on gitea site')
  10. parser.add_argument('-s', '--site', type=str, metavar='SITE', help='Website where your uploading these repos too a gitea instance.')
  11. parser.add_argument('-d', '--directory', type=str, metavar='DIRECTORY', help='Directory where your repos are.')
  12. parser.add_argument('-o', '--organization', type=str, metavar='organization', help='Organization name.')
  13. args = parser.parse_args()
  14. return args
  15. def main():
  16. args = get_arguments()
  17. for repo in os.listdir(str(args.directory)):
  18. x = requests.post(f'{args.site}/api/v1/orgs/{args.organization}/repos', json={"name":repo}, auth=HTTPBasicAuth(args.username, args.password))
  19. print(x.text)
  20. os.system(f"cd {args.organization} && cd {repo} && git remote set-url origin https://codeberg.org/{args.organization}/{repo}/")
  21. os.system(f"cd {args.organization} && cd {repo} && git add .")
  22. os.system(f"cd {args.organization} && cd {repo} && git push --force")
  23. if __name__ == '__main__':
  24. main()