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