updates for raycast

This commit is contained in:
Christian Lempa committed 2023-06-13 18:02:33 +02:00
1 parent 357980e765
commit 82b92939c1
7 files changed
+252

No files matched your search

+1
View File
@@ -0,0 +1 @@
**/.env
Binary file not shown.
+16
View File
@@ -0,0 +1,16 @@
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Check Repos 2
# @raycast.mode fullOutput
# Optional parameters:
# @raycast.icon 🤖
# Documentation:
# @raycast.author ChristianLempa
# @raycast.authorURL https://raycast.com/ChristianLempa
op run --env-file="/Users/xcad/.env" -- python3 /Users/xcad/Projects/christianlempa/scripts/repos check --list-orphaned
+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env python3
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title List Repos for clcreative
# @raycast.mode fullOutput
# Optional parameters:
# @raycast.icon https://avatars.githubusercontent.com/u/97734037?s=200&v=4
# Documentation:
# @raycast.author ChristianLempa
# @raycast.authorURL https://raycast.com/ChristianLempa
from dotenv import load_dotenv
import os
from repos import getRepos
load_dotenv()
github_token = os.getenv("GITHUB_TOKEN")
ignored_folders = [
'.git',
'.DS_Store',
'.obsidian',
]
if __name__ == "__main__":
try:
# List all repos for an organization from GitHub
# https://docs.github.com/en/rest/reference/repos#list-organization-repositories
repos = getRepos(github_token, 'clcreative')
if repos is not None:
for repo in repos:
print(f"{repo['name']}, {repo['owner']['login']}, {repo['description']}")
else:
raise Exception("repos is None")
# Sum all repos
print(f"---\nTotal: {len(repos)}")
except Exception as e:
print(f"error: {e}")
+83
View File
@@ -0,0 +1,83 @@
#!/usr/bin/env python3
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Check Repos for clcreative
# @raycast.mode inline
# Optional parameters:
# @raycast.icon https://avatars.githubusercontent.com/u/97734037?s=200&v=4
# Documentation:
# @raycast.author ChristianLempa
# @raycast.authorURL https://raycast.com/ChristianLempa
from dotenv import load_dotenv
import os
from pathlib import Path
from repos import getRepos
load_dotenv()
github_token = os.getenv("GITHUB_TOKEN")
ignored_folders = [
'.git',
'.DS_Store',
'.obsidian',
]
if __name__ == "__main__":
try:
# Get all repos for an organization from GitHub
# https://docs.github.com/en/rest/reference/repos#list-organization-repositories
repos = getRepos(github_token, 'clcreative')
repos_need_changes = []
repos_not_cloned = []
if repos is not None:
for repo in repos:
# set repo path on local workstation
repo_path = f'{ Path.home() }/projects/{repo["owner"]["login"]}/{repo["name"]}'
# when repo is existing
if os.path.exists(repo_path):
try:
os.chdir(repo_path)
# check if there are any changes
# changes = os.system('git diff --exit-code --quiet')
# check if there are any changes to the repo, and if something needs to be pulled or committed
changes = os.system('git diff --exit-code --quiet')
if changes != 0:
# print(f" {repo['name']} - {repo['description']}")
repos_need_changes.append(repo)
else:
pass
# print(f" {repo['name']} - {repo['description']}")
except Exception as e:
print(f"error: {e}")
else:
# print(f" {repo['name']} - {repo['description']}")
repos_not_cloned.append(repo)
# Check orphaned repos
repos_orphaned = []
# read all folders in projects folder
for item in os.listdir(f'{ Path.home() }/projects/clcreative'):
# check if item is in repos list, and if item is not in ignored folders
if item not in [repo['name'] for repo in repos] and item not in ignored_folders:
repos_orphaned.append(item)
# Get Information about all Repos
print(f"Repos: {len(repos)} \033[31m(u: {len(repos_need_changes)}, m: {len(repos_not_cloned)}, o: {len(repos_orphaned)})\033[0m")
except Exception as e:
print(f"error: {e}")
+56
View File
@@ -0,0 +1,56 @@
#!/usr/bin/env python3
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Clone Repos for clcreative
# @raycast.mode inline
# Optional parameters:
# @raycast.icon https://avatars.githubusercontent.com/u/97734037?s=200&v=4
# Documentation:
# @raycast.author ChristianLempa
# @raycast.authorURL https://raycast.com/ChristianLempa
from dotenv import load_dotenv
import os
from pathlib import Path
from repos import getRepos
load_dotenv()
github_token = os.getenv("GITHUB_TOKEN")
ignored_folders = [
'.git',
'.DS_Store',
'.obsidian',
]
if __name__ == "__main__":
# Clone Repositories for clcreative
# https://docs.github.com/en/rest/reference/repos#list-organization-repositories
# --
try:
repos = getRepos(github_token, 'clcreative')
cloned_repos = []
if repos is not None:
for repo in repos:
# set repo path on local workstation
repo_path = f'{ Path.home() }/projects/{repo["owner"]["login"]}/{repo["name"]}'
# when repo is not existing
if not os.path.exists(repo_path):
# print(f" {repo['name']} - {repo['description']}")
os.system(f'git clone git@github.com:{repo["owner"]["login"]}/{repo["name"]}.git {repo_path}')
cloned_repos.append(repo)
# Show how many repos are cloned
print(f"\033[32mcloned: {len(cloned_repos)}\033[0m")
except Exception as e:
print(f"error: {e}")
+49
View File
@@ -0,0 +1,49 @@
import requests
def getReposFromPage(github_token: str, organization: str, page: int):
# Get all repos from a specific page for an organization from GitHub.
# https://docs.github.com/en/rest/reference/repos#list-organization-repositories
try:
url = f"https://api.github.com/orgs/{organization}/repos"
payload = {}
headers = {
'Authorization': f'token {github_token}'
}
params = {
'per_page': '100',
'page': page,
'sort': 'full_name'
}
response = requests.request("GET", url, headers=headers, data=payload, params=params)
if response.status_code == 200:
return response.json()
else:
raise Exception(f"status code {response.status_code}")
except Exception as e:
print(f"error: {e}")
return None
def getRepos(github_token: str, organization: str):
# Get all repos for an organization from GitHub by iterating over all pages.
# https://docs.github.com/en/rest/reference/repos#list-organization-repositories
try:
repos = []
page = 1
while True:
repos_page = getReposFromPage(github_token, organization, page)
if repos_page is not None:
repos.extend(repos_page)
if len(repos_page) < 100:
break
else:
page += 1
else:
raise Exception("repos_page is None")
return repos
except Exception as e:
print(f"error: {e}")
return None