-
Notifications
You must be signed in to change notification settings - Fork 16
/
redmine
executable file
·79 lines (59 loc) · 2.41 KB
/
redmine
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
# pylint: disable=raise-missing-from
import argparse
import os
try:
from redminelib import Redmine
from redminelib.exceptions import ValidationError
except ImportError:
raise SystemExit('Failed to require python-redmine')
VERSION_STATES = ('open', 'locked', 'closed')
def get_redmine() -> Redmine:
try:
api_key = os.environ['REDMINE_API_KEY']
except KeyError:
raise SystemExit('No REDMINE_API_KEY environment variable set')
return Redmine('https://projects.theforeman.org', key=api_key)
def create_version(args: argparse.Namespace) -> None:
redmine = get_redmine()
try:
redmine.version.create(
project_id=args.project_id,
name=args.name,
status=args.status,
sharing=args.sharing,
)
except ValidationError as ex:
raise SystemExit(str(ex))
def set_status_version(args: argparse.Namespace) -> None:
redmine = get_redmine()
versions = redmine.version.filter(project_id=args.project_id)
# Katello uses 'Katello x.y.z' instead of 'x.y.z'
matches = (args.name, f'{args.project_id.capitalize()} {args.name})')
try:
version = [version for version in versions if version.name in matches][0]
except IndexError:
raise SystemExit('Version not found')
print('Setting', args.name, 'to closed')
version.save(status=args.status)
def main():
parser = argparse.ArgumentParser()
resource = parser.add_subparsers(title='resource')
version = resource.add_parser(name='version')
version_action = version.add_subparsers(title='action')
version_create = version_action.add_parser('create')
version_create.add_argument('project_id')
version_create.add_argument('name')
version_create.add_argument('--status', default='open', choices=VERSION_STATES)
version_create.add_argument('--sharing', default='descendants',
choices=('none', 'descendants', 'hierachy', 'tree', 'system'))
version_create.set_defaults(func=create_version)
version_set_status = version_action.add_parser('set-status')
version_set_status.add_argument('project_id')
version_set_status.add_argument('name')
version_set_status.add_argument('status', default='closed', choices=VERSION_STATES)
version_set_status.set_defaults(func=set_status_version)
args = parser.parse_args()
args.func(args)
if __name__ == '__main__':
main()