LoginSignup
0
1

More than 1 year has passed since last update.

#python で #Github #API を叩いて1個の Issue 情報を取得するスクリプト例

Last updated at Posted at 2019-03-30

公開のレポジトリであれば特に認証も必要ない

#!/usr/bin/env python3

import requests, os, json

owner = os.environ.get('OWNER')
repository = os.environ.get('REPOSITORY')
issue_number = os.environ.get('NUMBER')

api_url = 'https://api.github.com/repos/' + owner + '/' + repository + '/issues/' + issue_number

res = requests.get(api_url)
result = res.json()

print(json.dumps(result))

example

$ OWNER=YumaInaura REPOSITORY=YumaInaura NUMBER=22 python3 single-issue.py | jq .
{
  "url": "https://api.github.com/repos/YumaInaura/YumaInaura/issues/22",
  "repository_url": "https://api.github.com/repos/YumaInaura/YumaInaura",
  "labels_url": "https://api.github.com/repos/YumaInaura/YumaInaura/issues/22/labels{/name}",
  "comments_url": "https://api.github.com/repos/YumaInaura/YumaInaura/issues/22/comments",
  "events_url": "https://api.github.com/repos/YumaInaura/YumaInaura/issues/22/events",
  "html_url": "https://github.com/YumaInaura/YumaInaura/issues/22",
  "id": 394759299,
  "node_id": "MDU6SXNzdWUzOTQ3NTkyOTk=",
  "number": 22,
  "title": "「私はロボットではありません」失敗!皆大嫌いなあいつは「ReCAPCHA」というらしい。@yumainara @qiita #認証 #google",
  "user": {
    "login": "YumaInaura",
    "id": 13635059,
    "node_id": "MDQ6VXNlcjEzNjM1MDU5",
    "avatar_url": "https://avatars2.githubusercontent.com/u/13635059?v=4",
    "gravatar_id": "",
    "url": "https://api.github.com/users/YumaInaura",
    "html_url": "https://github.com/YumaInaura",
    "followers_url": "https://api.github.com/users/YumaInaura/followers",
    "following_url": "https://api.github.com/users/YumaInaura/following{/other_user}",
    "gists_url": "https://api.github.com/users/YumaInaura/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/YumaInaura/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/YumaInaura/subscriptions",
    "organizations_url": "https://api.github.com/users/YumaInaura/orgs",
    "repos_url": "https://api.github.com/users/YumaInaura/repos",
    "events_url": "https://api.github.com/users/YumaInaura/events{/privacy}",
    "received_events_url": "https://api.github.com/users/YumaInaura/received_events",
    "type": "User",
    "site_admin": false
  },
  "labels": [],
  "state": "open",
  "locked": false,
  "assignee": null,
  "assignees": [],
  "milestone": null,
  "comments": 0,
  "created_at": "2018-12-29T04:13:31Z",
  "updated_at": "2018-12-29T04:13:31Z",
  "closed_at": null,
  "author_association": "OWNER",
  "body": "# バスはどれ?\r\n\r\nわからないぜ。\r\n\r\n![image](https://user-images.githubusercontent.com/13635059/50533325-bdc8c080-0b6a-11e9-8654-0d07c3a5900e.png)\r\n\r\n![image](https://user-images.githubusercontent.com/13635059/50533324-b99ca300-0b6a-11e9-9d66-2a3861ebe251.png)\r\n\r\n![image](https://user-images.githubusercontent.com/13635059/50533331-db962580-0b6a-11e9-8300-856beaee6a11.png)\r\n\r\n\r\n#ReCaptcha Qiita\r\n\r\nhttps://qiita.com/amagasu1234/items/9760c2c410776fd02e12\r\n\r\n# reCAPTCHA: Easy on Humans, Hard on Bots - Google\r\n\r\n人間に優しくボットに厳しく。\r\n\r\n\r\n![image](https://user-images.githubusercontent.com/13635059/50533349-2f087380-0b6b-11e9-9a4c-d261ce910e62.png)\r\n\r\n# 僕らは人間じゃなかったらしいな?\r\n\r\n# V3らしい\r\n\r\n![image](https://user-images.githubusercontent.com/13635059/50533353-3891db80-0b6b-11e9-9d17-ec8c58616ee3.png)\r\n\r\n\r\n# スコア制らしい\r\n\r\n![image](https://user-images.githubusercontent.com/13635059/50533356-4ba4ab80-0b6b-11e9-81ac-6d4de3375dc0.png)\r\n\r\n\r\n#フロントエンドはこれだけ!\r\n\r\n```js\r\n <script src=\"https://www.google.com/recaptcha/api.js?render=reCAPTCHA_site_key\"></script>\r\n  <script>\r\n  grecaptcha.ready(function() {\r\n      grecaptcha.execute('reCAPTCHA_site_key', {action: 'homepage'}).then(function(token) {\r\n         ...\r\n      });\r\n  });\r\n  </script>\r\n```\r\n\r\nすごすぎ。\r\n\r\nこれは採用したくなる。\r\n\r\nおそるべしGoogle\r\n\r\n#で、なぜ嫌いなの?\r\n\r\nローカライズ全然出来てない。\r\n日本人が理解する「バス」が分からない。\r\n画像のローカライズって大変そう。\r\nでも現状一番の選択肢なんだろうな、コスパ考えると。\r\n\r\n# 以上。\r\n\r\n誰かバスの見つけ方おしえてください。\r\n\r\n",
  "closed_by": null
}

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1