Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to migrate attachments and set labels based on project name #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/github_issues/github_issue_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ def make_github_issue(self, redmine_json_fname, **kwargs):

include_comments = kwargs.get('include_comments', True)
include_assignee = kwargs.get('include_assignee', True)
include_attachments = kwargs.get('include_attachments', True)

json_str = open(redmine_json_fname, 'rU').read()
rd = json.loads(json_str) # The redmine issue as a python dict
Expand All @@ -321,14 +322,19 @@ def make_github_issue(self, redmine_json_fname, **kwargs):

author_name = rd.get('author', {}).get('name', None)
author_github_username = self.format_name_for_github(author_name)
attachments = []

if include_attachments:
attachments = rd.get('attachments')

desc_dict = {'description' : translate_for_github(rd.get('description', 'no description'))\
, 'redmine_link' : self.format_redmine_issue_link(rd.get('id'))\
, 'redmine_issue_num' : rd.get('id')\
, 'start_date' : rd.get('start_date', None)\
, 'author_name' : author_name\
, 'author_github_username' : author_github_username\
, 'redmine_assignee' : self.get_redmine_assignee_name(rd)
, 'redmine_assignee' : self.get_redmine_assignee_name(rd)\
, 'attachments' : attachments
}

description_info = template.render(desc_dict)
Expand Down Expand Up @@ -377,7 +383,7 @@ def make_github_issue(self, redmine_json_fname, **kwargs):
if include_comments:
journals = rd.get('journals', None)
if journals:
self.add_comments_for_issue(issue_obj.number, journals)
self.add_comments_for_issue(issue_obj.number, journals, attachments)


#
Expand Down Expand Up @@ -410,7 +416,7 @@ def is_redmine_issue_closed(self, redmine_issue_dict):



def add_comments_for_issue(self, issue_num, journals):
def add_comments_for_issue(self, issue_num, journals, attachments):
"""
Add comments
"""
Expand All @@ -427,11 +433,21 @@ def add_comments_for_issue(self, issue_num, journals):

author_name = j.get('user', {}).get('name', None)
author_github_username = self.format_name_for_github(author_name)
comment_attachments = []

# Find attachments that were added with this comment
for d in j.get('details'):
if d.get('property') == 'attachment':
attachment = next((x for x in attachments if str(x.get('id')) == d.get('name')), None)

if attachment is not None:
comment_attachments.append(attachment)

note_dict = { 'description' : translate_for_github(notes)\
, 'note_date' : j.get('created_on', None)\
, 'author_name' : author_name\
, 'author_github_username' : author_github_username\
, 'attachments' : comment_attachments\
}
comment_info = comment_template.render(note_dict)

Expand Down
5 changes: 5 additions & 0 deletions src/github_issues/label_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ def get_label_names(self, redmine_issue_dict, non_formatted=False):
if category_label_name:
label_names.append(category_label_name)

# Add project
project_label_name = self.get_label_from_id_name(redmine_issue_dict, 'project', 'Project:', non_formatted)
if project_label_name:
label_names.append(project_label_name)

# Add component
# "custom_fields": [
# {
Expand Down
3 changes: 3 additions & 0 deletions src/github_issues/migration_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self, redmine_json_directory, redmine2github_map_file, **kwargs):

self.include_comments = kwargs.get('include_comments', True)
self.include_assignee = kwargs.get('include_assignee', True)
self.include_attachments = kwargs.get('include_attachments', True)


self.user_mapping_filename = kwargs.get('user_mapping_filename', None)
Expand Down Expand Up @@ -196,6 +197,7 @@ def migrate_issues(self):
json_fname_fullpath = os.path.join(self.redmine_json_directory, json_fname)
gm_kwargs = { 'include_assignee' : self.include_assignee \
, 'include_comments' : self.include_comments \
, 'include_attachments' : self.include_attachments \
}
github_issue_number = gm.make_github_issue(json_fname_fullpath, **gm_kwargs)

Expand All @@ -215,6 +217,7 @@ def migrate_issues(self):
, redmine_issue_end_number=5000\
#, user_mapping_filename=USER_MAP_FILE # optional
, include_assignee=False # Optional. Assignee must be in the github repo and USER_MAP_FILE above
, include_attachments=True # optional
, label_mapping_filename=LABEL_MAP_FILE # optional
#, milestone_mapping_filename=MILESTONE_MAP_FILE # optional
)
Expand Down
7 changes: 7 additions & 0 deletions src/github_issues/templates/comment.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ Original Redmine Comment
---

{{ description }}

{% if attachments|length > 0 -%}
---
{% for attachment in attachments %}
- [{{ attachment.filename }}]({{ attachment.content_url }}) ({{ attachment.author.name }})
{%- endfor %}
{%- endif %}
8 changes: 6 additions & 2 deletions src/github_issues/templates/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@

{{ description }}



{% if attachments|length > 0 -%}
---
{% for attachment in attachments %}
- [{{ attachment.filename }}]({{ attachment.content_url }}) ({{ attachment.author.name }})
{%- endfor %}
{%- endif %}
2 changes: 1 addition & 1 deletion src/redmine_ticket/redmine_issue_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def get_single_issue(self, issue_id):
:returns: json string with issue information
"""
# test using .issue.get
issue = self.redmine_conn.issue.get(issue_id, include='children,journals,watchers,relations')
issue = self.redmine_conn.issue.get(issue_id, include='children,attachments,journals,watchers,relations')
json_str = json.dumps(issue._attributes, indent=4)
msg('Issue retrieved: %s' % issue_id)
return json_str
Expand Down