I am now able to commit messages to Github using their API.
pygit was overkill and I can do everything using requests/json with the API. Here is the code before it has been converted to micropython:
# coding=utf-8
"""
Writing this code in regular python before moving to micropython.
This code will handle putting commits up on Github for the Github connected Soldering Iron
"""
import json
import requests
GITHUB_OAUTH_TOKEN = "your_oauth_token_goes_here"
GITHUB_REPO_ADDRESS = "" # For example: "Cabalist/testSolder"
commit_message = "First try #2"
last_commit = requests.get("https://api.github.com/repos/{}/git/refs/heads/master".format(GITHUB_REPO_ADDRESS),
params={"access_token": GITHUB_OAUTH_TOKEN})
last_commit_sha = last_commit.json()['object']['sha']
r = requests.post("https://api.github.com/repos/{}/git/commits".format(GITHUB_REPO_ADDRESS),
params={"access_token": GITHUB_OAUTH_TOKEN},
json={"message": commit_message,
"parents": [last_commit_sha],
"tree": "4b825dc642cb6eb9a060e54bf8d69288fbee4904"}) # This is the empty folder SHA in git
commit_sha = r.json()['sha']
r2 = requests.patch("https://api.github.com/repos/{}/git/refs/heads/master".format(GITHUB_REPO_ADDRESS),
params={"access_token": GITHUB_OAUTH_TOKEN},
headers={'content-type': 'application/json'},
data=json.dumps({"sha": commit_sha, "force": True}))
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.