1
0
Fork 0
mirror of https://gitlab.wikimedia.org/ladsgroup/Phabricator-maintenance-bot synced 2024-11-28 15:02:39 +01:00

Make CX and Analytics patches too

This commit is contained in:
Amir Sarabadani 2020-08-29 23:51:34 +02:00
parent bd6ee7e894
commit 47c00f28ba
3 changed files with 95 additions and 10 deletions

View file

@ -80,6 +80,7 @@ class ShellMixin:
self.check_call(['git', 'config', 'user.name', creds['name']]) self.check_call(['git', 'config', 'user.name', creds['name']])
self.check_call(['git', 'config', 'user.email', creds['email']]) self.check_call(['git', 'config', 'user.email', creds['email']])
self.check_call(['git', 'submodule', 'update', '--init']) self.check_call(['git', 'submodule', 'update', '--init'])
load_ssh_key()
self.check_call(['scp', '-p', '-P', '29418', creds['name'] + self.check_call(['scp', '-p', '-P', '29418', creds['name'] +
'@gerrit.wikimedia.org:hooks/commit-msg', '.git/hooks/']) '@gerrit.wikimedia.org:hooks/commit-msg', '.git/hooks/'])
@ -126,7 +127,6 @@ class GerritBot(ShellMixin):
with open('.git/COMMIT_EDITMSG', 'w') as f: with open('.git/COMMIT_EDITMSG', 'w') as f:
f.write(self.commit_message) f.write(self.commit_message)
self.check_call(['git', 'commit', '-F', '.git/COMMIT_EDITMSG']) self.check_call(['git', 'commit', '-F', '.git/COMMIT_EDITMSG'])
load_ssh_key()
self.check_call(self.build_push_command( self.check_call(self.build_push_command(
{'hashtags': ['automated-wiki-creation'], 'repo': self.name})) {'hashtags': ['automated-wiki-creation'], 'repo': self.name}))

View file

@ -6,7 +6,8 @@ import socket
import requests import requests
from lib import Client from lib import Client
from patch_makers import DnsPatchMaker, WikimediaMessagesPatchMaker from patch_makers import (AnalyticsPatchMaker, CxPatchMaker, DnsPatchMaker,
WikimediaMessagesPatchMaker)
final_text = '' final_text = ''
gerrit_path = 'https://gerrit.wikimedia.org/g/' gerrit_path = 'https://gerrit.wikimedia.org/g/'
@ -62,17 +63,28 @@ def handle_restbase(url):
add_checklist(gerrit_path + path, 'RESTbase', url in restbase) add_checklist(gerrit_path + path, 'RESTbase', url in restbase)
def handle_cx(language_code): def handle_cx(language_code, bug_id):
path = get_gerrit_path( path = get_gerrit_path(
'mediawiki/services/cxserver', 'mediawiki/services/cxserver',
'config/languages.yaml' 'config/languages.yaml'
) )
cxconfig = get_file_from_gerrit(path) cxconfig = get_file_from_gerrit(path)
add_checklist(gerrit_path + path, 'CX Config', cx = '\n- ' + language_code in cxconfig
'\n- ' + language_code in cxconfig) add_checklist(gerrit_path + path, 'CX Config', cx)
if cx:
return
r = requests.get(
'https://gerrit.wikimedia.org/r/changes/'
'?q=bug:{}+project:mediawiki/services/cxserver'.format(bug_id))
b = json.loads('\n'.join(r.text.split('\n')[1:]))
if b:
return
maker = CxPatchMaker(lang, bug_id)
maker.run()
def handle_analytics(url): def handle_analytics(url, bug_id):
path = get_gerrit_path( path = get_gerrit_path(
'analytics/refinery', 'analytics/refinery',
'static_data/pageview/whitelist/whitelist.tsv' 'static_data/pageview/whitelist/whitelist.tsv'
@ -80,6 +92,17 @@ def handle_analytics(url):
refinery_whitelist = get_file_from_gerrit(path) refinery_whitelist = get_file_from_gerrit(path)
add_checklist(gerrit_path + path, 'Analytics refinery', add_checklist(gerrit_path + path, 'Analytics refinery',
url in refinery_whitelist) url in refinery_whitelist)
if url in refinery_whitelist:
return
r = requests.get(
'https://gerrit.wikimedia.org/r/changes/'
'?q=bug:{}+project:analytics/refinery'.format(bug_id))
b = json.loads('\n'.join(r.text.split('\n')[1:]))
if b:
return
maker = AnalyticsPatchMaker(lang, bug_id)
maker.run()
def handle_pywikibot(family, language_code): def handle_pywikibot(family, language_code):
@ -413,8 +436,8 @@ def hande_task(task_details):
add_text('\n-------\n**Post install automatic checklist:**') add_text('\n-------\n**Post install automatic checklist:**')
handle_restbase(url) handle_restbase(url)
handle_cx(language_code) handle_cx(language_code, task_tid)
handle_analytics('.'.join(parts[:2])) handle_analytics('.'.join(parts[:2]), task_tid)
handle_pywikibot(parts[1], language_code) handle_pywikibot(parts[1], language_code)
handle_wikidata(db_name) handle_wikidata(db_name)
add_text(' [] Import from Incubator') add_text(' [] Import from Incubator')

View file

@ -1,4 +1,5 @@
import json import json
from datetime import date
from gerrit import GerritBot from gerrit import GerritBot
@ -54,7 +55,7 @@ class WikimediaMessagesPatchMaker(GerritBot):
indent='\t', sort_keys=True)) indent='\t', sort_keys=True))
def DnsPatchMaker(): class DnsPatchMaker(GerritBot):
def __init__(self, lang, bug_id): def __init__(self, lang, bug_id):
self.wiki_lang = lang self.wiki_lang = lang
super().__init__( super().__init__(
@ -79,4 +80,65 @@ def DnsPatchMaker():
langs.append(" '{}',".format(self.wiki_lang)) langs.append(" '{}',".format(self.wiki_lang))
langs.sort() langs.sort()
with open('templates/helpers/langlist.tmpl', 'w') as f: with open('templates/helpers/langlist.tmpl', 'w') as f:
f.write('\n'.join(footer) + '\n'.join(langs) + '\n'.join(footer)) 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.sort()
with open('static_data/pageview/whitelist/whitelist.tsv', 'w') as f:
f.write('\n'.join(projects) + '\n' + '\n'.join(non_projects))
class CxPatchMakerTemp(GerritBot):
def __init__(self):
super().__init__(
'mediawiki/services/cxserver',
'Order entries by alphabetical order\n\nThis would make creating automated patches easier\n\nBug: T253439'
)
def changes(self):
with open('config/languages.yaml', 'r') as f:
lines = f.read().split('\n')[:-1]
lines.sort()
with open('config/languages.yaml', 'w') as f:
f.write('\n'.join(lines) + '\n')