3

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 
Ian Stapleton Cordasco
  • 26,944
  • 4
  • 67
  • 72
Naim Salameh
  • 387
  • 4
  • 18
  • Could you share the code of #3 ? – joaumg Dec 09 '16 at 12:38
  • 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 I need the description of each pull request. ignore the sloppy code please I'm still in the learning phase. – Naim Salameh Dec 09 '16 at 13:07

1 Answers1

2

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!

Ian Stapleton Cordasco
  • 26,944
  • 4
  • 67
  • 72
  • ok so this seems to be the solution, one thing before I confirm it. if I do milestone=m.id I get an error: raise exceptions.error_for(response) github3.exceptions.UnprocessableEntity: 422 Validation Failed for it to work, I did milestones=5 for example, then I get exactly what I need. I could of course parse the m.json() to get the int required, is there anything else I can do other than m.id? – Naim Salameh Dec 10 '16 at 15:43
  • Sorry. I always get that confused. It's not `m.id` it's `m.number`. – Ian Stapleton Cordasco Dec 13 '16 at 20:54