Fix workflow for closing nonexistent disable issues (#146447)

The workflow could not update issues because it didn't have permissions, and it looked green because it didn't check return codes.

Tested by running the workflow and seeing that issues did get closed
Fixes https://github.com/pytorch/pytorch/issues/145382
Pull Request resolved: https://github.com/pytorch/pytorch/pull/146447
Approved by: https://github.com/huydhn
This commit is contained in:
Catherine Lee 2025-02-05 22:29:05 +00:00 committed by PyTorch MergeBot
parent 9b6d680131
commit 97b64f2e5c
2 changed files with 16 additions and 3 deletions

View File

@ -107,16 +107,20 @@ def close_issue(num: int) -> None:
"Accept": "application/vnd.github.v3+json",
"Authorization": f"token {os.environ['GITHUB_TOKEN']}",
}
requests.post(
response = requests.post(
f"https://api.github.com/repos/pytorch/pytorch/issues/{num}/comments",
data=json.dumps({"body": CLOSING_COMMENT}),
headers=headers,
)
requests.patch(
if response.status_code != 201:
raise RuntimeError(f"Failed to comment on issue {num}: {response.text}")
response = requests.patch(
f"https://api.github.com/repos/pytorch/pytorch/issues/{num}",
data=json.dumps({"state": "closed"}),
headers=headers,
)
if response.status_code != 200:
raise RuntimeError(f"Failed to close issue {num}: {response.text}")
def check_if_exists(
@ -190,6 +194,13 @@ if __name__ == "__main__":
if args.dry_run:
print("dry run, not actually closing")
else:
failed = False
for item in to_be_closed:
_, (num, _, _) = item
try:
close_issue(num)
except RuntimeError as e:
print(e)
failed = True
if failed:
sys.exit(1)

View File

@ -7,6 +7,8 @@ on:
jobs:
close-nonexistent-disable-issues:
environment: rockset-read-only
permissions:
issues: write
if: github.repository_owner == 'pytorch'
runs-on: ubuntu-latest
steps: