add script to create repos on gitea instances
This commit is contained in:
118
README.md
118
README.md
@@ -1,3 +1,119 @@
|
||||
# gitea_repo_creator
|
||||
|
||||
--created with create_repo.py
|
||||
`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](https://demo.gitea.com/api/swagger#/repository/createCurrentUserRepo)
|
||||
|
||||
<details>
|
||||
<summary>Show table</summary>
|
||||
|
||||
| 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`<br>`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`<br>`collaborator`<br>`committer`<br>`collaboratorcommiter` | `false` | `false` |
|
||||
|
||||
</details>
|
||||
|
||||
[^1]: name of template to use, returns error when name not found
|
||||
|
||||
### examples
|
||||
|
||||
#### *sh
|
||||
|
||||
```bash
|
||||
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
|
||||
|
||||
```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
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
#### Python
|
||||
|
||||
`pip install requests`
|
||||
|
||||
```python
|
||||
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())
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user