Generate gitea project automagically
This commit is contained in:
parent
28d3163ca7
commit
0c830127ec
3 changed files with 44 additions and 5 deletions
|
@ -5,7 +5,45 @@ subprocess.call(["git", "add", "*"])
|
|||
subprocess.call(["git", "commit", "-m", "Initial commit"])
|
||||
subprocess.call(["git", "config", "user.name", "{{ cookiecutter.git_user }}"])
|
||||
subprocess.call(["git", "config", "user.email", "{{ cookiecutter.email }}"])
|
||||
subprocess.call(["git", "remote", "add", "origin", "{{ cookiecutter.git_ogirin }}"])
|
||||
subprocess.call(["git", "branch", "-u", "origin/master"])
|
||||
|
||||
subprocess.call(["python", "-m", "venv", "venv"])
|
||||
|
||||
if {{cookiecutter.generate_gitea_project}}:
|
||||
try:
|
||||
import giteapy
|
||||
except ModuleNotFoundError:
|
||||
print("giteapy is not availabled, repository not created")
|
||||
exit()
|
||||
try:
|
||||
import secretstorage
|
||||
|
||||
connection = secretstorage.dbus_init()
|
||||
collection = secretstorage.get_default_collection(connection)
|
||||
collection.unlock()
|
||||
secret = collection.search_items({"Title": "Gitea Token"}).__next__()
|
||||
secret.unlock()
|
||||
API_KEY = secret.get_secret().decode("utf-8")
|
||||
except (ModuleNotFoundError, StopIteration):
|
||||
try:
|
||||
import getpass
|
||||
|
||||
my_input = getpass.getpass
|
||||
except ModuleNotFoundError:
|
||||
my_input = input
|
||||
API_KEY = my_input(
|
||||
"Secret service or secret {'Title': 'Gitea Token'} not available,"
|
||||
"please enter you gitea api key:"
|
||||
)
|
||||
configuration = giteapy.Configuration()
|
||||
configuration.api_key["access_token"] = API_KEY
|
||||
client = giteapy.ApiClient(configuration)
|
||||
client.configuration.host = "{{ cookiecutter.gitea_url }}/api/v1"
|
||||
api_instance = giteapy.AdminApi(client)
|
||||
username = "{{ cookiecutter.git_user }}"
|
||||
repo = giteapy.CreateRepoOption(
|
||||
name="{{ cookiecutter.project_slug }}", private=True
|
||||
)
|
||||
api_instance.admin_create_repo(username, repo)
|
||||
|
||||
subprocess.call(["git", "remote", "add", "origin", "{{ cookiecutter.git_origin }}"])
|
||||
subprocess.call(["git", "push", "-u", "origin", "master"])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue