Query for existing assets and then delete

This commit is contained in:
Kovid Goyal 2022-11-23 07:53:14 +05:30
parent 2b676b63b1
commit 8fb2c209a9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -285,7 +285,6 @@ class GitHub(Base): # {{{
upload_url = release['upload_url'].partition('{')[0] upload_url = release['upload_url'].partition('{')[0]
asset_url = f'{self.url_base}/assets/{{}}' asset_url = f'{self.url_base}/assets/{{}}'
existing_assets = self.existing_assets(release['id']) existing_assets = self.existing_assets(release['id'])
original_existing_assets = existing_assets.copy()
def delete_asset(asset_id: str) -> None: def delete_asset(asset_id: str) -> None:
r = self.requests.delete(asset_url.format(asset_id)) r = self.requests.delete(asset_url.format(asset_id))
@ -318,7 +317,11 @@ class GitHub(Base): # {{{
try: try:
asset_id = r.json()['id'] asset_id = r.json()['id']
except Exception: except Exception:
asset_id = original_existing_assets[fname] try:
asset_id = self.existing_assets(release['id'])[fname]
except KeyError:
asset_id = 0
if asset_id:
self.info(f'Deleting {fname} from GitHub with id: {asset_id}') self.info(f'Deleting {fname} from GitHub with id: {asset_id}')
delete_asset(asset_id) delete_asset(asset_id)
time.sleep(sleep_time) time.sleep(sleep_time)