DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Mastering High-Risk GitHub Pull Requests: Review, Rollout Strategies, and Lessons Learned
  • Implementing ROS Communication Patterns
  • Code Search Using Retrieval Augmented Generation
  • GraalVM Features and Future

Trending

  • While Performing Dependency Selection, I Avoid the Loss Of Sleep From Node.js Libraries' Dangers
  • Beyond ChatGPT, AI Reasoning 2.0: Engineering AI Models With Human-Like Reasoning
  • Fixing Common Oracle Database Problems
  • Internal Developer Portals: Modern DevOps's Missing Piece
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. PyGitHub Quickstart Examples

PyGitHub Quickstart Examples

Helpful examples can make up for a lack of documentation. In this article, Chase Seibert shares some of his example code.

By 
Chase Seibert user avatar
Chase Seibert
·
Nov. 24, 16 · Opinion
Likes (1)
Comment
Save
Tweet
Share
9.9K Views

Join the DZone community and get the full member experience.

Join For Free

PyGitHub is the most popular GitHub API SDK for Python. Their documentation is very light on examples. They seem to think that this is fine. This makes for a prime candidate for the new Stack Overflow Documentation site!

In the meantime, I thought I would share my example code. These took me an hour of playing with the REPL to figure out.

Working With Pull Requests

The main challenge here was realizing that I needed to scope everything to my private org, not my user.

git = PyGithub('GITHUB_TOKEN')
org = git.get_organization('OrgName')
repo = org.get_repo('repo-name')
pr = repo.get_pull(1)
print 'PR author: %s' % pr.user.login
comments = pr.get_issue_comments()
for comment in comments:
  print 'Comment: ', comment.created_at, comment.user.login, comment.body
pr.create_issue_comment('Comment from GITHUB_TOKEN user') # aka git.get_user()

Getting the Contents of a File

From the default branch, not a particular pull request.

git = PyGithub('GITHUB_TOKEN')
org = git.get_organization('OrgName')
repo = org.get_repo('repo-name')
file_contents = repo.get_file_contents('path/to/file')

Listing the Members of a GitHub Team

There is no method to get a team by name, so you need to get them all and then pick out the one you want.

git = PyGithub('GITHUB_TOKEN')
org = git.get_organization('OrgName')
teams = org.get_teams()
team = [t for t in teams if t.name == 'TeamName'][0]  # assumes a match
print [m.login for m in team.get_members()]
Stack overflow pull requests teams GitHub Documentation Requests PRIME (PLC) Python (language) Branch (computer science)

Published at DZone with permission of Chase Seibert, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Mastering High-Risk GitHub Pull Requests: Review, Rollout Strategies, and Lessons Learned
  • Implementing ROS Communication Patterns
  • Code Search Using Retrieval Augmented Generation
  • GraalVM Features and Future

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!