Issue Code Examples

Examples usingIssues

Administering Issues

Let’s assume you have your username and password stored inuser andpwrespectively, you have your repository name stored inrepo, and the numberof the issue you’re concerned with innum.

fromgithub3importlogingh=login(user,pw)issue=gh.issue(user,repo,num)ifissue.is_closed():issue.reopen()issue.edit('New issue title',issue.body+'\n------\n**Update:** Text to append')

Closing and Commenting on Issues

# Assuming issue is the same as above ...issue.create_comment('This should be fixed in 6d4oe5. Closing as fixed.')issue.close()

Example issue to comment on

If you would like to test the above, seeissue #108. Justfollow the code there and fill in your username, password (or token), andcomment message. Then run the script and watch as the issue opens in yourbrowser focusing on the commentyou just created.

The following shows how you could use github3.py to fetch and display yourissues in your own style and in your web browser.

importtempfileimportwebbrowserimportgithub3template="""<html><head></head><body>{0}</body></html>"""i=github3.issue("kennethreitz","requests",868)withtempfile.NamedTemporaryFile()astmpfd:tmpfd.write(template.format(i.body_html))webbrowser.open("file://"+tmpfd.name)

Or how to do the same by wrapping the lines in your terminal.

importtextwrapimportgithub3i=github3.issue("kennethreitz","requests",868)forlineintextwrap.wrap(i.body_text,78,replace_whitespace=False):print(line)

Importing an issue

Not only can you create new issues, but you can import existing ones. Whenimporting, you preserve the timestamp creation date; you can preserve thetimestamp(s) for comment(s) too.

importgithub3gh=github3.login(token=token)issue={'title':'Documentation issue','body':'Missing links in index.html','created_at':'2011-03-11T17:00:40Z'}repository=gh.repository(user,repo)repository.import_issue(**issue)

Status of imported issue

Here’s how to check the status of the imported issue.

importgithub3issue=repository.imported_issue(issue_num)print(issue.status)