| |
@@ -627,9 +627,7 @@
|
| |
if 'title' in updates:
|
| |
# Update the title if needed
|
| |
if issue.title != existing.fields.summary:
|
| |
- data = {'summary': issue.title}
|
| |
- existing.update(data)
|
| |
- log.info(' Updated title')
|
| |
+ _update_title(issue, existing)
|
| |
|
| |
# Only synchronize transition (status) for listings that op-in
|
| |
if any('transition' in item for item in updates):
|
| |
@@ -703,6 +701,53 @@
|
| |
log.warning(' Could not update JIRA closed_status for %s' % issue.title)
|
| |
|
| |
|
| |
+ def _update_title(issue, existing):
|
| |
+ """
|
| |
+ Helper function to sync upstream/downstream title
|
| |
+ Args:
|
| |
+ issue (sync2jira.intermediary.Issue): Upstream issue
|
| |
+ existing (jira.resource.Issue): Existing JIRA issue
|
| |
+ Returns:
|
| |
+ Nothing
|
| |
+ """
|
| |
+ new_description = existing.fields.description
|
| |
+ if not new_description:
|
| |
+ new_description = ''
|
| |
+ if '] Upstream Reporter:' not in new_description:
|
| |
+ # We have to add the issue ID to the description so we can find it again
|
| |
+ if '] Upstream issue status:' in new_description:
|
| |
+ # We have to use regex to update the upstream reporter
|
| |
+ today = datetime.today()
|
| |
+ new_description = re.sub(
|
| |
+ r'\[[\w\W]*\] Upstream issue status: %s' % issue.status,
|
| |
+ '[%s] Upstream issue status: %s\n[%s] Upstream Reporter: %s'
|
| |
+ % (today.strftime("%a %b %y - %H:%M"),
|
| |
+ issue.status, issue.id, issue.reporter['fullname']),
|
| |
+ new_description)
|
| |
+ else:
|
| |
+ # We can just add it to the top
|
| |
+ new_description = '[%s] Upstream Repoter: %s' % \
|
| |
+ (issue.id, issue.reporter['fullname']) + new_description
|
| |
+ # Update the description
|
| |
+ # Now that we've updated the description (i.e. added
|
| |
+ # issue.id) we can delete the link in the description if its still there.
|
| |
+ new_description = re.sub(
|
| |
+ r'%s' % issue.url,
|
| |
+ r'',
|
| |
+ new_description
|
| |
+ )
|
| |
+
|
| |
+ # Now we can update the JIRA issue if we need to
|
| |
+ if new_description != existing.fields.description:
|
| |
+ data = {'description': new_description}
|
| |
+ existing.update(data)
|
| |
+ log.info(' Updated description')
|
| |
+ # Then we can update the title
|
| |
+ data = {'summary': issue.title}
|
| |
+ existing.update(data)
|
| |
+ log.info(' Updated title')
|
| |
+
|
| |
+
|
| |
def _update_comments(client, existing, issue):
|
| |
"""
|
| |
Helper function to sync comments between existing JIRA issue and upstream issue
|
| |
@@ -844,6 +889,8 @@
|
| |
|
| |
def _update_description(existing, issue):
|
| |
new_description = existing.fields.description
|
| |
+ if not new_description:
|
| |
+ new_description = ''
|
| |
if 'Upstream description' in new_description:
|
| |
# If we just need to update the content of the description
|
| |
new_description = re.sub(
|
| |
@@ -852,31 +899,32 @@
|
| |
new_description)
|
| |
elif '] Upstream issue status:' in new_description and '] Upstream Reporter:' in new_description:
|
| |
# We need to add a description field
|
| |
- # Need to find the 2nd new line as we already have
|
| |
- # Reporter and Status
|
| |
- index1 = new_description.find('\n')
|
| |
- index2 = new_description[index1+1:].find('\n')
|
| |
- new_description = "%s \nUpstream description: " \
|
| |
- "{quote}%s{quote}\n%s" % \
|
| |
- (new_description[:index1+index2+1],
|
| |
- issue.content,
|
| |
- new_description[index1+index2+1:])
|
| |
-
|
| |
- elif '] Upstream issue status:' in new_description:
|
| |
+ today = datetime.today()
|
| |
+ new_description = re.sub(r'\[[\w\W]*\] Upstream issue status: %s\n\[%s\] Upstream Reporter: %s' % (
|
| |
+ issue.status, issue.id, issue.reporter['fullname']),
|
| |
+ r'[%s] Upstream issue status: %s\n[%s] Upstream Reporter: %s\n'
|
| |
+ r'Upstream description: {quote}%s{quote}' % (
|
| |
+ today.strftime("%a %b %y - %H:%M"), issue.status, issue.id,
|
| |
+ issue.reporter['fullname'],
|
| |
+ issue.content),
|
| |
+ new_description)
|
| |
+
|
| |
+ elif '] Upstream issue status:' in new_description and '] Upstream Reporter:' not in new_description:
|
| |
# We need to add a upstream reporter and description field
|
| |
- upstream_reporter = '[%s] Upstream Reporter: %s' % (
|
| |
- issue.id,
|
| |
- issue.reporter['fullname']
|
| |
- )
|
| |
- upstream_description = "%s \nUpstream description: " \
|
| |
- "{quote}%s{quote}" % \
|
| |
- (upstream_reporter, issue.content)
|
| |
- # Add it to the old description
|
| |
- index = new_description.find('\n')
|
| |
- new_description = (new_description[:index] +
|
| |
- '\n' +
|
| |
- upstream_description +
|
| |
- new_description[index+1:])
|
| |
+ today = datetime.today()
|
| |
+ new_description = re.sub(r'\[[\w\W]*\] Upstream issue status: %s' % issue.status,
|
| |
+ r'[%s] Upstream issue status: %s\n'
|
| |
+ r'[%s] Upstream Reporter: %s\n'
|
| |
+ r'Upstream description: {quote}%s{quote}' %
|
| |
+ (today.strftime("%a %b %y - %H:%M"), issue.status, issue.id,
|
| |
+ issue.reporter['fullname'], issue.content),
|
| |
+ new_description)
|
| |
+ elif '] Upstream issue status:' not in new_description and '] Upstream Reporter:' in new_description:
|
| |
+ # We need to just add the description field
|
| |
+ new_description = re.sub(
|
| |
+ r'\[%s\] Upstream Reporter: %s [\w\W]*' % (issue.id, issue.reporter['fullname']),
|
| |
+ r'[%s] Upstream Reporter: %s \nUpstream description: {quote} %s {quote}' %
|
| |
+ (issue.id, issue.reporter['fullname'], issue.content), new_description)
|
| |
else:
|
| |
# Just add reporter and description to the top
|
| |
upstream_reporter = '[%s] Upstream Reporter: %s' % (
|
| |
@@ -891,7 +939,7 @@
|
| |
# Now that we've updated the description (i.e. added
|
| |
# issue.id) we can delete the link in the description if its still there.
|
| |
new_description = re.sub(
|
| |
- r'\[%s\]' % issue.url,
|
| |
+ r'%s' % issue.url,
|
| |
r'',
|
| |
new_description
|
| |
)
|
| |
Updated description matching to be all regex