3 # Copyright (C) 2016-2024 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
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
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/>.
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)
37 response
= json
.loads(r
.text
)
39 if 'error' in response
and response
['error']:
40 print(response
['message'])
43 # 2) mark the bug as spam
44 bug
= response
['bugs'][0]
45 creator
= bug
['creator']
49 'resolution': 'INVALID',
53 'comment': { 'comment': 'spam'},
57 'cc': {'remove': cc_list
},
59 'severity': 'trivial',
61 'assigned_to': 'unassigned@gcc.gnu.org' }
63 r
= requests
.put(u
, json
= data
)
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
:
74 u2
= '%sbug/comment/%d/tags' % (base_url
, comment_id
)
76 r
= requests
.put(u2
, json
= {'comment_id': comment_id
, 'add': ['spam'], 'api_key': api_key
})
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)]
86 attachment_id
= a
['id']
87 url
= '%sbug/attachment/%d' % (base_url
, attachment_id
)
88 r
= requests
.put(url
, json
= {'ids': [attachment_id
],
91 'content_type': 'application/x-spam',
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(',')
107 parts
= list(map(lambda x
: int(x
), c
.split('-')))
111 r
= range(parts
[0], parts
[1] + 1)
114 mark_as_spam(id, args
.api_key
, args
.verbose
)