-
Notifications
You must be signed in to change notification settings - Fork 22
/
backlog-set-due-date
executable file
·38 lines (33 loc) · 1.51 KB
/
backlog-set-due-date
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh -e
# This script sets the due date on tickets in Redmine based on
# specified conditions
#
# If you want to run this for testing there are two options
# 1. Run the script without updating the tickets
# dry_run=1 ./backlog-set-due-date
#
# 2. Like #1 but also read the tickets from a file
# dry_run=1 ./backlog-set-due-date <issues-json-file>
dry_run="${dry_run:-"0"}"
query_id="${query_id:-230}"
ticket_limit="${ticket_limit:-200}"
host="${host:-"https://progress.opensuse.org"}"
status="${status:-"In Progress"}"
duration="${duration:-"14 days"}"
priority="${priority:-"Low"}"
issues=$(mktemp -t backlog-set-due-date-XXXX)
jquery=".issues | .[] | select(.priority.name!=\"$priority\" and .due_date==null and .assigned_to!=null and .status.name==\"$status\")"
if [ $# -eq 1 ] && [ -f "$1" ] && [ "$dry_run" = "1" ]; then
jq -r "$jquery" "$1" > "$issues"
else
redmine_api_key="${redmine_api_key:?"Need redmine API key"}"
curl -sS -H "X-Redmine-API-Key: $redmine_api_key" "$host/issues.json?query_id=$query_id&limit=$ticket_limit" | jq -r "$jquery" > "$issues"
fi
[ "$dry_run" = "1" ] && prefix="echo"
for id in $(jq .id "$issues"); do
due_date=$(date -d"+$duration" +%Y-%m-%d)
echo "Updating ticket $id, new due date setup to $due_date"
$prefix curl -v -H "X-Redmine-API-Key: $redmine_api_key" -H 'Content-Type: application/json' -X PUT \
-d "{\"issue\": {\"due_date\": \"$due_date\", \"notes\": \"Setting due date based on mean cycle time of SUSE QE Tools\"}}" \
"$host/issues/$id.json"
done