= Jira = * https://confluence.atlassian.com/jira == Jira and Confluence Markup == {{{ h1. Biggest heading h3. Big heading h5. Small heading - some - bullet - points * some * bullet ** indented ** bullets * points # a # numbered # list ||heading 1||heading 2||heading 3|| |cell A1|cell A2|cell A3| |cell B1|cell B2|cell B3| *bold text* _italics_ [title | http://confluence.atlassian.com] !screenshot-1.png! !screenshot-2.png|thumbnail! }}} == JQL (Jira Query Language) == * https://support.atlassian.com/jira-core-cloud/docs/use-advanced-search-with-jira-query-language-jql/ * Sum time spent {{{ (assignee = bob OR assignee = alice) AND (type = "Issue" OR type = Epic) ORDER BY issuetype DESC labels in (Labelxyz) }}} * https://example.org/rest/api/2/search?jql=assignee=bob&maxResults=1000 * https://example.org/rest/api/2/search?jql=worklogAuthor=bob == getWorklog.py == {{{#!highlight python #!/usr/bin/python3 """ JIRA_USERS=alice,bob JIRA_URL=https://example.org JIRA_USER=userx JIRA_PASS=xxxxx python3 getWorklog.py """ import sys import os import requests import json #import utils URL_SESSION="/rest/auth/1/session" def loginJira(url,user,passw): sessionUrl = '%s%s'%(url,URL_SESSION) jsonRequest={'username':'','password':''} jsonRequest['username']=user jsonRequest['password']=passw response = requests.post(sessionUrl,json=jsonRequest) rsp = json.loads(response.text) return response.cookies def current_user(url,cookies): sessionUrl = '%s%s'%(url,URL_SESSION) response = requests.get(sessionUrl,cookies=cookies) return json.loads(response.text) def logout(url,cookies): sessionUrl = '%s%s'%(url,URL_SESSION) response = requests.delete(sessionUrl,cookies=cookies) return response.status_code def get_issue(url,cookies,issue): sessionUrl = '%s/rest/api/2/issue/%s'%(url,issue) print('Using %s'%(sessionUrl)) response = requests.get(sessionUrl, cookies=cookies ) rsp=json.loads(response.text) key = rsp['key'] summary = rsp['fields']['summary'] print('%s -> %s'%(key,summary)) def get_assigned_issues(url,cookies,user): sessionUrl = '%s/rest/api/2/search?maxResults=1000&jql=assignee=%s'%(url,user) response = requests.get(sessionUrl, cookies=cookies ) rsp=json.loads(response.text) for issue in rsp["issues"]: issue_key=issue["key"] issue_fields=issue["fields"] print("\nIssue: " + issue_key ) print("Type: " + issue_fields["issuetype"]["name"] ) print("Assignee: " + issue_fields["assignee"]["key"] ) print("Labels: " + str(issue_fields["labels"]) ) print("Project: " + issue_fields["project"]["key"] ) print("Summary: %s"%( issue_fields["summary"].encode('latin1','ignore') ) ) print("Status: " + issue_fields["status"]["name"] ) get_issue_worklog(url,cookies, issue_key, str(issue_fields["labels"])) def get_worklog_per_user(url,cookies,user): sessionUrl = '%s/rest/api/2/search?maxResults=1000&jql=worklogAuthor=%s'%(url,user) response = requests.get(sessionUrl, cookies=cookies ) rsp=json.loads(response.text) for issue in rsp["issues"]: issue_key=issue["key"] issue_fields=issue["fields"] labels="" for label in issue_fields["labels"]: labels = labels + " " + label issue_type = issue_fields["issuetype"]["name"] #issue_assignee = issue_fields["assignee"]["name"]#["emailAddress"] issue_project=issue_fields["project"]["key"] issue_summary=issue_fields["summary"].encode('latin1','ignore') issue_status=issue_fields["status"]["name"] print("\n%s %s %s %s %s %s"%(issue_project,issue_type,issue_key,labels,issue_summary,issue_status) ) #print("Assignee: " + issue_assignee ) get_issue_worklog(url,cookies, issue_key,str(issue_fields["labels"])) def get_issue_worklog(url,cookies,issue,labels): sessionUrl = '%s/rest/api/2/issue/%s/worklog?maxResults=1000'%(url,issue) response = requests.get(sessionUrl, cookies=cookies ) rsp=json.loads(response.text) for worklog in rsp["worklogs"]: author = worklog["author"]["emailAddress"] started = worklog["started"] timeSpent = worklog["timeSpent"] print(" %s %s %s %s %s " %(author,started,issue,labels,timeSpent) ) if __name__=='__main__': jiraUrl=os.environ['JIRA_URL'] jiraUser=os.environ['JIRA_USER'] jiraPass=os.environ['JIRA_PASS'] jiraUsers=os.environ['JIRA_USERS'] cookies=loginJira(jiraUrl, jiraUser, jiraPass ) current_user(jiraUrl,cookies) splitted = jiraUsers.split(",") for user in splitted: get_worklog_per_user(jiraUrl,cookies,user) logout(jiraUrl,cookies) }}} == getWorklogApiToken.py == {{{#!highlight python #!/usr/bin/python3 """ Uses an API token generated using an Atlassian user account. JIRA_URL=https://xyz.atlassian.net JIRA_USER=user@example.org JIRA_API_TOKEN=xxx TEAM_USERS=Alice,Bob,Mallory python3 getWorklogApiToken.py """ import sys import os import requests import json import base64 def get_assigned_issues(url,authorization,user): headers={ "Authorization":"Basic %s"%(authorization), "Content-Type":'application/json' } full_url = '%s/rest/api/2/search?maxResults=1000&jql=assignee=%s'%(url,user) response = requests.get(full_url,headers=headers) rsp=json.loads(response.text) for issue in rsp["issues"]: issue_key=issue["key"] issue_fields=issue["fields"] issue_type = issue_fields["issuetype"]["name"] issue_assignee = issue_fields["assignee"]["displayName"] summary = str( issue_fields["summary"].encode('latin1','ignore') , 'utf-8') status = issue_fields["status"]["name"] print("%8s - %32s - %48s"%(issue_key, status, summary[:48])) def get_worklog_per_user(url,authorization,user): headers={ "Authorization":"Basic %s"%(authorization), "Content-Type":'application/json' } full_url = '%s/rest/api/2/search?maxResults=10000&jql=worklogAuthor=%s'%(url,user) response = requests.get(full_url,headers=headers) rsp=json.loads(response.text) for issue in rsp["issues"]: issue_key=issue["key"] issue_fields=issue["fields"] labels="" for label in issue_fields["labels"]: labels = labels + " " + label issue_type = issue_fields["issuetype"]["name"] issue_summary=str( issue_fields["summary"].encode('utf-8','ignore') , encoding='utf-8') issue_status=issue_fields["status"]["name"] print("\n%s %s %s %s %s"%(issue_type,issue_key,labels,issue_status,issue_summary[:32]) ) get_issue_worklog(url,authorization, issue_key,str(issue_fields["labels"]),user,issue_summary) def get_issue_worklog(url,authorization,issue,labels,user,issue_summary): headers={ "Authorization":"Basic %s"%(authorization), "Content-Type":'application/json' } full_url = '%s/rest/api/2/issue/%s/worklog?maxResults=1000'%(url,issue) response = requests.get(full_url,headers=headers) rsp=json.loads(response.text) for worklog in rsp["worklogs"]: if worklog["author"]["accountId"]==user: author = user + " " + worklog["author"]["displayName"] started = worklog["started"] timeSpent = worklog["timeSpent"] print(" %s %s %s %s %s" %(author, started[0:10] ,issue,labels, timeSpent) ) def get_users(url,authorization,filter_users): headers={ "Authorization":"Basic %s"%(authorization), "Content-Type":'application/json' } full_url = "%s/rest/api/2/users?maxResults=10000"%(url) reply = requests.get(full_url,headers=headers) users = json.loads(reply.text) res=[] for u in users: for fu in filter_users: if fu in u["displayName"]: res.append({ 'user':u["displayName"] , 'accountId':u["accountId"] , 'active': u["active"] }) return res if __name__=='__main__': jiraUrl = os.environ['JIRA_URL'] jiraUser = os.environ['JIRA_USER'] jiraApiToken = os.environ['JIRA_API_TOKEN'] team_users = os.environ['TEAM_USERS'].split(',') authorization = str(base64.b64encode(bytes("%s:%s"%(jiraUser,jiraApiToken),'utf-8')),'utf-8') users = get_users(jiraUrl,authorization,team_users) for user in users: print("\n\n### %s - %s ###"%(user["user"], user["accountId"])) get_assigned_issues(jiraUrl,authorization,user["accountId"]) get_worklog_per_user(jiraUrl,authorization,user["accountId"]) }}}