-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.sh
executable file
Β·142 lines (118 loc) Β· 5.19 KB
/
post.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash -e
#
# VK share GitHub tag.
#
# @package Bash
# @author Kai Kimera <[email protected]>
# @copyright 2023 Kai Kimera
# @license MIT
# @version 0.0.1
# @link https://github.com/ghastore
# -------------------------------------------------------------------------------------------------------------------- #
# -------------------------------------------------------------------------------------------------------------------- #
# CONFIGURATION.
# -------------------------------------------------------------------------------------------------------------------- #
# Vars.
MODE="${1}"
GH_API="${2}"
GH_TOKEN="${3}"
VK_API="${4}"
VK_TOKEN="${5}"
VK_VER="${6}"
VK_OWNER="${7}"
VK_GROUP="${8}"
VK_CR="${9}"
VK_ADS="${10}"
USER_AGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"
# Apps.
date="$( command -v date )"
curl="$( command -v curl )"
# -------------------------------------------------------------------------------------------------------------------- #
# INITIALIZATION.
# -------------------------------------------------------------------------------------------------------------------- #
init() {
vk_wall_post
}
# -------------------------------------------------------------------------------------------------------------------- #
# GITHUB REPOSITORY TAGS.
# -------------------------------------------------------------------------------------------------------------------- #
gh_tags() {
local repo_api; repo_api=$( gh_api "${GH_API}" )
local repo_name; repo_name=$( jq -r '.full_name' <<< "${repo_api}" )
local repo_url; repo_url=$( jq -r '.html_url' <<< "${repo_api}" )
local repo_desc; repo_desc=$( jq -r '.description' <<< "${repo_api}" )
local repo_tags; repo_tags=$( jq -r '.tags_url' <<< "${repo_api}" )
local tags_api; tags_api=$( gh_api "${repo_tags}?per_page=1" )
local tag_name; tag_name=$( jq -r '.[0].name' <<< "${tags_api}" )
local tag_zip_url; tag_zip_url=$( jq -r '.[0].zipball_url' <<< "${tags_api}" )
local tag_tar_url; tag_tar_url=$( jq -r '.[0].tarball_url' <<< "${tags_api}" )
local tag_sha; tag_sha=$( jq -r '.[0].commit.sha' <<< "${tags_api}" )
echo "π New tag released! π";
[[ "${tag_name}" != "null" ]] && echo "π·οΈ Tag: ${tag_name}"
[[ "${repo_name}" != "null" ]] && echo "π¦ Repository: ${repo_name}"
[[ "${repo_desc}" != "null" ]] && echo "π Description: ${repo_desc}"
[[ "${repo_url}" != "null" ]] && echo "π Repository URL: ${repo_url}"
[[ "${tag_zip_url}" != "null" ]] && echo "πΎ Download (ZIP): ${tag_zip_url}"
[[ "${tag_tar_url}" != "null" ]] && echo "πΎ Download (TAR): ${tag_tar_url}"
[[ "${tag_sha}" != "null" ]] && echo "𧬠SHA: ${tag_sha}"
}
# -------------------------------------------------------------------------------------------------------------------- #
# GITHUB REPOSITORY TOPICS.
# -------------------------------------------------------------------------------------------------------------------- #
gh_topics() {
local topics_api; topics_api=$( gh_api "${GH_API}/topics" )
local names; names=$( ( jq -r '.names | @sh' <<< "${topics_api}" ) | tr -d \' )
for name in ${names}; do
echo -n "#${name} " | sed 's/-/_/'
done
}
# -------------------------------------------------------------------------------------------------------------------- #
# VK MESSAGE CONSTRUCTOR.
# -------------------------------------------------------------------------------------------------------------------- #
vk_message() {
[[ "${MODE}" == "tag" ]] && gh_tags
echo ""
gh_topics
}
# -------------------------------------------------------------------------------------------------------------------- #
# VK WALL POST.
# -------------------------------------------------------------------------------------------------------------------- #
vk_wall_post() {
local message; message="$( vk_message )"
${curl} -s \
"${VK_API}/method/wall.post?owner_id=${VK_OWNER}" \
-F "from_group=${VK_GROUP}" \
-F "message=${message}" \
-F "copyright=${VK_CR}" \
-F "mark_as_ads=${VK_ADS}" \
-F "access_token=${VK_TOKEN}" \
-F "v=${VK_VER}" \
-A "${USER_AGENT}"
}
# -------------------------------------------------------------------------------------------------------------------- #
# ------------------------------------------------< COMMON FUNCTIONS >------------------------------------------------ #
# -------------------------------------------------------------------------------------------------------------------- #
# GitHub API.
gh_api() {
${curl} -s \
-H "Authorization: Bearer ${GH_TOKEN}" \
-H "Accept: application/vnd.github+json" \
-A "${USER_AGENT}" \
"${1}"
}
# Pushd.
_pushd() {
command pushd "$@" > /dev/null || exit 1
}
# Popd.
_popd() {
command popd > /dev/null || exit 1
}
# Timestamp.
_timestamp() {
${date} -u '+%Y-%m-%d %T'
}
# -------------------------------------------------------------------------------------------------------------------- #
# -------------------------------------------------< RUNNING SCRIPT >------------------------------------------------- #
# -------------------------------------------------------------------------------------------------------------------- #
init "$@"; exit 0