ATLAS Offline Software
jira_issues.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 # @file PyUtils.scripts.jira
4 # @purpose Interface with CERN JIRA instance
5 # @author Edward Moyse
6 # @date July 2016
7 
8 from __future__ import print_function
9 
10 __doc__ = "Interface with CERN JIRA instance."
11 __author__ = "Edward Moyse"
12 
13 # Tried to use jira module, but apparently doesn't support cookie-based authenticatoon.
14 
15 # pip install --user requests
16 import requests
17 import PyUtils.acmdlib as acmdlib
18 
19 
20 
21 def queryJira(querystring, cookies):
22  # Now, let's make this request!
23  base_url = "https://its.cern.ch/jira/rest/api/2/"
24  url = base_url+querystring
25 
26  r = requests.get(url, cookies=cookies)
27  if r.status_code != 200:
28  if r.status_code == 401:
29  print ('Authorisation has failed. Have you got a valid SSO cookie? If not, re-run "cern-get-sso-cookie -u https://its.cern.ch/jira/loginCern.jsp -o jira.txt" ')
30  else:
31  print ("Something has gone wrong! The response is: ", r.text)
32  return
33 
34  import json
35  response = json.loads(r.text)
36  return response
37 
38 @acmdlib.command(name='jira.issues')
39 @acmdlib.argument('-c', '--cookies',
40  required=False,
41  default = 'jira.txt',
42  help='the CERN SSO cookies file')
43 @acmdlib.argument('-r', '--release',
44  required=False,
45  help='Limit the response to the specified release')
46 @acmdlib.argument('-m', '--myissues',
47  action='store_true',
48  default=True,
49  required=False,
50  help='Limit the response your own issues')
51 @acmdlib.argument('-q', '--query',
52  required=False,
53  help='Use the specified query string i.e. "search?jql=assignee=currentUser()+and+resolution=Unresolved"')
54 @acmdlib.argument('-s', '--status',
55  required=False,
56  help='Limit the search to issues with this status, e.g. "Open"')
57 
58 def main(args):
59  """Interface to the CERN JIRA instance"""
60 
61  #authentication
62  try:
63  cookiesFile = open(args.cookies, 'r')
64  cookies = {}
65  for line in cookiesFile:
66  text = line.split()
67  if 'JSESSIONID' in line:
68  cookies['JSESSIONID'] = text[-1]
69  if 'atlassian.xsrf.token' in line:
70  cookies['atlassian.xsrf.token'] = text[-1]
71  except Exception:
72  print ("Problems opening cookie file at ", args.cookies)
73  return 1
74 
75  querystring = ""
76  if (args.query):
77  print ("Will use the following search string: ",args.query)
78  querystring = args.query
79  else:
80  querystring = "search?jql=resolution=Unresolved"
81  if (args.myissues):
82  querystring += "+AND+assignee=currentUser()"
83  if (args.release):
84  querystring += "+AND+affectedVersion="+args.release
85  if (args.status):
86  querystring += "+AND+status="+args.status
87 
88  response = queryJira(querystring, cookies)
89  if not response:
90  return 1
91 
92  # Now lets get some information out
93  issues = response['issues']
94  print()
95  print ('Key'.ljust(20), 'Summary'.ljust(20))
96  print ('---'.ljust(20), '-------'.ljust(20))
97  for issue in issues:
98  print (issue['key'].ljust(20), issue['fields']['summary'].ljust(20))
99  return
100 
101 
102 
python.scripts.jira_issues.queryJira
def queryJira(querystring, cookies)
functions --------------------------------------------------------------—
Definition: jira_issues.py:21
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
python.scripts.jira_issues.main
def main(args)
Definition: jira_issues.py:58
Trk::open
@ open
Definition: BinningType.h:40