Skip to content

Commit 3073c4f

Browse files
authored
Issue backfiler (#2622)
* Fixing f-string reported by lint * Add a backfiler
1 parent d1c6aa8 commit 3073c4f

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

butler.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self, *args, **kwargs):
4444

4545
def error(self, message):
4646
"""Override to print full help for ever error."""
47-
sys.stderr.write('error: %s\n' % message)
47+
sys.stderr.write(f'error: {message}\n')
4848
self.print_help()
4949
sys.exit(2)
5050

@@ -190,6 +190,8 @@ def main():
190190
parser_run.add_argument(
191191
'script_name',
192192
help='The script module name under `./local/butler/scripts`.')
193+
parser_run.add_argument(
194+
'--script_args', action='append', help='Script specific arguments')
193195
parser_run.add_argument(
194196
'--non-dry-run',
195197
action='store_true',
@@ -299,7 +301,7 @@ def main():
299301
return
300302

301303
_setup()
302-
command = importlib.import_module('local.butler.%s' % args.command)
304+
command = importlib.import_module(f'local.butler.{args.command}')
303305
command.execute(args)
304306

305307

src/local/butler/run.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import importlib
1818
import os
19+
import sys
1920

2021
from local.butler import constants
2122
from src.clusterfuzz._internal.config import local_config
@@ -25,6 +26,8 @@
2526
def execute(args):
2627
"""Run Python unit tests under v2. For unittests involved appengine, sys.path
2728
needs certain modification."""
29+
print(args.script_args)
30+
sys.path.insert(0, os.path.abspath(os.path.join('src', 'appengine')))
2831
os.environ['CONFIG_DIR_OVERRIDE'] = args.config_dir
2932
local_config.ProjectConfig().set_environment()
3033

@@ -39,8 +42,7 @@ def execute(args):
3942
'For permanent modifications, re-run with --non-dry-run.')
4043

4144
with ndb_init.context():
42-
script = importlib.import_module(
43-
'local.butler.scripts.%s' % args.script_name)
45+
script = importlib.import_module(f'local.butler.scripts.{args.script_name}')
4446
script.execute(args)
4547

4648
if not args.local:
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""backfiler.py queries past testcases of the given projects
15+
and filed them to the projects' GitHub repository."""
16+
17+
from clusterfuzz._internal.datastore import data_types
18+
from clusterfuzz._internal.datastore import ndb_utils
19+
from libs.issue_management import oss_fuzz_github
20+
21+
22+
def execute(args):
23+
"""Query Testcases of the given projects,
24+
and conditionally file them to the corresponding GitHub repo."""
25+
if not args.script_args:
26+
print('Need at least one project name (with -p) '
27+
'when running the backfiler.')
28+
return
29+
for project_name in args.script_args:
30+
print(f'Back filing project {project_name}')
31+
for testcase in data_types.Testcase.query(
32+
ndb_utils.is_true(data_types.Testcase.open),
33+
ndb_utils.is_false(data_types.Testcase.one_time_crasher_flag),
34+
data_types.Testcase.status == 'Processed',
35+
data_types.Testcase.project_name == project_name,
36+
):
37+
if not testcase.bug_information:
38+
print(f'Skip testcase without bugs: {testcase.key.id()}')
39+
continue
40+
print(f'Back filing testcase id: {testcase.key.id()}')
41+
if args.non_dry_run:
42+
oss_fuzz_github.file_issue(testcase)

0 commit comments

Comments
 (0)