Skip to content

Commit

Permalink
Add progress clock - prep v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonk committed Oct 22, 2021
1 parent 9098836 commit 8b0c7e8
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 7 deletions.
13 changes: 9 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,29 @@ adheres to [Semantic Versioning][semver].

## [Unreleased]

## [v1.0.4] - 2021-10-22

- Add progress clock.

## [v1.0.3] - 2021-10-22

- Add a full dump of the payload when running with debugging.
- Make the headers work correctly with older versions of curl.

## [v1.0.2] - 2021-10-04

- Make it work correctly when you symlink to the `inform-slack` script
- Make it work correctly when you symlink to the `inform-slack` script.

## [v1.0.1] - 2021-10-04

- Fix some release process issues
- Fix some release process issues.

## [v1.0.0] - 2021-10-01

- First actual release
- First actual release.

[Unreleased]: https://github.com/jasonk/inform-slack/compare/v1.0.3...HEAD
[Unreleased]: https://github.com/jasonk/inform-slack/compare/v1.0.4...HEAD
[v1.0.4]: https://github.com/jasonk/inform-slack/releases/tag/v1.0.4
[v1.0.3]: https://github.com/jasonk/inform-slack/releases/tag/v1.0.3
[v1.0.2]: https://github.com/jasonk/inform-slack/releases/tag/v1.0.2
[v1.0.1]: https://github.com/jasonk/inform-slack/releases/tag/v1.0.1
Expand Down
2 changes: 1 addition & 1 deletion bin/inform-slack
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# https://github.com/jasonk/inform-slack

export INFORM_SLACK_VERSION="v1.0.3"
export INFORM_SLACK_VERSION="v1.0.4"

export INFORM_SLACK_SELF="$(realpath -P "${BASH_SOURCE[0]}")"
export INFORM_SLACK_DIR="$(cd -P "$(dirname "$INFORM_SLACK_SELF")/.." && pwd)"
Expand Down
12 changes: 10 additions & 2 deletions builders/thread-progress
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ title="${INFORM_SLACK_TITLE:-}"
status="${INFORM_SLACK_STATUS:-}"
max="${INFORM_SLACK_PROGRESS_MAX:-}"
pos="${INFORM_SLACK_PROGRESS_POS:-}"
clock="${INFORM_SLACK_PROGRESS_CLOCK:-}"

while (( $# )); do
case "$1" in
Expand All @@ -21,11 +22,18 @@ while (( $# )); do
--max=*) max="${1#*=}" ; shift 1 ;;
-P|--pos) pos="$2" ; shift 2 ;;
--pos=*) pos="${1#*=}" ; shift 1 ;;
--clock) clock="true" ; shift 1 ;;
*) usage "Unknown option '$1'" ;;
esac
done

text "${txt:-$title${status:+ - $status}}"
block-header "$title"
block-progress "$pos" "$max"

if [ -n "$clock" ]; then
block-header "$(draw-progress-clock) $title"
else
block-header "$title"
block-progress "$pos" "$max"
fi

block-mrkdwn "$status"
38 changes: 38 additions & 0 deletions lib/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,44 @@ draw-progress-bar() {
done
}

# Given a percentage complete, this picks the clock emoji that is
# closest to that percentage through a 12-hour cycle.
draw-progress-clock() {
local -i PCT="$1"

local CLOCKS=(
:clock1200:
:clock1230:
:clock100:
:clock130:
:clock200:
:clock230:
:clock300:
:clock330:
:clock400:
:clock430:
:clock500:
:clock530:
:clock600:
:clock630:
:clock700:
:clock730:
:clock800:
:clock830:
:clock900:
:clock930:
:clock1000:
:clock1030:
:clock1100:
:clock1130:
:clock1200:
)

local -i WIDE=24
local -i DONE=$(( WIDE * PCT / 100 ))
echo "${CLOCKS[$DONE]}"
}

# Emit a plain string message, properly quoted and escaped. This will
# be used as the 'text' value in a message
text() { jq -csR '.|gsub("^\\s+|\\s+$";"")' <<<"$1"; }
22 changes: 22 additions & 0 deletions test/progress.bats
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,26 @@ setup() { load "bats-setup.bash"; }
}'
}

@test "progress-clock" {
source inform-slack

run draw-progress-clock 0
assert_output ":clock1200:"

run draw-progress-clock 100
assert_output ":clock1200:"

run draw-progress-clock 99
assert_output ":clock1130:"

run draw-progress-clock 50
assert_output ":clock600:"

run draw-progress-clock 75
assert_output ":clock900:"

run draw-progress-clock 25
assert_output ":clock300:"
}

# vim:ft=bash

0 comments on commit 8b0c7e8

Please sign in to comment.