Created
January 27, 2020 12:23
-
-
Save tclh123/4ccb504839ad40229edfce2ef326ac92 to your computer and use it in GitHub Desktop.
Upload gitlab snippets from cli. dependency: [python-gitlab](https://github.com/python-gitlab/python-gitlab)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
filepath=$1 | |
if [[ -z $filepath ]]; then | |
echo "Usage: $0 <filepath>" | |
exit 1 | |
fi | |
filename=$(basename $filepath) | |
random_title=$(strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 14 | tr -d '\n'; echo) | |
out=$(gitlab snippet create --title $random_title --file-name $filename --content "$(cat $filepath)" 2>/dev/null) | |
guess_url=$(sed -nr 's|^url\s*=\s*(http.*)|\1|p' ~/.python-gitlab.cfg | head -n1) | |
id=$(echo "$out"| sed -nr 's|id: ([0-9]+)|\1|p') | |
echo [OK] Uploaded $random_title | |
echo Go: $guess_url/snippets/$id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment