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
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
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/>. */
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)
35 response
= json
.loads(r
.text
)
37 if 'error' in response
and response
['error']:
38 print(response
['message'])
41 # 2) mark the bug as spam
42 bug
= response
['bugs'][0]
43 creator
= bug
['creator']
47 'resolution': 'INVALID',
51 'comment': { 'comment': 'spam'},
55 'cc': {'remove': cc_list
},
57 'severity': 'trivial',
59 'assigned_to': 'unassigned@gcc.gnu.org' }
61 r
= requests
.put(u
, json
= data
)
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
:
72 u2
= '%sbug/comment/%d/tags' % (base_url
, comment_id
)
74 r
= requests
.put(u2
, json
= {'comment_id': comment_id
, 'add': ['spam'], 'api_key': api_key
})
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)]
84 attachment_id
= a
['id']
85 url
= '%sbug/attachment/%d' % (base_url
, attachment_id
)
86 r
= requests
.put(url
, json
= {'ids': [attachment_id
],
89 'content_type': 'application/x-spam',
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(',')
105 parts
= list(map(lambda x
: int(x
), c
.split('-')))
109 r
= range(parts
[0], parts
[1] + 1)
112 mark_as_spam(id, args
.api_key
, args
.verbose
)