-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitea_plugin.sh
52 lines (52 loc) · 2.21 KB
/
gitea_plugin.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
################################################
# Gitea Server API Plugin for git_sync
# Author: Abdelaziz Elrashed (@vzool)
# Version: 0.3
# Date: 2024-01-08
# License: MIT
# REF: https://docs.gitea.com/api/1.20/
################################################
function gitea_plugin_version(){ echo "vzool_0.3"; }
function gitea_required_permissions(){ echo "write:organization, write:repository, write:user"; }
function gitea_user_can_create_repo_flag(){ echo "true"; }
function gitea_check_repository(){
local domain="$1"
local repository="$2"
echo $(curl --write-out '%{http_code}' --silent --output /dev/null -X GET \
-H "Content-Type: application/json" \
-H "Authorization: token $TOKEN" $HTTP_HOST/api/v1/repos/$domain/$repository)
}
function gitea_user_create_repository(){
local domain="$1"
local repository="$2"
echo $(curl --write-out '%{http_code}' --silent --output /dev/null \
-X 'POST' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
--data '{"name":"'$repository'", "private":true, "auto_init": false}' \
$HTTP_HOST/api/v1/user/repos?access_token=$TOKEN)
}
function gitea_check_organization(){
local domain="$1"
echo $(curl --write-out '%{http_code}' --silent --output /dev/null -X GET \
-H "Authorization: Bearer $TOKEN" \
$HTTP_HOST/api/v1/orgs/$domain)
}
function gitea_create_organization(){
local domain="$1"
echo $(curl --write-out '%{http_code}' --silent --output /dev/null -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"username": "'$domain'", "visibility":"private", "full_name": "My Repositores Mirror from '$domain'"}' \
$HTTP_HOST/api/v1/orgs)
}
function gitea_organization_create_repository(){
local domain="$1"
local repository="$2"
echo $(curl --write-out '%{http_code}' --silent --output /dev/null \
-X 'POST' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
--data '{"name":"'$repository'", "private":true, "auto_init": false}' \
$HTTP_HOST/api/v1/orgs/$domain/repos?access_token=$TOKEN)
}