Skip to content

Instantly share code, notes, and snippets.

@kernoeb
Last active June 29, 2020 11:42
Show Gist options
  • Save kernoeb/6da296aced9443d604a630b8fbfc5bf2 to your computer and use it in GitHub Desktop.
Save kernoeb/6da296aced9443d604a630b8fbfc5bf2 to your computer and use it in GitHub Desktop.
Last GitLab commits
#!/bin/bash
dimstr="\e[2m"
bold="\e[1m"
normalstr="\e[0m"
green=$'\e[1;32m'
yellow=$'\e[1;33m'
cyn=$'\e[1;36m'
echo -e "${bold}BASH GitLab Commits :"
default_orga="default_orga"
default_project="default_project"
printcommits() {
for i in {1..5}
do
printf "%s" "${yellow}"
echo $commits | jq -rj --argjson index $i '.[$index] | .title'
printf "%s" "${green} ("
echo $commits | jq -rj --argjson index $i '.[$index] | .committer_name'
echo ")${cyn}"
echo $commits | jq --argjson index $i '.[$index] | .committed_date' | xargs date -d
echo -e ""
done
}
print_error() {
echo -e "${normalstr}${dimstr}Usage example : ./seecommits gitlab_token $default_orga $default_project"
}
if [ $# -eq 0 ]
then
print_error
elif [ "$#" = 1 ]
then
echo -e "${dimstr}$default_orga / $default_project\n"
commits=`curl -s --header "PRIVATE-TOKEN: $1" "https://gitlab.com/api/v4/projects/$default_orga%2F$default_project/repository/commits"` && printcommits
elif [ "$#" = 3 ]
then
echo -e "${dimstr}$2 / $3\n"
commits=`curl -s --header "PRIVATE-TOKEN: $1" "https://gitlab.com/api/v4/projects/$2%2F$3/repository/commits"` && printcommits
else
print_error
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment