#60 Added support for custom fields and custom ticket type for repository
Merged by ralph. Opened by biakymet.
biakymet/sync-to-jira custom-fields-support  into  develop

Download 60.patch

Fixes: https://pagure.io/sync-to-jira/issue/57

@ralph please, review.

The string 'github' shouldn't appear anywhere in the downstream.py file. This function won't work for pagure repos as written.

Instead, you should probably focus implementation in intermediary.py, creating a new issuetype attribute that gets populated correctly from github or pagure and can be influenced by config like this.

rebased onto b93b76d638de85e6cc892ed137b00b2c5402d767

@ralph updated, please, review.

Try the following:

custom_fields = issue.downstream.get('custom_fields', [])
default_type = issue.downstream.get('type', "Bug")

This will avoid raising a KeyError if either type or custom_fields isn't present at all in issue.downstream.

Close @biakymet! I think one last change to avoid the KeyError and this will be good to merge.

Btw - definitely run the tests with tox which will catch things like this:

EE.........................
======================================================================
ERROR: test_create_jira_issue (tests.test_downstream.TestDownstream)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/threebean/devel/sync-to-jira/.tox/py35/lib/python3.5/site-packages/mock/mock.py", line 1305, in patched
    return func(*args, **keywargs)
  File "/home/threebean/devel/sync-to-jira/tests/test_downstream.py", line 100, in test_create_jira_issue
    result = d._create_jira_issue(jira.client.JIRA(), MockIssue(), config)
  File "/home/threebean/devel/sync-to-jira/sync2jira/downstream.py", line 170, in _create_jira_issue
    custom_fields = issue.downstream['custom_fields'] or []
KeyError: 'custom_fields'
-------------------- >> begin captured logging << --------------------
sync2jira.downstream: INFO:     Creating {'component': 'alsoawesome', 'project': 'awesome'} issue for <tests.test_downstream.TestDownstream.test_create_jira_issue.<locals>.MockIssue object at 0x7fe1074a89e8>
--------------------- >> end captured logging << ---------------------
======================================================================
ERROR: test_create_jira_issue_with_custom_url (tests.test_downstream.TestDownstream)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/threebean/devel/sync-to-jira/.tox/py35/lib/python3.5/site-packages/mock/mock.py", line 1305, in patched
    return func(*args, **keywargs)
  File "/home/threebean/devel/sync-to-jira/tests/test_downstream.py", line 129, in test_create_jira_issue_with_custom_url
    result = d._create_jira_issue(jira.client.JIRA(), MockIssue(), config)
  File "/home/threebean/devel/sync-to-jira/sync2jira/downstream.py", line 170, in _create_jira_issue
    custom_fields = issue.downstream['custom_fields'] or []
KeyError: 'custom_fields'
-------------------- >> begin captured logging << --------------------
sync2jira.downstream: INFO:     Creating {'component': 'alsoawesome', 'project': 'awesome'} issue for <tests.test_downstream.TestDownstream.test_create_jira_issue_with_custom_url.<locals>.MockIssue object at 0x7fe107476a58>
--------------------- >> end captured logging << ---------------------
----------------------------------------------------------------------
Ran 27 tests in 0.139s
FAILED (errors=2)
ERROR: InvocationError for command '/home/threebean/devel/sync-to-jira/.tox/py35/bin/nosetests' (exited with code 1)
flake8 installed: entrypoints==0.3,flake8==3.7.7,mccabe==0.6.1,pycodestyle==2.5.0,pyflakes==2.1.1,sync2jira==1.7
flake8 run-test-pre: PYTHONHASHSEED='146325912'
flake8 runtests: commands[0] | flake8 sync2jira/
sync2jira/downstream.py:175:78: E202 whitespace before ')'
ERROR: InvocationError for command '/home/threebean/devel/sync-to-jira/.tox/flake8/bin/flake8 sync2jira/' (exited with code 1)
____________________________________________________________________ summary _____________________________________________________________________
ERROR:   py27: commands failed
ERROR:   py35: commands failed
ERROR:   flake8: commands failed

rebased onto e26ede8fc740e46b58d65e24b74b816feb800010

@ralph done, please, review.

Ah, @biakymet - you gotta run tox locally. I think you'd see that there is code in the patch here that works on python2 but not on python3.

rebased onto 450149dbc5369f94061b024aede5c1537c9cc0cc

@ralph true, I just didn't have python3.5, only python3.7, but now installed and fixed it.

Thanks! :+1:

Pull-Request has been merged by ralph

Metadata