1
1
Fork 0
mirror of https://github.com/tonydamage/nux-env.git synced 2025-12-11 13:24:28 +01:00

taskie: Added initial version.

Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
Tony Tkáčik 2017-06-21 10:50:27 +02:00
parent 613ef65f67
commit 73f634318f
6 changed files with 240 additions and 1 deletions

View file

@ -11,7 +11,8 @@
## - *local* - by default same as global
## - *global* - ~/.config/{app-name}/
## - *dist* - {app-path}/config
## - value is tried to be read first from *local*, then *global*, then *dist* configuration.
## - value is tried to be read first from *local*, then *global*, then *dist*
## configuration.
##
## #Usage
##

View file

@ -0,0 +1,17 @@
backend.github.with() {
github_repository=$(echo $backendId | cut -d: -f2)
github_api_url=https://api.github.com
github_api_user=$(nux.cfg.read github.user)
github_api_token=$(nux.cfg.read github.api.token)
github_issuemap=~/.config/taskie/github.issuemap.json
nux.log debug Github repository is $github_repository;
nux.log debug Github API URL: $github_api_url;
}
backend.github.list() {
local api="$github_api_url/repos/$github_repository/issues"
CURL_ADDITIONAL_ARGS="-u $github_api_user:$github_api_token" \
backend.githublike.get "$api" | jq -r ".[] | [.number,.state,.title] | @sh"
}

View file

@ -0,0 +1,67 @@
nux.use taskie/backend.utils
backend.gogs.list() {
local api="$gogs_api_url/repos/$gogs_repository/issues?token=$gogs_api_token"
local append_next="&token=$gogs_api_token"
backend.githublike.get "$api" "$append_next" \
| jq -r ".[] | [.number,.state,.title] | @sh"
}
backend.gogs.issue.exists() {
local message="$@"
nux.json.start
nux.json.open "$gogs_issuemap"
id=$(nux.json.read "\"$gogs_api_url\".\"$gogs_repository\".\"$message\"")
nux.log debug "Message Id is $id"
test "$id" != null #-o -n "$id";
}
backend.gogs.detect() {
closest_git=$(nuxfs.closest .git "$1")
git.origins "$closest_git" | while read origin
do
nux.log debug Testing backend for: $origin
optlist=$(nux.url.parse "$origin" "\1\3\5\6\8 \5\6\8 \5\8 \5\6 \5")
repository=$(nux.url.parse "$origin" "\9" | sed -s "s/\.git\$//")
for opt in $optlist; do
gogs_api_url=$(gogs.config.site "$opt" ".api.url")
if [ -n "$gogs_api_url" ]; then
echo $repository:$closest_git:$opt
return 0;
fi
done
done
}
backend.gogs.with() {
gogs_repository=$(echo $backendId | cut -d: -f2)
gogs_configId=$(echo $backendId | cut -d: -f4)
gogs_api_url=$(gogs.config.site "$gogs_configId" .api.url)
gogs_api_token=$(gogs.config.site "$gogs_configId" .api.token)
gogs_issuemap=$(nux.cfg.dir.global)/gogs.issuemap.json
nux.log debug Gogs repository is $gogs_repository;
nux.log debug Gogs API URL: $gogs_api_url;
}
backend.gogs.add() {
echo "Adding issue:" "\"$@\""
local message="$@"
local payload="{\"title\": \"$message\",\"body\": \"$message\"}"
local api="$gogs_api_url/repos/$gogs_repository/issues?token=$gogs_api_token"
nux.log debug Repository is $gogs_repository, message is $message
nux.log debug API call: $api Payload: $payload
remId=$(curl -s -H "Content-Type: application/json" -X POST -d "$payload" "$api" | jq -r .number)
nux.json.start
nux.json.open "$gogs_issuemap"
nux.json.write "\"$gogs_api_url\".\"$gogs_repository\".\"$message\"" $remId
nux.json.flush "$gogs_issuemap"
echo Issue Number is: $remId
}

View file

@ -0,0 +1,20 @@
backend.githublike.get() {
local api=$1;
local append_next="$2";
nux.log debug Repository is $gogs_repository, message is $message
nux.log debug API call: $api Payload: $payload
header_tmp=$(mktemp);
while [ -n "$api" ];
do
curl $CURL_ADDITIONAL_ARGS -s -D "$header_tmp" -H "Content-Type: application/json" "$api"
next=$(grep "Link: " "$header_tmp" | tr "," "\n" | grep rel=\"next\" | cut -d"<" -f2 | cut -d">" -f1)
nux.log debug Next "$next";
if [ -n "$next" ]; then
api="${next}${append_next}"
else
api=""
fi
done;
rm -f $header_tmp;
}

View file