Seppl ff31de0ca2 [general] add template config
[create_repo.py] add default toml filename
[.gitignore] unignore template dir
2024-07-13 21:38:45 +02:00
2024-07-13 21:38:45 +02:00
2024-07-13 21:38:45 +02:00
2024-07-13 21:38:45 +02:00
2024-07-13 21:33:50 +02:00

gitea_repo_creator

python .\create_repo.py -h

TODO

  • create package from script

notes on gitea api usage for creating repos

POST @ endpoint api/v1/user/repos

general notes

required headers

  • accept: application/json
  • Content-Type: application/json
  • Authorization: token your_token_here

request body fields -d '{...}'

Gitea API Documentation

Show table
field name description data type possible values uniqueItems required
name Name of the repository to create string true true
auto_init Whether the repository should be auto-initialized? boolean false false
default_branch DefaultBranch of the repository (used when initializes and in template) string false false
description Description of the repository to create string false false
gitignores Gitignores to use 1 string false false
issue_labels Label-Set to use 1 string false false
license License to use 1 string false false
object_format_name ObjectFormatName of the underlying git repository string sha1
sha256
false false
private Whether the repository is private boolean false false
readme Readme of the repository to create 1 string false false
template Whether the repository is a template boolean false false
trust_model TrustModel of the repository string default
collaborator
committer
collaboratorcommiter
false false

examples

*sh

repo_name="repo_name"
token="your_token_here"
address="gitea.domain.tld"

response="$(\
  curl -X "POST" \
    "https://$address/api/v1/user/repos" \
    -H "accept: application/json" \
    -H "Content-Type: application/json" \
    -H "Authorization: token $token" \
    -d "{\"name\": \"$repo_name\"}" \
2>/dev/null)"

echo $response | jq
# pretty print the returned json object with color highlighting

# alternative, if jq is not installed
# echo $response | python3 -m json.tool

PowerShell

$repo_name = "repo_name"
$token = "your_token_here"
$address = "gitea.domain.tld"

$headers = @{
    "accept" = "application/json"
    "Authorization" = "token $token"
}
$response = Invoke-RestMethod -Uri "https://$address/api/v1/user/repos" `
    -Method Post `
    -Headers $headers `
    -ContentType "application/json" `
    -Body "{`"name`": `"`$repo_name`", `"auto_init`": false}"

echo $response

Python

pip install requests

import requests

repo_name = 'repo_name'
token = 'your_token_here'
address = 'gitea.domain.tld'

headers = {
    'accept': 'application/json',
    'Authorization': f'token {token}',
    # 'Content-Type': 'application/json', # Already added when you pass json=
}

json_data = {
    'name': f'{repo_name}', #required
    'auto_init': False,
}

response = requests.post(f'https://{address}/api/v1/user/repos', headers=headers, json=json_data)

print(response.content.decode())

  1. name of template to use, returns error when name not found ↩︎

Description
--created with create_repo.py
Readme 38 KiB
Languages
Python 100%