Skip to content

Instantly share code, notes, and snippets.

@ilovechai
Last active October 18, 2021 11:44
Show Gist options
  • Save ilovechai/9c3b976ea685df0fd39af9be22a413ec to your computer and use it in GitHub Desktop.
Save ilovechai/9c3b976ea685df0fd39af9be22a413ec to your computer and use it in GitHub Desktop.
Python script to comment on pull request
## Install PyGithub
!pip install PyGithub
from github import Github
import os
import sys
docker_image = 'Some docker build image with url'
build_url = os.environ.get('BUILD_URL')
git_commit = os.environ.get('GIT_COMMIT')
access_token = os.environ.get('SOME_CREDENTIAL')
g = Github(base_url="https://<hosturl>/api/v3", login_or_token=access_token)
repo = g.get_repo("<owner>/<repo>")
def add_message_to_commit_status():
## Add docker image id to commit status
repo.get_commit(sha=git_commit).create_status(
state="success",
target_url=build_url,
description=docker_image,
context="Docker Image")
def add_comment_to_pr(id):
issue = repo.get_issue(id)
issue.create_comment("Pushed docker image to: " + docker_image)
if __name__ == '__main__':
if len(sys.argv) == 2:
pull_request_id = sys.argv[1]
add_comment_to_pr(pull_request_id)
add_message_to_commit_status()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment