🖥
#python で #Github #API を叩いて Issue を 新規作成するスクリプトの例
Ref
Token
Personal Access Token を作っておく
Example
$ USERNAME=YumaInaura REPOSITORY=playground PASSWORD=[PersonalAccessToken] TITLE=testing BODY=testing_body LABELS=example,some_label python create-issue.py
Script
# https://gist.github.com/JeffPaine/3145490
import os
import json
import requests
# Authentication for user filing issue (must have read/write access to
# repository to add issue to)
USERNAME = os.environ.get('USERNAME')
PASSWORD = os.environ.get('PASSWORD')
# The repository to add this issue to
REPO_OWNER = os.environ.get('USERNAME')
REPO_NAME = os.environ.get('REPOSITORY')
TITLE = os.environ.get('TITLE')
BODY = os.environ.get('BODY')
if os.environ.get('LABELS'):
LABELS = os.environ.get('LABELS').split(',')
else:
LABELS = ''
def make_github_issue(title, body=None, labels=None):
'''Create an issue on github.com using the given parameters.'''
# Our url to create issues via POST
url = 'https://api.github.com/repos/%s/%s/issues' % (REPO_OWNER, REPO_NAME)
# Create an authenticated session to create the issue
session = requests.Session()
session.auth = (USERNAME, PASSWORD)
# Create our issue
issue = {'title': title,
'body': body,
'labels': labels}
# Add the issue to our repository
r = session.post(url, json.dumps(issue))
if r.status_code == 201:
print ('Successfully created Issue {0:s}'.format(title))
else:
print ('Could not create Issue {0:s}'.format(title))
print ('Response:', r.content)
make_github_issue(TITLE, body=BODY, labels=LABELS)
Original by Github issue
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。
公開日時
2019-03-10
Discussion