Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jupyter-naas
GitHub Repository: jupyter-naas/awesome-notebooks
Path: blob/master/GitHub/GitHub_Close_issue.ipynb
2973 views
Kernel: Python 3

GitHub.png

GitHub - Close issue

Give Feedback | Bug report

Tags: #github #issues #update #rest #api #snippet #operations

Last update: 2023-05-26 (Created: 2022-03-18)

Description: This notebook explains how to close an issue on GitHub using the REST API.

Input

Import libraries

import requests import naas

Setup Variables

  • token: GitHub token

  • owner: owner of the repository

  • repo: name of the repository

  • issue_number: number of the issue

  • state_reason: The reason for the issue closed. Can be one of: completed, not_planned

# Inputs token = naas.secret.get('GITHUB_TOKEN') owner = "jupyter-naas" repo = "awesome-notebooks" issue_number = 99 # Outputs state_reason = "not_planned"

Model

Update issue

This function updates an issue on GitHub using the REST API.

def update_issue( token, owner, repo, issue_number, title=None, body=None, state="closed", state_reason=None, labels=[], assignees=[], ): url = f"https://api.github.com/repos/{owner}/{repo}/issues/{issue_number}" headers = {"Authorization": f"token {token}"} data = {} if title: data["title"] = title if body: data["body"] = body if state: data["state"] = state if state_reason: data["state_reason"] = state_reason if len(labels) > 0: data["labels"] = labels if len(assignees) > 0: data["assignees"] = assignees # Send the PATCH request res = requests.patch(url, headers=headers, json=data) if res.status_code == 200: print(f"✅ Issue closed:", f"https://github.com/{owner}/{repo}/issues/{issue_number}") return res else: print(res.status_code, res.json())

Output

Display Result

update_issue( token, owner, repo, issue_number, state_reason=state_reason, )