1 # SPDX-License-Identifier: EPL-1.0
2 ##############################################################################
3 # Copyright (c) 2019 The Linux Foundation and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Eclipse Public License v1.0
7 # which accompanies this distribution, and is available at
8 # http://www.eclipse.org/legal/epl-v10.html
9 ##############################################################################
12 from __future__ import print_function
20 from lftools import config
22 log = logging.getLogger(__name__)
32 @click.command(name='get')
33 @click.argument('url')
34 @click.argument('endpoint')
36 def get_scheme(ctx, url, endpoint):
37 """Get request a jira end-point.
40 url = jira.example.com
49 userandpass = config.get_setting("jira", "base64")
50 url = ("https://{}/rest/api/2/{}").format(url, endpoint)
52 "Accept": "application/json",
53 "Content-Type": "application/json",
54 "Authorization": "Basic %s" % userandpass
56 response = requests.request(
61 log.info(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
64 @click.command(name='create-project')
65 @click.argument('notificationscheme')
66 @click.argument('description')
67 @click.argument('lead')
68 @click.argument('url')
69 @click.argument('projecttemplatekey')
70 @click.argument('longname')
71 @click.argument('shortkey')
72 @click.argument('projecturl')
74 def create_project(ctx, notificationscheme, description, lead, url, projecttemplatekey, longname, shortkey, projecturl):
75 """Create a JIRA project.
78 notificationscheme: 10000 is the global default
79 lead: lfid of the project lead. (lead must have previously signed in to jira)
81 projectTemplateKey: Valid values are one of the following
82 com.pyxis.greenhopper.jira:gh-scrum-template
83 com.pyxis.greenhopper.jira:gh-kanban-template
84 com.pyxis.greenhopper.jira:basic-software-development-template
85 longname: Long project name, please double quote.
86 shortkey: Ten character SHORTKEY must be capitalized
87 projecturl: Projects URL, probaly a link to their wiki.
89 TODO: do we need to add these as options?
90 issueSecurityScheme: 10001,
94 lftools jira create-project 10000 "example description" adminlfid jira.example.com com.pyxis.greenhopper.jira:gh-scrum-template "Example test project" EXAMPLE https://wiki.example.com/exampleproject
96 userandpass = config.get_setting("jira", "base64")
97 url = ("https://{}/rest/api/2/project/").format(url)
99 "Accept": "application/json",
100 "Content-Type": "application/json",
101 "Authorization": "Basic %s" % userandpass
104 payload = json.dumps({
105 "notificationScheme": "{}".format(notificationscheme), # 10000 make a default
106 "description": "{}".format(description),
107 "lead": "{}".format(lead),
108 "url": "{}".format(projecturl),
109 "projectTemplateKey": "{}".format(projecttemplatekey),
110 "name": "{}".format(longname), # 80 chars
111 "permissionScheme": 0, # this is default
112 "assigneeType": "PROJECT_LEAD",
113 "projectTypeKey": "software",
114 "key": "{}".format(shortkey), # 10 chars
118 response = requests.request(
125 log.info(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
128 @click.command(name='set-owner')
129 @click.argument('jiraurl')
130 @click.argument('currentgroup')
131 @click.argument('projectkey')
132 @click.argument('role')
134 def set_owner(ctx, jiraurl, currentgroup, projectkey, role):
135 """Set an ldap group as owner on a jira project. 1002 is the role for owner, 1001 is devloper.
138 Example: jira.example.com ldap-group-committers PROJECTSHORTKEY 1002
139 Rolls may be diffrent across jiras.
140 find admin role with lftools jira get-scheme jira.example.com role
142 userandpass = config.get_setting("jira", "base64")
143 url = ("https://{}/rest/api/2/project/{}/role/{}").format(jiraurl, projectkey, role)
146 "Accept": "application/json",
147 "Content-Type": "application/json",
148 "Authorization": "Basic %s" % userandpass
151 payload = json.dumps({
153 "{}".format(currentgroup)
156 response = requests.request(
163 log.info(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
166 jira.add_command(get_scheme)
167 jira.add_command(create_project)
168 jira.add_command(set_owner)