Skip to content

Commit

Permalink
Use GitHub API token (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaclarke committed Apr 21, 2021
1 parent 12573ba commit 646b630
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion conbench/entities/summary.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import decimal
import os

import flask as f
import marshmallow
Expand Down Expand Up @@ -91,7 +92,13 @@ def create(data):
if not commit:
name = repository.split("github.com/")[1]
url = f"https://api.github.com/repos/{name}/commits/{sha}"
response = requests.get(url)

token, session = os.getenv("GITHUB_API_TOKEN"), None
if token:
session = requests.Session()
session.headers = {"Authorization": f"Bearer {token}"}

response = session.get(url) if session else requests.get(url)
github = parse_commit(response.json())
commit = Commit.create(
{
Expand Down
10 changes: 9 additions & 1 deletion migrations/versions/662175f2e6c6_backfill_parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Create Date: 2021-04-21 09:23:28.589522
"""
import os

from alembic import op
import requests

Expand All @@ -23,12 +25,18 @@ def upgrade():
commit_table = Commit.__table__
connection = op.get_bind()

token, session = os.getenv("GITHUB_API_TOKEN"), None
if token:
session = requests.Session()
session.headers = {"Authorization": f"Bearer {token}"}

commits = connection.execute(
commit_table.select().where(commit_table.c.parent == None) # noqa
)

for commit in commits:
url = f"https://api.github.com/repos/apache/arrow/commits/{commit.sha}"
response = requests.get(url)
response = session.get(url) if session else requests.get(url)
parent = response.json()["parents"][0]["sha"]
connection.execute(
commit_table.update()
Expand Down

0 comments on commit 646b630

Please sign in to comment.