Generate gitea project automagically
This commit is contained in:
parent
28d3163ca7
commit
0c830127ec
|
@ -5,8 +5,10 @@
|
|||
"email": "histausse@protonmail.com",
|
||||
"git_user": "histausse",
|
||||
"project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_') }}",
|
||||
"project_url": "https://git.mineau.eu/{{ cookiecutter.git_user }}/{{ cookiecutter.project_slug }}",
|
||||
"git_ogirin": "git@git.mineau.eu/{{ cookiecutter.git_user }}/{{ cookiecutter.project_slug }}.git",
|
||||
"gitea_url": "https://git.mineau.eu",
|
||||
"project_url": "{{ cookiecutter.gitea_url }}/{{ cookiecutter.git_user }}/{{ cookiecutter.project_slug }}",
|
||||
"generate_gitea_project": true,
|
||||
"git_origin": "{{ cookiecutter.gitea_url.replace('https://', 'gitea@').replace('http://', 'gitea') }}:{{ cookiecutter.git_user }}/{{ cookiecutter.project_slug }}.git",
|
||||
"version": "0.1.0",
|
||||
"open_source_license": ["GNU General Public License v3", "MIT license", "BSD license", "ISC license", "Apache Software License 2.0", "Not open source"],
|
||||
"python_min_version": "3.10"
|
||||
|
|
|
@ -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…
Reference in a new issue