-
Notifications
You must be signed in to change notification settings - Fork 0
/
gogs_plugin.sh
48 lines (48 loc) · 2.08 KB
/
gogs_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
################################################
# Gogs Server API Plugin for git_sync
# Author: Abdelaziz Elrashed (@vzool)
# Version: 0.3
# Date: 2024-01-08
# License: MIT
# REF: https://github.com/gogs/go-gogs-client
################################################
function gogs_plugin_version(){ echo "vzool_0.3"; }
function gogs_required_permissions(){ echo "non-specifiable"; }
function gogs_user_can_create_repo_flag(){ echo "true"; }
function gogs_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 gogs_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?token=$TOKEN)
}
function gogs_check_organization(){
local domain="$1"
echo $(curl --write-out '%{http_code}' --silent --output /dev/null -X GET \
$HTTP_HOST/api/v1/orgs/$domain?token=$TOKEN)
}
function gogs_create_organization(){
local domain="$1"
echo $(curl --write-out '%{http_code}' --silent --output /dev/null -X POST \
-H "Content-Type: application/json" \
-d '{"username": "'$domain'", "full_name": "'$domain'", "description": "My Repositores Mirror from '$domain'"}' \
$HTTP_HOST/api/v1/user/orgs?token=$TOKEN)
}
function gogs_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/org/$domain/repos?token=$TOKEN)
}