Skip to content

Commit

Permalink
Merge pull request #3 from mercari/update-error-handling
Browse files Browse the repository at this point in the history
Update error handling, installation id readme
  • Loading branch information
subodh101 committed Jul 29, 2021
2 parents da44074 + 88a56e6 commit 3cc9567
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.0
current_version = 0.1.1
commit = True
tag = False
message = github-token-app: {current_version} → {new_version}
Expand Down
10 changes: 9 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
Please read the CLA carefully before submitting your contribution to Mercari.
Under any circumstances, by submitting your contribution, you are deemed to accept and agree to be bound by the terms and conditions of the CLA.

https://www.mercari.com/cla/
https://www.mercari.com/cla/


## WHAT
(Write the change being made with this pull request)


## WHY
(Write the motivation why you submit this pull request)
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ pip install github-token-app
## What the code does?


1. The code is for authenticating a [github app as an installation](https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps#authenticating-as-an-installation). Installations are created from a Github app settings (Install App).
1. The code is for authenticating a [github app as an installation](https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps#authenticating-as-an-installation). Installations are created from a Github app settings (Install App).

2. The code contains `get_installations` function which can be called by CLI command `gta installations`. It returns a response of list of installations. The `id` attributes in the responses are the installation ids. Set the **INSTALLATION_ID** as environment variable based on your required access.
2. Under Install App, click on the account settings. You will find the installation ID in the URL https://github.com/apps/my-app-name/installations/**INSTALLATION_ID**. Set the **INSTALLATION_ID** as environment variable based on your required access.

Alternatively, the code contains `get_installations` function which can be called by CLI command `gta installations`. It returns a response of list of installations. The `id` attributes in the responses are the installation ids.

3. Finally, there are three methods read, write and write-pr. That generates token to perform respective actions to specific repositories.

Expand Down
28 changes: 17 additions & 11 deletions github_token_app/github_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,31 @@

def get_default_app():
if not hasattr(get_default_app, "app"):
pem_key = os.getenv("BASE64_PRIVATE_PEM_KEY")
pem_key = os.getenv("BASE64_PRIVATE_PEM_KEY", "")
if not pem_key:
raise RuntimeError("Missing Environment Variable: 'BASE64_PRIVATE_PEM_KEY'")

pem_key = base64.b64decode(pem_key)

app_id = os.getenv("GITHUB_APP_ID")
try:
app_id = int(app_id)
except ValueError:
raise ValueError(f"Invalid $GITHUB_APP_ID={app_id}, NOT a valid integer")
github_app_id = os.getenv("GITHUB_APP_ID", "")
if not github_app_id:
raise RuntimeError("Missing Environment Variable: 'GITHUB_APP_ID'")

installation_id = os.getenv("INSTALLATION_ID")
try:
installation_id = int(installation_id)
github_app_id = int(github_app_id)
except ValueError:
raise ValueError(f"Invalid $INSTALLATION_ID={installation_id}, NOT a valid integer")

get_default_app.app = GithubApp(app_id=app_id, private_pem_key=pem_key, installation_id=installation_id)
raise ValueError(f"Invalid $GITHUB_APP_ID={github_app_id}, NOT a valid integer")

installation_id = os.getenv("INSTALLATION_ID", "")
if not installation_id:
print("[Warning] Missing Environment Variable: 'INSTALLATION_ID'")
else:
try:
installation_id = int(installation_id)
except ValueError:
raise ValueError(f"Invalid $INSTALLATION_ID={installation_id}, NOT a valid integer")

get_default_app.app = GithubApp(app_id=github_app_id, private_pem_key=pem_key, installation_id=installation_id)

return get_default_app.app

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from setuptools import find_packages, setup

VERSION = "0.1.0"
VERSION = "0.1.1"


def generate_install_requires() -> List[str]:
Expand Down

0 comments on commit 3cc9567

Please sign in to comment.