Skip to content

Instantly share code, notes, and snippets.

@MayamaTakeshi
Last active December 14, 2019 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MayamaTakeshi/68c3436a58c1d6ecb8558657a2d0da65 to your computer and use it in GitHub Desktop.
Save MayamaTakeshi/68c3436a58c1d6ecb8558657a2d0da65 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
redmine_url = 'YOUR_REDMINE_URL'
redmine_key = 'YOUR_REDMINE_KEY'
import sys
from redminelib import Redmine
from datetime import datetime, timedelta
def usage():
app = sys.argv[0]
print """
Usage: %s number_of_days old_status new_status
Ex: %s 30 'in progress' hold
""" % (app, app)
if len(sys.argv) != 4:
print "Invalid number of arguments"
usage()
sys.exit(1)
app, number_of_days, old_status, new_status = sys.argv
number_of_days=int(number_of_days)
old_status_lc = old_status.lower()
new_status_lc = new_status.lower()
redmine = Redmine(redmine_url, key = redmine_key)
statuses = redmine.issue_status.all()
new_status_id = None
old_status_id = None
for status in statuses:
#print status.name, status.id
status_name_lc = status.name.lower()
if status_name_lc == new_status_lc:
new_status_id = status.id
elif status_name_lc == old_status_lc:
old_status_id = status.id
if not old_status_id:
print "Invalid old_status '" + old_status + "'"
sys.exit(1)
if not old_status_id:
print "Invalid new_status '" + new_status + "'"
sys.exit(1)
now = datetime.now()
count = 0
for issue in redmine.issue.all():
if issue.status.id == old_status_id:
if issue.updated_on < now - timedelta(days=number_of_days):
print "Updating #%u (%s) status from '%s' to '%s'" %(issue.id, issue.subject, old_status, new_status)
issue.status_id = new_status_id
issue.notes = "Status automatically set to '%s'" % (new_status,)
issue.save()
count = count + 1
print "Finished (total updated: %u)" % (count,)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment