Skip to content

Instantly share code, notes, and snippets.

@vanessaaleung
vanessaaleung / add_pr_label.py
Created May 2, 2021 23:11
Add Label to GitHub PR
def add_pr_label(owner: str, repo: str, token: str, pull_number: str) -> None:
url = "https://api.github.com/repos/{}/{}/issues/{}/labels".format(owner, repo, pull_number)
headers = {
"Authorization": "token {}".format(token),
"Content-Type": "application/json"
}
payload = {
"labels" : ["driver"]
}
@vanessaaleung
vanessaaleung / request_pr_review.py
Created May 2, 2021 23:10
Request GitHub PR Review
def request_pr_reviwer(owner: str, repo: str, token: str, pull_number: str, reviewers: list) -> None:
url = "https://api.github.com/repos/{}/{}/pulls/{}/requested_reviewers".format(owner, repo, pull_number)
headers = {
"Authorization": "token {}".format(token),
"Content-Type": "application/json"
}
payload = {
"reviewers" : reviewers
}
def create_pull_request(owner: str, repo: str, token: str, branch_name: str, new_branch: str, base: str) -> str:
"""Create a PR for the new branch, return the PR number"""
url = "https://api.github.com/repos/{}/{}/pulls".format(owner, repo)
headers = {
"Authorization": "token {}".format(token),
"Content-Type": "application/json"
}
payload = {
"head": new_branch,
def update_file_contents(owner: str, repo: str, token: str, new_branch: str, sha: str, path: str) -> None:
"""Update the file content and add a commit"""
url = "https://api.github.com/repos/{}/{}/contents/{}".format(owner, repo, path)
headers = {
"Authorization": "token {}".format(token),
"Content-Type": "application/json"
}
with open(os.path.join(os.path.dirname(__file__), "../..", path),'rb') as content:
b64_content = base64.b64encode(content.read())
@vanessaaleung
vanessaaleung / get_file_sha.py
Created May 2, 2021 23:08
GitHub Get File SHA
def get_file_sha(owner: str, repo: str, token: str, path: str) -> str:
"""Return the file's SHA for updating the file"""
url = "https://api.github.com/repos/{}/{}/contents/{}".format(owner, repo, path)
headers = {
"Authorization": "token {}".format(token),
"Content-Type": "application/json"
}
try:
response = requests.get(url, headers=headers)
@vanessaaleung
vanessaaleung / load_git_packages.py
Last active May 2, 2021 23:07
GitHub API packages
#!/usr/bin/env python3
import os
import sys
import logging
import requests
import json
import datetime
import base64
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
@vanessaaleung
vanessaaleung / create_branch.py
Created May 2, 2021 23:03
create_git_branch
def create_branch(owner: str, repo: str, token: str, base: str, new_branch: str) -> None:
"""Create a new branch"""
url = "https://api.github.com/repos/{}/{}/git/refs".format(owner, repo)
headers = {
"Authorization": "token {}".format(token),
"Content-Type": "application/json"
}
try:
get_response = requests.get(url+"/heads/"+base, headers=headers)
sf_merged.loc[sf_merged['Cluster Labels'] == 4, sf_merged.columns[[1] + list(range(5, sf_merged.shape[1]))]]
sf_merged.loc[sf_merged['Cluster Labels'] == 3, sf_merged.columns[[1] + list(range(5, sf_merged.shape[1]))]]
sf_merged.loc[sf_merged['Cluster Labels'] == 2, sf_merged.columns[[1] + list(range(5, sf_merged.shape[1]))]]