Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub API get issues description using Python

The task: (using GitHub API) 1) get all closed milestones for a given repo 2) get all issues for that milestone 3) for every issue get it's description 4) finally, using Markdown for example, create a page for PM to view

I'm using Python 3.5, using lib github3.py, I got 1&2 but having trouble with #3. Looking at the GitHub documents, I'm not sure it supports retrieving the description of an issue.

I'm looking at this API document: https://developer.github.com/v3/issues

My question is, can #3 be done? Am I missing anything?

Thank you. What I have so far is this:

g = github3.login(token='123...')
r = g.repository(owner='owner', repository='services')
for m in r.milestones(state='closed'):
    print(m.as_json()) # this works giving me all the milestones
for i in r.issues(milestone=5, state='closed'):
    print(i.pull_request()) # works giving me all the pull requests from here 
like image 837
Naim Salameh Avatar asked Dec 12 '25 14:12

Naim Salameh


1 Answers

So the description of an issue is typically returned from the API in the body portion of the object.

The problem you might have (I haven't exercised this path before) is that the body might not be returned when you list the issues like that. If that's the case, then you will need to do something like:

for m in r.milestones(state='closed'):
    for i in r.issues(milestone=m.number, state='closed'):
         i.refresh()
         print(i.body)

It's worth noting, however, that the body you get there will be the body the user entered. If you wan to display it as HTML without rendering, github3.py requests that from the GitHub API for you automatically so then you could instead just access

i.body_html

Or if you wanted everything in plain-text

i.body_text

Cheers!

like image 111
Ian Stapleton Cordasco Avatar answered Dec 15 '25 12:12

Ian Stapleton Cordasco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!