Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- TOKEN=GITLAB_ACCESS_TOKEN
- function url_to_namespaced_path_encoded {
- url=$1
- if [[ ${url} == git@* ]]; then
- # ssh clone url. remove server path
- url=${url#*:}
- else
- # http[s] clone url. remove server path
- url=${url#*//}
- url=${url#*/}
- fi
- # remove .git from end
- url=${url%.git}
- # replace / with %2F
- url=${url//'/'/"%2F"}
- echo ${url}
- }
- function url_to_hostname {
- url=$1
- if [[ ${url} == git@* ]]; then
- # ssh clone url. remove server path
- url=${url:4}
- url=${url%%:*}
- else
- # http[s] clone url. remove server path
- url=${url#*//}
- url=${url%%/*}
- fi
- echo ${url}
- }
- TODOS=$(git diff --cached --diff-filter=d -U0 | grep -e "^+.*TODO")
- remoteURL=$(git remote get-url origin)
- remotePath=$(url_to_namespaced_path_encoded ${remoteURL})
- hostname=$(url_to_hostname ${remoteURL})
- if [ "${TODOS}" != "" ]; then
- # for line in variable
- while IFS= read -r line; do
- # remove TODO and text before it.
- text=${line#*TODO}
- curl --request POST --header "PRIVATE-TOKEN: ${TOKEN}" --data-urlencode "title=${text}" https://${hostname}/api/v4/projects/${remotePath}/issues >/dev/null
- done <<< "${TODOS}"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement