11. Dirty hacks

11.1. Manipulacje na bazie

11.2. Django ORM

Django Inspect DB + Jira = Django ORM

11.3. Skryptowanie

11.4. Time tracking

11.5. Atlassian Python API

11.5.1. Reindex

Listing 11.1. Jira reindex
from pprint import pprint
from atlassian import Jira


jira = Jira(
    url="http://localhost:8000/",
    username="admin",
    password="admin")

status = jira.reindex().json()
pprint(status)

11.5.2. Project Administrators

Listing 11.2. Jira Project Administrators
import logging
from atlassian import Confluence
from atlassian import Jira


logging.basicConfig(level=logging.DEBUG, format="[%(asctime).19s] [%(levelname)s] %(message)s")
logging.getLogger("requests").setLevel(logging.WARNING)
log = logging.getLogger("jira-projects-administrators")


jira = Jira(
    url="http://localhost:8000/",
    username="admin",
    password="admin")

html = "<table><tr><th>Project Key</th><th>Project Name</th><th>Leader</th><th>Email</th></tr>"

for data in jira.project_leaders():
    log.info("{project_key} leader is {lead_name} <{lead_email}>".format(**data))
    html += "<tr><td>{project_key}</td><td>{project_name}<td></td>{lead_name}<td></td><a href='mailto:{lead_email}'>{lead_email}</a></td></tr>".format(**data)

html += "</table><p></p><p></p>"
html += "<p>Autogenerated with <a href='http://localhost:7999/projects/AGILE/repos/devops-utils-jira/browse/bin/jira-projects-administrators.py'>this script</a></p>"

confluence = Confluence(
    url="http://localhost:8090/",
    username="admin",
    password="admin")

confluence.update_page(
    page_id=13207798,
    parent_id=7471197,
    title="Administratorzy JIRA",
    body=html)

log.info("Confluence Page Created with JRIA Administrators at: http://localhost:8095/pages/viewpage.action?pageId=13207798")

11.6. Assignments

11.6.1. Atlassian Python API - Instalacja

  1. Zainstaluj bibliotekę Atlassian Python API atlassian-python-api

Note

Kod biblioteki dostępny jest na GitHub https://github.com/atlassian-api/atlassian-python-api

Warning

Wymagany Python 3.4 lub nowszy

11.6.2. Atlassian Python API - Reindeksacja

  1. Stwórz skrypt jira-reindex.py
  2. Skrypt wykorzystując bibliotekę atlassian-python-api ma reindeksować JIRĘ
  3. Skrypt jira-reindex.py dodaj Crontab by był uruchamiany o 4 w nocy
  4. Pamiętaj, że cron ma inne zmienne środowiskowe