aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-04-19 01:33:11 +0200
committerTeddy Wing2018-04-19 01:40:35 +0200
commit28786a99da12474f5bdbfd89bc1f867714b69d91 (patch)
treee8d1fe48d0c3cb4944dc3a11bcdc3ed8eae66f49
parent3c451d5f504c9872e4b589c998d52479f38aabbc (diff)
downloadredprine-28786a99da12474f5bdbfd89bc1f867714b69d91.tar.bz2
Make the Redmine issue fields to update customisable
Add a new command line argument that accepts a Bash script string that will output the JSON wanted when making the request to update the Redmine issue. This allows the JSON to be customised to any fields the user wants to update instead of the ones I hard-coded. The param is a Bash-executable string to allow us to pass the pull request URL in to it for use in the JSON.
-rwxr-xr-xredprine32
1 files changed, 19 insertions, 13 deletions
diff --git a/redprine b/redprine
index 2c2d055..4299878 100755
--- a/redprine
+++ b/redprine
@@ -11,6 +11,7 @@ GITHUB_OWNER_REPO=''
REDMINE_BASE_URL=''
REDMINE_TOKEN=''
+REDMINE_JSON_PARAMS=''
XDG_DATA_HOME=${XDG_DATA_HOME:-"${HOME}/.local/share"}
REDPRINE_DATA_DIR=${REDPRINE_DATA_DIR:-"${XDG_DATA_HOME}/redprine"}
@@ -19,7 +20,7 @@ CACHE_FILE="${REDPRINE_DATA_DIR}/${GITHUB_OWNER_REPO/\//--}.json"
function print_usage () {
cat 1>&2 <<__EOF__
-Usage: redprine --github-token TOKEN --github-username USERNAME --github-owner-repo OWNER_REPO --redmine-base-url URL --redmine-token TOKEN
+Usage: redprine --github-token TOKEN --github-username USERNAME --github-owner-repo OWNER_REPO --redmine-base-url URL --redmine-token TOKEN --redmine-json-params EXEC
Flags:
--github-token=TOKEN GitHub API token with pull request access.
@@ -29,6 +30,9 @@ Flags:
--redmine-base-url=URL Base Redmine URL
(e.g. 'https://redmine.eaglejump.co').
--redmine-token=TOKEN Redmine account API key
+ --redmine-json-params=EXEC Bash-executable string that outputs JSON
+ as a parameter for updating issues.
+ Argument '\$0' is the pull request URL.
-h, --help Show this help.
-v, --version Show application version.
__EOF__
@@ -142,18 +146,7 @@ function update_redmine_status () {
cut -d ' ' -f 2 -
)
- # status_id=14 # Review
- # done_ratio=100
- # issue[custom_field_values][11] # Pull Request
- local json="{
- \"issue\": {
- \"status_id\": 14,
- \"done_ratio\": 100,
- \"custom_field_values\": {
- \"11\": \"$pull_request_link\"
- }
- }
- }"
+ local json=$(bash -c "$REDMINE_JSON_PARAMS" "$pull_request_link")
local status_code=$(
curl \
@@ -284,6 +277,18 @@ function parse_arguments () {
shift
continue
;;
+ --redmine-json-params)
+ REDMINE_JSON_PARAMS="$2"
+
+ shift 2
+ continue
+ ;;
+ --redmine-json-params=*)
+ REDMINE_JSON_PARAMS="${1##--redmine-json-params=}"
+
+ shift
+ continue
+ ;;
-h | --help)
print_usage
@@ -305,6 +310,7 @@ function parse_arguments () {
check_required_argument '--github-owner-repo' "$GITHUB_OWNER_REPO"
check_required_argument '--redmine-base-url' "$REDMINE_BASE_URL"
check_required_argument '--redmine-token' "$REDMINE_TOKEN"
+ check_required_argument '--redmine-json-params' "$REDMINE_JSON_PARAMS"
}