Skip to content

Commit bc42b86

Browse files
committed
update all bugs in the source
1 parent f6f9178 commit bc42b86

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

tools/datafix/request_worker_update_record.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,35 +103,55 @@ def main():
103103
default=False,
104104
help="Delete bugs if not found in source (GIT only)")
105105
parser.add_argument(
106-
"bugs", action="append", nargs="+", help="The bug IDs to operate on")
106+
"bugs",
107+
action="append",
108+
nargs="*",
109+
help="The bug IDs to operate on. If not specified, all bugs from the "
110+
"source will be processed.")
107111

108112
args = parser.parse_args()
109113

110114
datastore_client = ndb.Client(args.project_id)
111115

112116
with datastore_client.context():
113-
source = osv.SourceRepository.get_by_id(args.source)
114-
115-
if source.type == osv.SourceRepositoryType.REST_ENDPOINT:
116-
for bug in args.bugs[0]:
117-
record_url = f'{source.link}{bug}{source.extension}'
118-
path = f'{bug}{source.extension}'
117+
source_repo = osv.SourceRepository.get_by_id(args.source)
118+
if not source_repo:
119+
raise ValueError(f"Source repository '{args.source}' not found.")
120+
121+
bugs_to_process = []
122+
if args.bugs and args.bugs[0]:
123+
bugs_to_process = args.bugs[0]
124+
else:
125+
print(f'No bug IDs provided. Querying all bugs for source {args.source}...')
126+
query = osv.Bug.query(osv.Bug.source == args.source)
127+
bugs_to_process = [b.key.id() for b in query]
128+
print(f'Found {len(bugs_to_process)} bugs to update.')
129+
confirm = input('Are you sure you want to proceed? (y/N) ')
130+
if confirm.lower() not in ('y', 'yes'):
131+
print('Aborting.')
132+
return
133+
134+
if source_repo.type == osv.SourceRepositoryType.REST_ENDPOINT:
135+
for bug in bugs_to_process:
136+
record_url = f'{source_repo.link}{bug}{source_repo.extension}'
137+
path = f'{bug}{source_repo.extension}'
119138
request_url_update(record_url, args.project_id, args.source, path,
120139
args.timeout, False)
121140

122-
if source.type == osv.SourceRepositoryType.GIT:
123-
for bug in args.bugs[0]:
141+
if source_repo.type == osv.SourceRepositoryType.GIT:
142+
for bug in bugs_to_process:
124143
entity = osv.Bug.get_by_id(bug)
125144
if not entity:
126-
raise ValueError(f'{bug} does not exist in Datastore')
145+
print(f'Warning: {bug} does not exist in Datastore, skipping.')
146+
continue
127147

128148
path = entity.source_id.split(':')[1]
129149

130-
record_url = github_raw_url(source.repo_url, path)
150+
record_url = github_raw_url(source_repo.repo_url, path)
131151
request_url_update(record_url, args.project_id, args.source, path,
132152
args.timeout, args.allow_delete)
133153

134-
if source.type == osv.SourceRepositoryType.BUCKET:
154+
if source_repo.type == osv.SourceRepositoryType.BUCKET:
135155
raise NotImplementedError("Use reimport_gcs_record.py for now")
136156

137157

0 commit comments

Comments
 (0)