Skip to content

Commit 87bd277

Browse files
committed
added --ignore-pullrequests option
1 parent 9fed7f6 commit 87bd277

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

gh-issues-import.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def init_config():
3939
config.add_section('target')
4040
config.add_section('format')
4141
config.add_section('settings')
42-
42+
config.add_section('filter')
43+
4344
arg_parser = argparse.ArgumentParser(description="Import issues from one GitHub repository into another.")
4445

4546
config_group = arg_parser.add_mutually_exclusive_group(required=False)
@@ -50,11 +51,14 @@ def init_config():
5051
arg_parser.add_argument('-p', '--password', help="The password (in plaintext) of the account that will create the new issues. The password will not be stored anywhere if passed in as an argument.")
5152
arg_parser.add_argument('-s', '--source', help="The source repository which the issues should be copied from. Should be in the format `user/repository`.")
5253
arg_parser.add_argument('-t', '--target', help="The destination repository which the issues should be copied to. Should be in the format `user/repository`.")
53-
54-
arg_parser.add_argument('--ignore-comments', dest='ignore_comments', action='store_true', help="Do not import comments in the issue.")
54+
55+
arg_parser.add_argument('--ignore-comments', dest='ignore_comments', action='store_true', help="Do not import comments in the issue.")
5556
arg_parser.add_argument('--ignore-milestone', dest='ignore_milestone', action='store_true', help="Do not import the milestone attached to the issue.")
5657
arg_parser.add_argument('--ignore-labels', dest='ignore_labels', action='store_true', help="Do not import labels attached to the issue.")
57-
58+
arg_parser.add_argument('--ignore-pullrequests', dest='ignore_pullrequests', action='store_true', help="Do not import issues that are pull requests.")
59+
60+
arg_parser.add_argument('--filter-labels', dest='filter_labels', help="Comma separated values of labels to use as filters.")
61+
5862
arg_parser.add_argument('--issue-template', help="Specify a template file for use with issues.")
5963
arg_parser.add_argument('--comment-template', help="Specify a template file for use with comments.")
6064
arg_parser.add_argument('--pull-request-template', help="Specify a template file for use with pull requests.")
@@ -235,18 +239,24 @@ def get_issues_by_id(which, issue_ids):
235239
issues = []
236240
for issue_id in issue_ids:
237241
issues.append(get_issue_by_id(which, int(issue_id)))
238-
242+
239243
return issues
240244

241245
# Allowed values for state are 'open' and 'closed'
242246
def get_issues_by_state(which, state):
243247
issues = []
244248
page = 1
249+
import_pullrequests = config.getboolean('settings', 'import-pullrequests')
250+
default_labels = ''
251+
labels = config.get('filter', 'labels', fallback=default_labels)
245252
while True:
246-
new_issues = send_request(which, "issues?state=%s&direction=asc&page=%d" % (state, page))
253+
new_issues = send_request(which, "issues?state=%s&direction=asc&page=%d&labels=%s" % (state, page, labels))
247254
if not new_issues:
248255
break
249-
issues.extend(new_issues)
256+
if import_pullrequests:
257+
issues.extend(new_issues)
258+
else:
259+
issues.extend(filter(lambda issue:'pull_request' not in issue ,new_issues))
250260
page += 1
251261
return issues
252262

0 commit comments

Comments
 (0)