Skip to content
This repository has been archived by the owner on Aug 24, 2021. It is now read-only.

Commit

Permalink
[#3] issues/copy: specify target repo based on mapping (#8)
Browse files Browse the repository at this point in the history
* ctrl/issues: allow dynamic destination repository

* conn/github: compare with NotSet object instead of None

* eg/issues/copy: add example CSV
  • Loading branch information
Skaty authored Apr 5, 2018
1 parent 0a45cf2 commit 17fedd5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion connectors/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def create_issue(self, title, msg, assignee, labels=[], repo=None):
return True
except GithubException as e:
GitHubConnector.log_exception(e.data)
if assignee is None:
if assignee is GithubObject.NotSet:
return False
else:
# try without assignee
Expand Down
16 changes: 12 additions & 4 deletions controllers/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def copy_issues(self, mapping_file, fromrepo, torepo, offset):
mapping_dict = parsers.csvparser.get_rows_as_dict(mapping_file) if mapping_file is not None else {}
REF_TEMPLATE = '\n\n<sub>[original: {}#{}]</sub>'

if torepo.count('{}') > 1:
logging.error('torepo contains more than 1 replacement field!')
sys.exit(1)

if not offset:
offset = 0

Expand All @@ -79,13 +83,17 @@ def copy_issues(self, mapping_file, fromrepo, torepo, offset):

if from_mapping:
from_mapping = from_mapping.group(1)
print(from_mapping)
to_mapping = mapping_dict.get(from_mapping, from_mapping)
to_mapping = mapping_dict.get(from_mapping, [])

try:
actl_to_repo = torepo.format(to_mapping[0])
except IndexError:
actl_to_repo = torepo.format('')

is_transferred = self.ghc.create_issue(new_title, new_body, None, to_mapping, torepo)
is_transferred = self.ghc.create_issue(new_title, new_body, None, to_mapping, actl_to_repo)

if not is_transferred:
logging.error('Unable to create issue with idx: %s', user)
logging.error('[%d][#%d][%s -> %s] Unable to copy', idx, issue.number, fromrepo, actl_to_repo)

def blast_issues(self, csv_file, title, msg_file, start_from):
"""
Expand Down
4 changes: 4 additions & 0 deletions example/issues/copy/mapping.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
origin1,tag1,tag2,tag3
origin2,tag1,tag2,tag3
origin3,tag1,tag2,tag3
(and so on...)

0 comments on commit 17fedd5

Please sign in to comment.