@@ -103,35 +103,55 @@ def main():
103
103
default = False ,
104
104
help = "Delete bugs if not found in source (GIT only)" )
105
105
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." )
107
111
108
112
args = parser .parse_args ()
109
113
110
114
datastore_client = ndb .Client (args .project_id )
111
115
112
116
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 } '
119
138
request_url_update (record_url , args .project_id , args .source , path ,
120
139
args .timeout , False )
121
140
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 :
124
143
entity = osv .Bug .get_by_id (bug )
125
144
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
127
147
128
148
path = entity .source_id .split (':' )[1 ]
129
149
130
- record_url = github_raw_url (source .repo_url , path )
150
+ record_url = github_raw_url (source_repo .repo_url , path )
131
151
request_url_update (record_url , args .project_id , args .source , path ,
132
152
args .timeout , args .allow_delete )
133
153
134
- if source .type == osv .SourceRepositoryType .BUCKET :
154
+ if source_repo .type == osv .SourceRepositoryType .BUCKET :
135
155
raise NotImplementedError ("Use reimport_gcs_record.py for now" )
136
156
137
157
0 commit comments