Daily bump.
[official-gcc.git] / contrib / mark_spam.py
blob86f46a129ccd1377462329814ed0d1eabaa03a53
1 #!/usr/bin/env python3
3 # Script to mark bunch of PRs as spam
5 # This file is part of GCC.
7 # GCC is free software; you can redistribute it and/or modify it under
8 # the terms of the GNU General Public License as published by the Free
9 # Software Foundation; either version 3, or (at your option) any later
10 # version.
12 # GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GCC; see the file COPYING3. If not see
19 # <http://www.gnu.org/licenses/>. */
24 import requests
25 import json
26 import argparse
28 base_url = 'https://gcc.gnu.org/bugzilla/rest.cgi/'
30 def mark_as_spam(id, api_key, verbose):
31 print('Marking as spam: PR%d' % id)
32 # 1) get bug info to find 'cc'
33 u = base_url + 'bug/' + str(id)
34 r = requests.get(u)
35 response = json.loads(r.text)
37 if 'error' in response and response['error']:
38 print(response['message'])
39 return
41 # 2) mark the bug as spam
42 bug = response['bugs'][0]
43 creator = bug['creator']
44 cc_list = bug['cc']
45 data = {
46 'status': 'RESOLVED',
47 'resolution': 'INVALID',
48 'summary': 'spam',
49 'ids': [id],
50 'api_key': api_key,
51 'comment': { 'comment': 'spam'},
52 'product': 'gcc',
53 'component': 'spam',
54 'version': 'unknown',
55 'cc': {'remove': cc_list},
56 'priority': 'P5',
57 'severity': 'trivial',
58 'url': '',
59 'assigned_to': 'unassigned@gcc.gnu.org' }
61 r = requests.put(u, json = data)
62 if verbose:
63 print(r)
64 print(r.text)
66 # 3) mark the first comment as spam
67 r = requests.get(u + '/comment')
68 response = json.loads(r.text)
69 for c in response['bugs'][str(id)]['comments']:
70 if c['creator'] == creator:
71 comment_id = c['id']
72 u2 = '%sbug/comment/%d/tags' % (base_url, comment_id)
73 print(u2)
74 r = requests.put(u2, json = {'comment_id': comment_id, 'add': ['spam'], 'api_key': api_key})
75 if verbose:
76 print(r)
77 print(r.text)
79 # 4) mark all attachments as spam
80 r = requests.get(u + '/attachment')
81 response = json.loads(r.text)
82 attachments = response['bugs'][str(id)]
83 for a in attachments:
84 attachment_id = a['id']
85 url = '%sbug/attachment/%d' % (base_url, attachment_id)
86 r = requests.put(url, json = {'ids': [attachment_id],
87 'summary': 'spam',
88 'file_name': 'spam',
89 'content_type': 'application/x-spam',
90 'is_obsolete': True,
91 'api_key': api_key})
92 if verbose:
93 print(r)
94 print(r.text)
96 parser = argparse.ArgumentParser(description='Mark Bugzilla issues as spam.')
97 parser.add_argument('api_key', help = 'API key')
98 parser.add_argument('range', help = 'Range of IDs, e.g. 10-23,24,25,27')
99 parser.add_argument('--verbose', action = 'store_true', help = 'Verbose logging')
101 args = parser.parse_args()
103 chunks = args.range.split(',')
104 for c in chunks:
105 parts = list(map(lambda x: int(x), c.split('-')))
106 if len(parts) == 1:
107 r = [parts[0]]
108 else:
109 r = range(parts[0], parts[1] + 1)
111 for id in r:
112 mark_as_spam(id, args.api_key, args.verbose)