forked from Ladsgroup/Phabricator-maintenance-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch_makers.py
130 lines (111 loc) · 4.48 KB
/
patch_makers.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import json
from datetime import date
from gerrit import GerritBot
class WikimediaMessagesPatchMaker(GerritBot):
def __init__(self, db_name, english_name, url, lang, bug_id):
self.db_name = db_name
self.english_name = english_name
self.wiki_url = url
self.wiki_lang = lang
super().__init__(
'mediawiki/extensions/WikimediaMessages',
'Add messages for {} ({})\n\nBug:{}'.format(
english_name, db_name, bug_id)
)
def changes(self):
file_ = 'i18n/wikimediaprojectnames/en.json'
result = self._read_json(file_)
result['project-localized-name-' + self.db_name] = self.english_name
self._write_json(file_, result)
file_ = 'i18n/wikimediaprojectnames/qqq.json'
result = self._read_json(file_)
result['project-localized-name-' + self.db_name] = '{{ProjectNameDocumentation|url=https://' + \
self.wiki_url + '|name=' + self.english_name + \
'|language=' + self.wiki_lang + '}}'
self._write_json(file_, result)
if not 'wikipedia' in self.wiki_url:
return
file_ = 'i18n/wikimediainterwikisearchresults/en.json'
result = self._read_json(file_)
result['search-interwiki-results-' +
self.db_name] = 'Showing results from [[:{}:|{}]].'.format(self.wiki_lang, self.english_name)
self._write_json(file_, result)
file_ = 'i18n/wikimediainterwikisearchresults/qqq.json'
result = self._read_json(file_)
result['search-interwiki-results-' + self.db_name] = 'Search results description for ' + \
self.english_name + '.\n{{LanguageNameTip|' + self.wiki_lang + '}}'
self._write_json(file_, result)
def _read_json(self, path):
with open(path, 'r') as f:
result = json.load(f)
return result
def _write_json(self, path, content):
with open(path, 'w') as f:
f.write(json.dumps(content, ensure_ascii=False,
indent='\t', sort_keys=True) + '\n')
class DnsPatchMaker(GerritBot):
def __init__(self, lang, bug_id):
self.wiki_lang = lang
super().__init__(
'operations/dns',
'Add {} to langlist helper\n\nBug:{}'.format(lang, bug_id)
)
def changes(self):
with open('templates/helpers/langlist.tmpl', 'r') as f:
lines = f.read().split('\n')
header = []
langs = []
footer = []
for line in lines:
if not line.startswith(' '):
if not header:
header.append(line)
else:
footer.append(line)
else:
langs.append(line)
langs.append(" '{}',".format(self.wiki_lang))
langs.sort()
with open('templates/helpers/langlist.tmpl', 'w') as f:
f.write('\n'.join(header) + '\n' +
'\n'.join(langs) + '\n' + '\n'.join(footer))
class CxPatchMaker(GerritBot):
def __init__(self, lang, bug_id):
self.wiki_lang = lang
super().__init__(
'mediawiki/services/cxserver',
'Add {} to languages \n\nBug:{}'.format(lang, bug_id)
)
def changes(self):
with open('config/languages.yaml', 'r') as f:
lines = f.read().split('\n')[:-1]
lines.append("- {}".format(self.wiki_lang))
lines.sort()
with open('config/languages.yaml', 'w') as f:
f.write('\n'.join(lines) + '\n')
class AnalyticsPatchMaker(GerritBot):
def __init__(self, project, bug_id):
self.project = project
super().__init__(
'analytics/refinery',
'Add {} to pageview whitelist \n\nBug:{}'.format(project, bug_id)
)
def changes(self):
with open('static_data/pageview/whitelist/whitelist.tsv', 'r') as f:
lines = f.read().split('\n')
projects = []
non_projects = []
for line in lines:
if line.startswith('project'):
projects.append(line)
else:
non_projects.append(line)
today = date.today()
projects.append('project\t{}\t{}'.format(
self.project,
today.strftime("%Y-%m-%d 00:00:00")
))
projects = list(set(projects))
projects.sort()
with open('static_data/pageview/whitelist/whitelist.tsv', 'w') as f:
f.write('\n'.join(projects) + '\n' + '\n'.join(non_projects))