MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

  • Jira

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

   1 #!/usr/bin/python3
   2 """
   3 JIRA_USERS=alice,bob JIRA_URL=https://example.org JIRA_USER=userx JIRA_PASS=xxxxx python3 getWorklog.py 
   4 """
   5 import sys
   6 import os
   7 import requests
   8 import json
   9 #import utils
  10 
  11 URL_SESSION="/rest/auth/1/session"
  12 
  13 def loginJira(url,user,passw):
  14     sessionUrl = '%s%s'%(url,URL_SESSION)
  15     jsonRequest={'username':'','password':''}
  16     jsonRequest['username']=user
  17     jsonRequest['password']=passw
  18     response = requests.post(sessionUrl,json=jsonRequest)
  19     rsp = json.loads(response.text)
  20     return response.cookies
  21 
  22 def current_user(url,cookies):
  23     sessionUrl = '%s%s'%(url,URL_SESSION)
  24     response = requests.get(sessionUrl,cookies=cookies)
  25     return json.loads(response.text)
  26 
  27 def logout(url,cookies):
  28     sessionUrl = '%s%s'%(url,URL_SESSION)
  29     response = requests.delete(sessionUrl,cookies=cookies)
  30     return response.status_code
  31 
  32 def get_issue(url,cookies,issue):
  33     sessionUrl = '%s/rest/api/2/issue/%s'%(url,issue)
  34     print('Using %s'%(sessionUrl))
  35     response = requests.get(sessionUrl, cookies=cookies )
  36     rsp=json.loads(response.text)
  37     key = rsp['key']
  38     summary = rsp['fields']['summary']
  39     print('%s -> %s'%(key,summary))
  40 
  41 def get_assigned_issues(url,cookies,user):
  42     sessionUrl = '%s/rest/api/2/search?maxResults=1000&jql=assignee=%s'%(url,user)
  43     response = requests.get(sessionUrl, cookies=cookies )
  44     rsp=json.loads(response.text)
  45     for issue in rsp["issues"]:
  46         issue_key=issue["key"]
  47         issue_fields=issue["fields"]
  48         print("\nIssue: " + issue_key )
  49         print("Type: " + issue_fields["issuetype"]["name"] )
  50         print("Assignee: " + issue_fields["assignee"]["key"] )
  51         print("Labels: " + str(issue_fields["labels"]) )
  52         print("Project: " + issue_fields["project"]["key"] )
  53         print("Summary: %s"%( issue_fields["summary"].encode('latin1','ignore') )  )
  54         print("Status: " + issue_fields["status"]["name"] )
  55         get_issue_worklog(url,cookies, issue_key, str(issue_fields["labels"]))
  56 
  57 def get_worklog_per_user(url,cookies,user):
  58     sessionUrl = '%s/rest/api/2/search?maxResults=1000&jql=worklogAuthor=%s'%(url,user)
  59     response = requests.get(sessionUrl, cookies=cookies )
  60     rsp=json.loads(response.text)
  61 
  62     for issue in rsp["issues"]:
  63         issue_key=issue["key"]
  64         issue_fields=issue["fields"]
  65         labels=""
  66         for label in issue_fields["labels"]:
  67             labels = labels + " " + label
  68         issue_type = issue_fields["issuetype"]["name"]
  69         #issue_assignee = issue_fields["assignee"]["name"]#["emailAddress"]
  70         issue_project=issue_fields["project"]["key"]
  71         issue_summary=issue_fields["summary"].encode('latin1','ignore')
  72         issue_status=issue_fields["status"]["name"]
  73         print("\n%s %s %s %s %s %s"%(issue_project,issue_type,issue_key,labels,issue_summary,issue_status) )       
  74         #print("Assignee: " + issue_assignee )
  75         get_issue_worklog(url,cookies, issue_key,str(issue_fields["labels"]))
  76 
  77 def get_issue_worklog(url,cookies,issue,labels):
  78     sessionUrl = '%s/rest/api/2/issue/%s/worklog?maxResults=1000'%(url,issue)
  79     response = requests.get(sessionUrl, cookies=cookies )
  80     rsp=json.loads(response.text)
  81 
  82     for worklog in rsp["worklogs"]:
  83         author = worklog["author"]["emailAddress"]
  84         started = worklog["started"]
  85         timeSpent =  worklog["timeSpent"]
  86         print("  %s %s %s %s %s " %(author,started,issue,labels,timeSpent) )
  87 
  88 if __name__=='__main__':
  89     jiraUrl=os.environ['JIRA_URL'] 
  90     jiraUser=os.environ['JIRA_USER']
  91     jiraPass=os.environ['JIRA_PASS']
  92     jiraUsers=os.environ['JIRA_USERS']
  93 
  94     cookies=loginJira(jiraUrl, jiraUser, jiraPass )
  95     current_user(jiraUrl,cookies)
  96     splitted = jiraUsers.split(",")
  97     for user in splitted:
  98         get_worklog_per_user(jiraUrl,cookies,user)
  99     logout(jiraUrl,cookies)    

getWorklogApiToken.py

   1 #!/usr/bin/python3
   2 """
   3 Uses an API token generated using an Atlassian user account.
   4 JIRA_URL=https://xyz.atlassian.net JIRA_USER=user@example.org JIRA_API_TOKEN=xxx TEAM_USERS=Alice,Bob,Mallory python3 getWorklogApiToken.py
   5 """
   6 import sys
   7 import os
   8 import requests
   9 import json
  10 import base64
  11 
  12 def get_assigned_issues(url,authorization,user):
  13     headers={
  14         "Authorization":"Basic %s"%(authorization),
  15         "Content-Type":'application/json'
  16         }
  17     full_url = '%s/rest/api/2/search?maxResults=1000&jql=assignee=%s'%(url,user)
  18     response = requests.get(full_url,headers=headers)
  19     rsp=json.loads(response.text)
  20 
  21     for issue in rsp["issues"]:
  22         issue_key=issue["key"]
  23         issue_fields=issue["fields"]
  24         issue_type = issue_fields["issuetype"]["name"]
  25         issue_assignee = issue_fields["assignee"]["displayName"] 
  26         summary = str( issue_fields["summary"].encode('latin1','ignore')  , 'utf-8')
  27         status = issue_fields["status"]["name"]
  28         print("%8s - %32s - %48s"%(issue_key, status, summary[:48]))
  29 
  30 def get_worklog_per_user(url,authorization,user):
  31     headers={
  32         "Authorization":"Basic %s"%(authorization),
  33         "Content-Type":'application/json'
  34         }
  35     full_url = '%s/rest/api/2/search?maxResults=10000&jql=worklogAuthor=%s'%(url,user)
  36     response = requests.get(full_url,headers=headers)
  37     rsp=json.loads(response.text)
  38 
  39     for issue in rsp["issues"]:
  40         issue_key=issue["key"]
  41         issue_fields=issue["fields"]
  42         labels=""
  43         for label in issue_fields["labels"]:
  44             labels = labels + " " + label
  45         issue_type = issue_fields["issuetype"]["name"]
  46         issue_summary=str( issue_fields["summary"].encode('utf-8','ignore') , encoding='utf-8')
  47         issue_status=issue_fields["status"]["name"]
  48         print("\n%s %s %s %s %s"%(issue_type,issue_key,labels,issue_status,issue_summary[:32]) )       
  49         get_issue_worklog(url,authorization, issue_key,str(issue_fields["labels"]),user,issue_summary)
  50 
  51 def get_issue_worklog(url,authorization,issue,labels,user,issue_summary):
  52     headers={
  53         "Authorization":"Basic %s"%(authorization),
  54         "Content-Type":'application/json'
  55         }
  56     full_url = '%s/rest/api/2/issue/%s/worklog?maxResults=1000'%(url,issue)
  57     response = requests.get(full_url,headers=headers)
  58     rsp=json.loads(response.text)
  59 
  60     for worklog in rsp["worklogs"]:
  61         if worklog["author"]["accountId"]==user:
  62             author = user + " " + worklog["author"]["displayName"]
  63             started = worklog["started"]
  64             timeSpent =  worklog["timeSpent"]
  65             print("  %s %s %s %s %s" %(author, started[0:10] ,issue,labels, timeSpent) )
  66 
  67 def get_users(url,authorization,filter_users):
  68     headers={
  69         "Authorization":"Basic %s"%(authorization),
  70         "Content-Type":'application/json'
  71         }
  72     full_url = "%s/rest/api/2/users?maxResults=10000"%(url)
  73     reply = requests.get(full_url,headers=headers)
  74     users = json.loads(reply.text)
  75     res=[]
  76     for u in users:
  77         for fu in filter_users:
  78             if fu in u["displayName"]:
  79                 res.append({
  80                     'user':u["displayName"] , 
  81                     'accountId':u["accountId"] , 
  82                     'active': u["active"] 
  83                     })
  84     return res
  85 if __name__=='__main__':
  86     jiraUrl = os.environ['JIRA_URL'] 
  87     jiraUser = os.environ['JIRA_USER']
  88     jiraApiToken = os.environ['JIRA_API_TOKEN']
  89     team_users = os.environ['TEAM_USERS'].split(',')
  90 
  91     authorization = str(base64.b64encode(bytes("%s:%s"%(jiraUser,jiraApiToken),'utf-8')),'utf-8')
  92 
  93     users = get_users(jiraUrl,authorization,team_users)
  94     for user in users:
  95         print("\n\n### %s - %s ###"%(user["user"], user["accountId"]))
  96         get_assigned_issues(jiraUrl,authorization,user["accountId"])
  97         get_worklog_per_user(jiraUrl,authorization,user["accountId"])        
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01