Giter Site home page Giter Site logo

ask-jira's Introduction

ask-jira

Python app that uses the JIRA API for automated tasks and aggregate or complex reports that are not possible with filters or gadgets in JIRA web UI.

Features:

  • export_import_issues_for_jql: export issues from one JIRA instance to another with comments and attachments (see Export/import below)

  • list_epics_stories_and_tasks_for_jql: print a Markdown-compatible tree of epics, stories and subtasks that match the given JQL query

  • projects: List available JIRA projects (mainly for testing)

  • fields: List available JIRA field names and IDs

  • sum_timetracking_for_jql: Sum original estimate, time spent and time remaining for all issues that match the given JQL query

  • import_worklogs_from_google_calendar: Import worklog entries from Google Calendar to corresponding JIRA tasks

Installation

git clone https://github.com/mrts/ask-jira.git

cd ask-jira

python -m venv venv
. venv/scripts/activate # when using Git BASH from Git for Windows
# . venv/bin/activate # in non-Windows environments
pip install --requirement=requirements.txt

cp jiraconfig-sample.py jiraconfig.py

# edit jiraconfig.py

./ask-jira.py projects # for testing, will print available projects

JIRA server configuration is picked up from jiraconfig.py.

Usage

Run the command with

$ ./ask-jira.py <command> <command-specific parameters>

Here's the default help:

$ ./ask-jira.py
usage: ask-jira.py [-h] command

positional arguments:
 command   the command to run, available commands:
           'export_import_issues_for_jql': Export issues from one JIRA instance
             to another with comments and attachments
           'fields': List available JIRA field names and IDs
           'import_worklogs_from_google_calendar': Import worklog entries from Google Calendar
             to corresponding JIRA tasks
           'list_epics_stories_and_tasks_for_jql': Print a Markdown-compatible tree of epics,
             stories and subtasks that match the given JQL query
           'projects': List available JIRA projects
           'sum_timetracking_for_jql': Sum original estimate, time spent
             and time remaining for all issues that match the given JQL query
           'transitions': List available JIRA transitions for the given issue

optional arguments:
  -h, --help  show this help message and exit

Examples

# current sprint velocity
./ask-jira.py sum_timetracking_for_jql 'project = PROJ and sprint in openSprints() and status = Closed'

./ask-jira.py list_epics_stories_and_tasks_for_jql 'project = PROJ and type = Epic'

Export/import

The export_import_issues_for_jql task exports issues from one JIRA instance to another with comments, attachments, epics and sub-tasks.

Source JIRA server configuration is picked up from jiraconfig.py.

There is special support for "portfolio epics", a SAFe concept. Run export_import_issues_for_jql with the --portfolio-epics flag to enable portfolio epic mode. In portfolio epic mode, the argument JQL must return only top-level portfolio epics and all the linked issues are recursively migrated along with them. See also configuration settings with PORTFOLIO_EPIC prefix below.

The task needs special configuration in exportimportconfig.py (see sample in exportimportconfig-sample.py):

  • JIRA: the target JIRA server configuration where the issues are exported to
  • PRIORITY_MAP: map source JIRA priorities to target priorities, e.g. 'Major': 'Medium'
  • DEFAULT_PRIORITY: if source JIRA priority is not found in PRIORITY_MAP use this priority (optional)
  • ISSUETYPE_MAP: map source JIRA issue types to target issue types, e.g. 'New Feature': 'Story'
  • DEFAULT_ISSUETYPE: if source JIRA issue type is not found in ISSUETYPE_MAP use this issue type (optional)
  • ASSIGNEE_MAP: map source JIRA assignees to target assignees
  • DEFAULT_ASSIGNEE: if source JIRA issue type is not found in ASSIGNEE_MAP use this issue type (optional)
  • REPORTER_MAP: map source JIRA reporters to target reporters (usually identical to ASSIGNEE_MAP)
  • DEFAULT_REPORTER: if source JIRA issue type is not found in REPORTER_MAP use this issue type (optional)
  • SOURCE_EPIC_LINK_FIELD_ID: ID of the epic field in source JIRA, find it by calling fields, look for Epic Link
  • SOURCE_EPIC_NAME_FIELD_ID: ID of the epic field in source JIRA, find it by calling fields, look for Epic Name
  • TARGET_EPIC_NAME_FIELD_ID: ID of the epic field in target JIRA, find it by changing configuration to use target JIRA and calling fields, look for Epic Name
  • PORTFOLIO_EPIC_LABEL: (porfolio epic mode) for an issue to be considered a porfolio epic, this label must be attached to it
  • PORTFOLIO_EPIC_SUB_EPIC_SOURCE_LINK_NAME: (porfolio epic mode) only issues that are linked to the portfolio epic with this link name are migrated
  • PORTFOLIO_EPIC_SUB_EPIC_TARGET_LINK_NAME: (porfolio epic mode) the link name to use in target JIRA to link issues to portfolio epics
  • STATUS_TRANSITIONS: map of source JIRA statuses to list of workflow transition names in target JIRA that result in equivalent status, None for no transition
  • STATUS_TRANSITIONS_ISSUETYPE: issuetype specific map of source JIRA statuses to list of workflow transition names in target JIRA that result in equivalent status, None for no transition. If an issuetype is not in this list, the default STATUS_TRANSITIONS are used.
  • RESOLUTION_MAP: map source JIRA resolutions to target resolutions, only used when a WithResolution transition is used in STATUS_TRANSITIONS
  • CUSTOM_FIELD_FOR_SOURCE_JIRA_ISSUE_KEY: custom field in target JIRA for saving the source JIRA issue key, specifying this avoids duplicate imports, can be None
  • INCLUDE_WORKLOGS: if True, add worklogs from source JIRA issue to the new issue in target JIRA
  • ADD_COMMENT_TO_OLD_ISSUE: if True, add comment to source JIRA issue that it was exported to new issue in target JIRA with issue link
  • CUSTOM_FIELD: a single custom field that you can set to a default value for all issues (set to None if not needed)
  • CUSTOM_FIELD_MAP: map source JIRA fields to target JIRA fields. This can also be used for system fields that are not mapped out of the box, such as 'environment'

Note that epics and sub-tasks should be excluded from the source JIRA query as they are automatically imported via the parent task. The recommended snippet to add to the query is:

AND issuetype not in subTaskIssueTypes() AND issuetype != Epic

Full example:

./ask-jira.py export_import_issues_for_jql 'project = PROJ
    AND status not in (Closed, Done, Fixed, Resolved)
    AND issuetype not in subTaskIssueTypes()
    AND issuetype != Epic'

Importing worklogs from Google Calendar

The import_worklogs_from_google_calendar task helps filling JIRA time reports from Google Calendar events. The Google Calendar events must be formatted according to JIRA-ID: comment convention, where JIRA-ID is the JIRA issue ID and comment is the comment to add to the worklog. The comment is optional. The script finds the corresponding JIRA issue by ID and adds a worklog with the event duration to it.

It needs special configuration in worklogconfig.py (see sample in worklogconfig-sample.py, you probably need to change the Google Calendar timezone in TIMEZONE and can keep the rest as-is).

You also need to setup API access to Google Calendar in Google Developers Console as explained here. Be sure to download the OAuth client secret as instructed and save it to ~/.credentials/client_secret.json.

Usage

Usage:

./ask-jira.py import_worklogs_from_google_calendar -h
usage: ask-jira.py [-h] command calendar fromdate todate

positional arguments:
  command     import_worklogs_from_google_calendar
  calendar    the calendar name to import worklogs from
  fromdate    import date range start, in yyyy-mm-dd format
  todate      import date range end, in yyyy-mm-dd format

Full example:

./ask-jira.py import_worklogs_from_google_calendar 'Timereport' 2017-02-23 2017-02-24

ask-jira's People

Contributors

mrts avatar nikolabintev avatar tjaehnel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ask-jira's Issues

Document README.md corrections

Thanks for the ask-jira.
Their seems an typo error in readme Export/import.

in exportimportconfig.py
JIRA: As per code working this is a Target server configuration, but currently mentioned as Source

also please add a detail saying, Source Server Configuration will be picked from jiraconfig.py

Thanks & Regards,
KK

Ability to set a default user for moving tickets

I have the problem that our JIRA is very old and we need to move historical tickets, so we would like to be able to set a default assignee for the user when there is not one in the list. Since this causes the job to abort

AttributeError: type object 'PropertyHolder' has no attribute 'comment'

Very new to Jira & this library. And similarly a beginner in python.
I am trying a basic search.

issues = jira.search_issues(cfg.EpicSearch,maxResults=10000)
print(issues)
print (issues[5])
print (issues[5].fields.comment)

And getting the above error. Python version is 3.6.5 on windows10

Replicate custom fields

Hi,

I have been trying to replicate custom fields but could not achieve it.
I was thinking of something like CUSTOM_FIELD = ('customfield_10300', {'value': 'customfield_12345'}). Is it implemented ?
If not, do you know a way to do it (I guess it is quite easily feasible in code) ?

Thanks, Antoine

Issue with attachment transfer

Hello,

I'm using this tool since years now and it was always very helpful! ๐Ÿ˜ƒ

Unfortunately I wanted to run use it again today and had below issue with attachment transfer:
image

I have also tested this with the lasted master version and same picture there. If I "comment out" _add_attachments() then all works. Any ideas what the reason could be?

Regards,
Martin

leadUserName is empty

Hi,

We have started using it to migrate information between JIRA instances and we think it is great!!!
But when using
def component(self, id):

All attributes are ok, except leadUserName which is always None.

Just for your information, I have seen JIRA REST API returns component lead information not as a simple field but as an structure...
[{"self":"https://jirainstance.dddd.com/rest/api/2/component/14223","id":"14223","name":"OKxxxxxxxxxxxxxx","description":"xxxxxxxxxxxxxxx ","lead":{"self":"https://jirainstance.dddd.com/rest/api/2/user?username=ASSDDD","key":"assddd","name":"ASSDDD","avatarUrls":{"16x16":" ...avatarId=10111"},"displayName":"User name","active":true},"assigneeType":"...

Please, could you check it?

Thank you in advnace.

Attribute error

Hi,

running ask-jira.py throw me AttributeError

(venv) user@deb82:~/ask-jira$ ./ask-jira.py projects
Traceback (most recent call last):
  File "./ask-jira.py", line 111, in <module>
    _main()
  File "./ask-jira.py", line 66, in _main
    argparser = _make_main_argument_parser()
  File "./ask-jira.py", line 78, in _make_main_argument_parser
    "commands:\n{0}".format(_list_local_commands()))
  File "./ask-jira.py", line 98, in _list_local_commands
    sorted_globals.sort()
AttributeError: 'dict_items' object has no attribute 'sort'

Do you know how to fix this?

Kalle

Error:- AttributeError: type object 'PropertyHolder' has no attribute 'labels'

Hello,
I am facing below error while running 'export_import_issues_for_jql'.
Could you please help me how we can resolve this issue?

D:\jira-python\ask-jira>python ./ask-jira.py export_import_issues_for_jql "project = TMOVE AND issuetype not in subTaskIssueType
) AND issuetype != Epic ORDER BY key ASC"
About to export/import 50 issues
Exporting TMOVE-134 Traceback (most recent call last):
File "./ask-jira.py", line 133, in
_main()
File "./ask-jira.py", line 90, in _main
command(jira, args)
File "./ask-jira.py", line 59, in export_import_issues_for_jql
exportimportconfig, args.jql)
File "D:\jira-python\ask-jira\lib\export_import.py", line 15, in export_import_issues
_make_new_issues(source_jira, target_jira, issues, conf, result, None)
File "D:\jira-python\ask-jira\lib\export_import.py", line 24, in _make_new_issues
fields = _get_new_issue_fields(issue.fields, conf)
File "D:\jira-python\ask-jira\lib\export_import.py", line 66, in _get_new_issue_fields
value = getattr(fields, name)
AttributeError: type object 'PropertyHolder' has no attribute 'labels'

===============================================================

Thanks,
Sahidul

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.