]>
Commit | Line | Data |
---|---|---|
ce84ada3 | 1 | #!/usr/bin/env python3 |
81f86cb9 | 2 | |
83ffe9cd | 3 | # Copyright (C) 2016-2023 Free Software Foundation, Inc. |
ce84ada3 ML |
4 | # |
5 | # Script to mark bunch of PRs as spam | |
6 | # | |
7 | # This file is part of GCC. | |
8 | # | |
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. | |
13 | # | |
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. | |
18 | # | |
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/>. */ | |
22 | # | |
23 | # | |
24 | # | |
25 | ||
26 | import requests | |
27 | import json | |
28 | import argparse | |
29 | ||
30 | base_url = 'https://gcc.gnu.org/bugzilla/rest.cgi/' | |
31 | ||
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) | |
38 | ||
28619cd7 ML |
39 | if 'error' in response and response['error']: |
40 | print(response['message']) | |
41 | return | |
42 | ||
ce84ada3 | 43 | # 2) mark the bug as spam |
abe95ef6 ML |
44 | bug = response['bugs'][0] |
45 | creator = bug['creator'] | |
46 | cc_list = bug['cc'] | |
ce84ada3 ML |
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', | |
28619cd7 | 60 | 'url': '', |
ce84ada3 ML |
61 | 'assigned_to': 'unassigned@gcc.gnu.org' } |
62 | ||
63 | r = requests.put(u, json = data) | |
64 | if verbose: | |
65 | print(r) | |
66 | print(r.text) | |
67 | ||
68 | # 3) mark the first comment as spam | |
69 | r = requests.get(u + '/comment') | |
70 | response = json.loads(r.text) | |
abe95ef6 ML |
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) | |
ce84ada3 | 80 | |
3f1b3373 ML |
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) | |
28619cd7 ML |
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}) | |
3f1b3373 ML |
94 | if verbose: |
95 | print(r) | |
96 | print(r.text) | |
97 | ||
ce84ada3 ML |
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') | |
102 | ||
103 | args = parser.parse_args() | |
104 | ||
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) | |
112 | ||
113 | for id in r: | |
114 | mark_as_spam(id, args.api_key, args.verbose) |