forked from svigerske/trac-to-github
-
Notifications
You must be signed in to change notification settings - Fork 5
/
minimize_issue_comments.py
executable file
·77 lines (63 loc) · 2.2 KB
/
minimize_issue_comments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python3
import re
import os
import sys
import configparser
import logging
import json
from time import sleep
from github import Github, GithubObject, InputFileContent
from github.Issue import Issue
from github.IssueComment import IssueComment
from github.Repository import Repository
from github.GithubException import IncompletableObject
from rich.console import Console
from rich.table import Table
#import github as gh
#gh.enable_console_debug_logging()
log = logging.getLogger("trac_to_gh")
default_config = {
'url' : 'https://api.github.com'
}
config = configparser.ConfigParser(default_config)
if len(sys.argv) > 1 :
config.read(sys.argv[1])
else :
config.read('migrate.cfg')
github_api_url = config.get('target', 'url')
github_token = None
if config.has_option('target', 'token') :
github_token = config.get('target', 'token')
elif config.has_option('target', 'username'):
github_username = config.get('target', 'username')
github_password = config.get('target', 'password')
else:
github_username = None
github_project = config.get('target', 'project_name')
def to_minimize(c):
return c.body.startswith('Description changed:\n')
if __name__ == "__main__":
if github_token is not None:
github = Github(github_token, base_url=github_api_url)
elif github_username is not None:
github = Github(github_username, github_password, base_url=github_api_url)
if github:
repo = github.get_repo(github_project)
with open("minimized_issue_comments.json", "r") as f:
comment_urls = json.load(f)
issue_numbers = set()
for url in comment_urls:
issue_url = url.partition('#')[0]
issue_number = int(issue_url.rpartition('/')[2])
issue_numbers.add(issue_number)
minimized_node_ids = []
try:
for issue_number in sorted(issue_numbers):
i = repo.get_issue(issue_number)
node_ids = [c.node_id for c in i.get_comments() if to_minimize(c)]
print(i.html_url, node_ids)
minimized_node_ids.extend(node_ids)
sleep(1.5)
finally:
with open("minimized_issue_comment_node_ids.json", "w") as f:
json.dump(minimized_node_ids, f, indent=4)