Skip to content

Instantly share code, notes, and snippets.

@mattijsf
Last active June 17, 2019 10:43
Show Gist options
  • Save mattijsf/cc8181eb98367f8288feef748bf8417a to your computer and use it in GitHub Desktop.
Save mattijsf/cc8181eb98367f8288feef748bf8417a to your computer and use it in GitHub Desktop.
Standup summary/reminder based on Git commits and YouTrack issues
#!/bin/bash
# Requirements:
# jq - installation: brew install jq
CONFIG_FILE=~/.standup
NOCOLOR='\033[0m'
YELLOW='\033[1;33m'
LIGHT_CYAN='\033[1;36m'
if [ ! -f $CONFIG_FILE ]; then
echo "Create config file: $CONFIG_FILE with the following content:
# To obtain a YouTrack token go to YouTrack > Profile > General > Update personal information and manager logins > Authentication
YOUTRACK_TOKEN="1234"
GIT_IGNORE_COMMIT_PATTERN=\"(Update RN submodule|Update react-native submodule)\"
GIT_DIRS=(
# Us folowing notation (entry per line):
# "REPO_NAME1" "REPO_DIR1"
# "REPO_NAME2" "REPO_DIR2"
)
"
exit 1
fi
. $CONFIG_FILE
function git-commits-since() {
SINCE=$1
REPO_NAME=$2
# --no-merges
RESULT=$(git log --all \
--date=format:'%H:%M' \
--committer=$(git config user.email) \
--pretty=format:"- ${YELLOW}$REPO_NAME${NOCOLOR}: %s" \
--since="$SINCE")
echo "$RESULT"
}
function git-standup-repo() {
REPO_NAME=$1
REPO_DIR=$2
cd $REPO_DIR
if [ `date +%w` == 1 ]; then
git-commits-since last.friday.midnight $REPO_NAME;
else
git-commits-since yesterday $REPO_NAME;
fi
}
function git-standup-repos {
for (( i=1; i<${#GIT_DIRS[@]}+1; i+=2 ));
do
REPO_NAME=${GIT_DIRS[$i-1]}
REPO_DIR=${GIT_DIRS[$i]}
git-standup-repo $REPO_NAME $REPO_DIR
done
}
function git-standup {
# awk removes duplicate commit messages if the same commit exists in multiple repo's
echo -e "$(git-standup-repos)" | awk '!seen[substr($0, index($0, ":"))]++' | awk 'NF' | grep -vwEi "$GIT_IGNORE_COMMIT_PATTERN"
}
function youtrack-issues() {
FILTER=$1
[ ! -z "$2" ] && FILTER_NAME=" (${LIGHT_CYAN}$2${NOCOLOR})" || FILTER_NAME=""
curl -G -sk 'https://innovactory.myjetbrains.com/youtrack/api/issues' \
--data-urlencode "query=$FILTER" \
--data-urlencode "fields=idReadable,summary" \
-H 'Accept: application/json' \
-H "Authorization: Bearer $YOUTRACK_TOKEN" \
-H 'Content-Type: application/json' \
-H 'Cache-Control: no-cache' | jq -rC '.[] | "- \(.idReadable): \(.summary)"' \
| perl -pe "s|- (\w+-\d+):|- ${YELLOW}\1${NOCOLOR}$FILTER_NAME:|"
}
function youtrack-standup() {
[ -z "$YOUTRACK_TOKEN" ] && return
YT_FILTER_RESOLVED="updated: {Last working day}, Today #{Assigned to me}, State: Resolved"
YT_FILTER_INPROGRESS="updated: {Last working day}, Today #{Assigned to me}, State: {In Progress}"
youtrack-issues "$YT_FILTER_RESOLVED" ""
youtrack-issues "$YT_FILTER_INPROGRESS" "IN PROGRESS"
}
git-standup
youtrack-standup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment