restructure to folders

This commit is contained in:
keystroke 2026-02-06 23:27:46 +11:00
parent bff3302b73
commit a3a153af38
6 changed files with 80 additions and 0 deletions

View file

@ -1,6 +1,12 @@
# Snippets
## Bash
- backup.sh: Backup script that syncs from a file containing directories/files to an offsite remote using rclone.
- monitor-toggle.sh: Turn off a display to stop my monitor from switching to the "active" server input with my computer off.
- remove-metadata.sh: Removes name and comment metadata from mp4 and mkv files from a directory recursively.
## PHP
- E621Bridge.php: An e621 bridge for [rss-bridge](https://github.com/RSS-Bridge/rss-bridge).
## Python
- github2forgejo.py: Copying a user's GitHub repositories and querying a Forgejo API to migrate them.

74
python/github2forgejo.py Normal file
View file

@ -0,0 +1,74 @@
#!/usr/bin/python
import requests
# Vars
FORGEJO_OWNER = 'user'
FORGEJO_URL = 'https://git.example.org'
GITHUB_ACCESS_TOKEN = 'ghp_???'
FORGEJO_ACCESS_TOKEN = '???'
# Get GitHub repos
gh_api = 'https://api.github.com/user/repos'
gh_headers = {
'Accept': 'application/vnd.github+json',
'Authorization': f'Bearer {GITHUB_ACCESS_TOKEN}',
'X-GitHub-Api-Version': '2022-11-28',
}
gh_params = {
'affiliation': 'owner', # Don't migrate orgs
'per_page': 100,
'page': 1
}
repos = []
while True: # Keep going until end of pagination
gh_response = requests.get(gh_api, headers=gh_headers, params=gh_params)
repos += gh_response.json()
if not 'Link' in gh_response.headers:
break
if not 'rel="next"' in gh_response.headers['Link']:
break
gh_params.update({'page': gh_params['page'] + 1})
# Forgejo migration
fj_api = f'{FORGEJO_URL}/api/v1/repos/migrate'
fj_headers = {
'accept': 'application/json',
'Authorization': f'token {FORGEJO_ACCESS_TOKEN}',
'Content-Type': 'application/json'
}
fj_body = {
'service': 'github',
'auth_token': GITHUB_ACCESS_TOKEN,
'mirror': False,
'lfs': False,
'wiki': True,
'issues': True,
'pull_requests': True,
'labels': True,
'milestones': True,
'releases': True,
'repo_owner': FORGEJO_OWNER
}
for repo in repos:
print(f'Migrating {repo['name']}')
fj_body.update({
'clone_addr': repo['clone_url'],
'repo_name': repo['name'],
'private': repo['private'],
'description': repo['description']
})
fj_response = requests.post(fj_api, headers=fj_headers, json=fj_body)
if fj_response.status_code == 201:
print('Success!')
elif fj_response.status_code == 409:
print('Repository already exists')
else:
print(f'Status code {fj_response.status_code}; check documentation: {FORGEJO_URL}/api/swagger#/repository/repoMigrate')