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

GitHub.png

GitHub - Create an issue comment

Give Feedback | Bug report

Tags: #github #issue #comment #api #python #library

Last update: 2023-05-26 (Created: 2023-05-26)

Description: This notebook shows how to add a comment to an issue on GitHub.

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

  • comment: comment to be added

token = naas.secret.get('GITHUB_TOKEN') owner = "jupyter-naas" repo = "awesome-notebooks" issue_number = 1808 comment = "This is a comment"

Model

Create an issue comment

def create_issue_comment( token=None, owner=None, repo=None, issue_number=None, comment=None ): # URL url = f"https://api.github.com/repos/{owner}/{repo}/issues/{issue_number}/comments" data = {"body": comment} # Set the request headers headers = { "Authorization": f"token {token}", "Content-Type": "application/json" } # Send the POST request res = requests.post(url, headers=headers, json=data) if res.status_code == 201: print(f"✅ Comment added on issue:", f"https://github.com/{owner}/{repo}/issues/{issue_number}") return res else: print(res.status_code, res.json())

Output

Display result

create_issue_comment(token, owner, repo, issue_number, comment)