Hello. This is python script that utilizes bugzilla API and marks PRs as spam:
$ ./mark_spam.py --help usage: mark_spam.py [-h] [--verbose] api_key range Mark Bugzilla issues as spam. positional arguments: api_key API key range Range of IDs, e.g. 10-23,24,25,27 optional arguments: -h, --help show this help message and exit --verbose Verbose logging Sample usage: $ ./mark_spam.py my_api_key 72634-72636 Marking as spam: PR72634 Marking as spam: PR72635 Marking as spam: PR72636 API key can be set up here: https://gcc.gnu.org/bugzilla/userprefs.cgi?tab=apikey Sample PR marked by the script: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72635 Ready to install? Martin
>From 467dc2cf8f0c549f5d7ee190efe59c841a9acad9 Mon Sep 17 00:00:00 2001 From: marxin <mli...@suse.cz> Date: Tue, 26 Jul 2016 14:34:55 +0200 Subject: [PATCH] Add mark_spam.py script contrib/ChangeLog: 2016-07-26 Martin Liska <mli...@suse.cz> * mark_spam.py: New file. --- contrib/mark_spam.py | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100755 contrib/mark_spam.py diff --git a/contrib/mark_spam.py b/contrib/mark_spam.py new file mode 100755 index 0000000..cc394dc --- /dev/null +++ b/contrib/mark_spam.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python3 +# +# Script to mark bunch of PRs as spam +# +# This file is part of GCC. +# +# GCC is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation; either version 3, or (at your option) any later +# version. +# +# GCC is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# <http://www.gnu.org/licenses/>. */ +# +# +# + +import requests +import json +import argparse + +base_url = 'https://gcc.gnu.org/bugzilla/rest.cgi/' + +def mark_as_spam(id, api_key, verbose): + print('Marking as spam: PR%d' % id) + # 1) get bug info to find 'cc' + u = base_url + 'bug/' + str(id) + r = requests.get(u) + response = json.loads(r.text) + + # 2) mark the bug as spam + cc_list = response['bugs'][0]['cc'] + data = { + 'status': 'RESOLVED', + 'resolution': 'INVALID', + 'summary': 'spam', + 'ids': [id], + 'api_key': api_key, + 'comment': { 'comment': 'spam'}, + 'product': 'gcc', + 'component': 'spam', + 'version': 'unknown', + 'cc': {'remove': cc_list}, + 'priority': 'P5', + 'severity': 'trivial', + 'assigned_to': 'unassig...@gcc.gnu.org' } + + r = requests.put(u, json = data) + if verbose: + print(r) + print(r.text) + + # 3) mark the first comment as spam + r = requests.get(u + '/comment') + response = json.loads(r.text) + comment_id = response['bugs'][str(id)]['comments'][0]['id'] + + u2 = '%sbug/comment/%d/tags' % (base_url, comment_id) + r = requests.put(u2, json = {'comment_id': comment_id, 'add': ['spam'], 'api_key': api_key}) + if verbose: + print(r) + print(r.text) + +parser = argparse.ArgumentParser(description='Mark Bugzilla issues as spam.') +parser.add_argument('api_key', help = 'API key') +parser.add_argument('range', help = 'Range of IDs, e.g. 10-23,24,25,27') +parser.add_argument('--verbose', action = 'store_true', help = 'Verbose logging') + +args = parser.parse_args() + +chunks = args.range.split(',') +for c in chunks: + parts = list(map(lambda x: int(x), c.split('-'))) + if len(parts) == 1: + r = [parts[0]] + else: + r = range(parts[0], parts[1] + 1) + + for id in r: + mark_as_spam(id, args.api_key, args.verbose) -- 2.9.2
#!/usr/bin/env python3 # # Script to mark bunch of PRs as spam # # This file is part of GCC. # # GCC is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3, or (at your option) any later # version. # # GCC is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License # along with GCC; see the file COPYING3. If not see # <http://www.gnu.org/licenses/>. */ # # # import requests import json import argparse base_url = 'https://gcc.gnu.org/bugzilla/rest.cgi/' def mark_as_spam(id, api_key, verbose): print('Marking as spam: PR%d' % id) # 1) get bug info to find 'cc' u = base_url + 'bug/' + str(id) r = requests.get(u) response = json.loads(r.text) # 2) mark the bug as spam cc_list = response['bugs'][0]['cc'] data = { 'status': 'RESOLVED', 'resolution': 'INVALID', 'summary': 'spam', 'ids': [id], 'api_key': api_key, 'comment': { 'comment': 'spam'}, 'product': 'gcc', 'component': 'spam', 'version': 'unknown', 'cc': {'remove': cc_list}, 'priority': 'P5', 'severity': 'trivial', 'assigned_to': 'unassig...@gcc.gnu.org' } r = requests.put(u, json = data) if verbose: print(r) print(r.text) # 3) mark the first comment as spam r = requests.get(u + '/comment') response = json.loads(r.text) comment_id = response['bugs'][str(id)]['comments'][0]['id'] u2 = '%sbug/comment/%d/tags' % (base_url, comment_id) r = requests.put(u2, json = {'comment_id': comment_id, 'add': ['spam'], 'api_key': api_key}) if verbose: print(r) print(r.text) parser = argparse.ArgumentParser(description='Mark Bugzilla issues as spam.') parser.add_argument('api_key', help = 'API key') parser.add_argument('range', help = 'Range of IDs, e.g. 10-23,24,25,27') parser.add_argument('--verbose', action = 'store_true', help = 'Verbose logging') args = parser.parse_args() chunks = args.range.split(',') for c in chunks: parts = list(map(lambda x: int(x), c.split('-'))) if len(parts) == 1: r = [parts[0]] else: r = range(parts[0], parts[1] + 1) for id in r: mark_as_spam(id, args.api_key, args.verbose)