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:
parent
613ef65f67
commit
73f634318f
6 changed files with 240 additions and 1 deletions
134
bin/taskie
Executable file
134
bin/taskie
Executable file
|
|
@ -0,0 +1,134 @@
|
|||
#!/usr/bin/env nux-runner
|
||||
|
||||
# FIXME: Check for configuration
|
||||
|
||||
#source ~/.config/nux-env/taskie
|
||||
|
||||
nux.use nuxfs
|
||||
nux.use nux.repl
|
||||
|
||||
nux.use taskie/backend.github
|
||||
nux.use taskie/backend.gogs
|
||||
|
||||
with.backend() {
|
||||
backendId="$1";
|
||||
backend=$(echo $backendId | cut -d: -f1);
|
||||
nux.exec.optional backend.$backend.with;
|
||||
}
|
||||
|
||||
endwith.backend() {
|
||||
unset backendId;
|
||||
unset backendEngine;
|
||||
}
|
||||
|
||||
|
||||
task.add() {
|
||||
with.backend $(backend.detect);
|
||||
if ! backend.$backend.issue.exists "$@" ; then
|
||||
backend.$backend.add "$@";
|
||||
else
|
||||
nux.echo.error Issue already exists.
|
||||
fi
|
||||
endwith.backend;
|
||||
}
|
||||
|
||||
task.interactive() {
|
||||
with.backend $(backend.detect);
|
||||
.process() {
|
||||
backendFunc=backend.$backend.$command;
|
||||
if nux.check.function $backendFunc; then
|
||||
|
||||
eval backend.$backend.$command "$arguments"
|
||||
else
|
||||
echo "$command" is not defined.
|
||||
fi
|
||||
}
|
||||
.complete() {
|
||||
nux.log debug "Requested completion for " "$@"
|
||||
echo """
|
||||
add
|
||||
done
|
||||
close
|
||||
finish
|
||||
exit
|
||||
list
|
||||
report
|
||||
help
|
||||
""" | grep -G "^ *$@"
|
||||
#statements
|
||||
#statements
|
||||
#statementsi
|
||||
}
|
||||
.prompt() {
|
||||
echo "${nc_green}taskie${nc_end}> "
|
||||
}
|
||||
nux.repl.start .process .prompt .complete
|
||||
endwith.backend;
|
||||
}
|
||||
|
||||
task.list() {
|
||||
with.backend $(backend.detect);
|
||||
backend.$backend.list "$@";
|
||||
endwith.backend;
|
||||
}
|
||||
|
||||
taskie_backends=$(nux.cfg.read backends.preference);
|
||||
|
||||
git.origins() {
|
||||
nux.log debug Closest git parent is $closest_git;
|
||||
if [ -n "$closest_git" ]; then
|
||||
grep -E "url *=" "$closest_git/config" | cut -d= -f2
|
||||
fi
|
||||
}
|
||||
|
||||
task.detect() {
|
||||
backend.detect --all "$@";
|
||||
}
|
||||
|
||||
backend.detect() {
|
||||
all=$1;
|
||||
if [ "$all" = "--all" ]; then
|
||||
shift;
|
||||
fi
|
||||
for backend in $taskie_backends; do
|
||||
nux.log trace Executing backend $backend detection
|
||||
localId=$(backend.$backend.detect "$@")
|
||||
if [ -n "$localId" ]; then
|
||||
echo $backend:$localId
|
||||
if [ "$all" != "--all" ]; then
|
||||
return 0;
|
||||
fi
|
||||
fi
|
||||
done;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
gogs.config.site() {
|
||||
nux.cfg.read "gogs.\"$1\"$2";
|
||||
}
|
||||
|
||||
backend.github.detect() {
|
||||
closest_git=$(nuxfs.closest .git "$1")
|
||||
|
||||
git.origins "$closest_git" | grep github.com | while read origin
|
||||
do
|
||||
repo=$(nux.url.parse "$origin" "\9")
|
||||
echo $repo:$closest_git
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
|
||||
backend.file.detect() {
|
||||
:
|
||||
|
||||
}
|
||||
|
||||
backend.dir.detect() {
|
||||
:
|
||||
}
|
||||
|
|
@ -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
|
||||
##
|
||||
|
|
|
|||
17
inc/taskie/backend.github.inc.sh
Normal file
17
inc/taskie/backend.github.inc.sh
Normal 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"
|
||||
|
||||
}
|
||||
67
inc/taskie/backend.gogs.inc.sh
Normal file
67
inc/taskie/backend.gogs.inc.sh
Normal 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
|
||||
|
||||
}
|
||||
20
inc/taskie/backend.utils.inc.sh
Normal file
20
inc/taskie/backend.utils.inc.sh
Normal 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;
|
||||
}
|
||||
0
inc/taskie/backend.yaml.inc.sh
Normal file
0
inc/taskie/backend.yaml.inc.sh
Normal file
Loading…
Add table
Add a link
Reference in a new issue