-
Notifications
You must be signed in to change notification settings - Fork 4
Large rework to enable sending pull requests as user. #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mithro
wants to merge
1
commit into
The-OpenROAD-Project:main
Choose a base branch
from
mithro:github-apps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| *-build | ||
| *.pem |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Copyright 2021 OpenROAD Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| include common/config.mk | ||
|
|
||
| APPS=pull-request-sender pull-request-sender-auth-check | ||
|
|
||
| env: | ||
| virtualenv env | ||
| source env/bin/activate; pip install -r pull-request-sender/requirements.txt | ||
| source env/bin/activate; pip install -r pull-request-sender-auth-check/requirements.txt | ||
|
|
||
| enter: | ||
| source env/bin/activate; bash | ||
|
|
||
| build: | ||
| for A in $(APPS); do (cd $$A; make build); done | ||
|
|
||
| deploy: | ||
| make build | ||
| (cd common; yes | gcloud --project=$(PROJECT_ID) datastore indexes create index.yaml) | ||
| for A in $(APPS); do (cd $$A; make deploy); done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Dockerfile | ||
| README.md | ||
| *.pyc | ||
| *.pyo | ||
| *.pyd | ||
| __pycache__ | ||
| .pytest_cache |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Use the official lightweight Python image. | ||
| # https://hub.docker.com/_/python | ||
| FROM python:3.9-slim | ||
|
|
||
| # Allow statements and log messages to immediately appear in the Knative logs | ||
| ENV PYTHONUNBUFFERED True | ||
|
|
||
| # Copy local code to the container image. | ||
| ENV APP_HOME /app | ||
| WORKDIR $APP_HOME | ||
| COPY . ./ | ||
| RUN find | sort | ||
| RUN mkdir /keys | ||
|
|
||
| # Install production dependencies. | ||
| RUN pip install -r requirements.txt | ||
|
|
||
| # Run the web service on container startup. Here we use the gunicorn | ||
| # webserver, with one worker process and 8 threads. | ||
| # For environments with multiple CPU cores, increase the number of workers | ||
| # to be equal to the cores available. | ||
| # Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling. | ||
| CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 app:app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Copyright 2021 OpenROAD Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| PROJECT_ID=openroad-robot | ||
| REGION=us-central1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| #!/usr/bin/env python3 | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright 2021 OpenROAD Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
|
|
||
| import datetime | ||
| import pprint | ||
| import requests | ||
| import urllib | ||
|
|
||
|
|
||
| from google.cloud import ndb | ||
|
|
||
|
|
||
| class Token(ndb.Model): | ||
| login = ndb.StringProperty(indexed=True, required=True) | ||
| access_token = ndb.StringProperty(required=True) | ||
| expires_in = ndb.IntegerProperty(required=True) | ||
| refresh_token = ndb.StringProperty(required=True) | ||
| refresh_token_expires_in = ndb.IntegerProperty(required=True) | ||
| token_type = ndb.StringProperty(required=True) | ||
| updated = ndb.DateTimeProperty(auto_now=True) | ||
| created = ndb.DateTimeProperty(auto_now_add=True) | ||
|
|
||
| def to_table(self): | ||
| c = (datetime.datetime.utcnow() - self.created).seconds | ||
| u = (datetime.datetime.utcnow() - self.updated).seconds | ||
| ein = self.created + datetime.timedelta(seconds=self.expires_in) | ||
| rin = self.created + datetime.timedelta(seconds=self.refresh_token_expires_in) | ||
| return f"""\ | ||
| <table> | ||
| <tr><th>Login </th><td>{self.login} </td><td> </td></tr> | ||
| <tr><th>Created </th><td>{c}s ago </td><td>{self.created}</td></tr> | ||
| <tr><th>Last updated </th><td>{u}s ago </td><td>{self.updated}</td></tr> | ||
| <tr><th>Auth Expires In </th><td>t + {self.expires_in}s </td><td>{ein} </td></tr> | ||
| <tr><th>Refresh Expires In</th><td>t + {self.refresh_token_expires_in}s</td><td>{rin} </td></tr> | ||
| <tr><th>Type </th><td>{self.token_type} </td><td> </td></tr> | ||
| </table> | ||
| """ | ||
|
|
||
| def to_html(self): | ||
| return f"""\ | ||
| <html> | ||
| <body> | ||
| {self.to_table()} | ||
| </body> | ||
| </html> | ||
| """ | ||
|
|
||
| @classmethod | ||
| def latest(cls, login): | ||
| with client.context(): | ||
| q = cls.query().filter(cls.login==login).order(-cls.created) | ||
| for t in q: | ||
| return t | ||
|
|
||
| @classmethod | ||
| def delete(cls, login): | ||
| with client.context(): | ||
| q = cls.query().filter(cls.login==login).order(-cls.created) | ||
| for t in q: | ||
| t.key.delete() | ||
|
|
||
| @classmethod | ||
| def from_response(cls, login, d): | ||
| od = dict(urllib.parse.parse_qsl(d.text)) | ||
|
|
||
| if 'error' in od: | ||
| ods = pprint.pformat(od) | ||
| return f"""\ | ||
| <html> | ||
| <body> | ||
| <a href="{od['error_uri']}">{od['error_description']}</a> | ||
| <br> | ||
| <pre>{ods}</pre> | ||
| </body> | ||
| </html> | ||
| """ | ||
| # Use the token to figure out the username of the user associated with the | ||
| # token. | ||
| headers = { | ||
| "Accept": "application/vnd.github.v3+json", | ||
| "Authorization": f"{od['token_type']} {od['access_token']}", | ||
| } | ||
| ud = requests.get( | ||
| url="https://api.github.com/user", | ||
| headers=headers, | ||
| ).json() | ||
| assert ud['login'] == login, (ud['login'], login) | ||
|
|
||
| od['login'] = login | ||
| return cls.from_json(od) | ||
|
|
||
| @classmethod | ||
| def from_json(cls, od): | ||
| assert 'access_token' in od, od | ||
| assert 'token_type' in od, od | ||
| assert 'expires_in' in od, od | ||
| od['expires_in'] = int(od['expires_in']) | ||
| assert 'refresh_token' in od, od | ||
| assert 'refresh_token_expires_in' in od, od | ||
| od['refresh_token_expires_in'] = int(od['refresh_token_expires_in']) | ||
| return cls(**od) | ||
|
|
||
|
|
||
| client = ndb.Client() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Copyright 2021 OpenROAD Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| MAKE_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) | ||
|
|
||
| include $(MAKE_DIR)/config.mk | ||
|
|
||
| SRCS=\ | ||
| ../common/Dockerfile \ | ||
| ../common/.dockerignore \ | ||
| ../common/db.py \ | ||
| ../common/utils.py \ | ||
| *.py \ | ||
| *.txt \ | ||
| ../../github_api | ||
|
|
||
| PYTHONPATH=$(abspath $(PWD)/../common):$(abspath $(PWD)/../../) | ||
| export PYTHONPATH | ||
|
|
||
| BUILD_DIR=$(PROJECT_NAME)-build | ||
|
|
||
| build: | ||
| rm -rf $(BUILD_DIR) | ||
| mkdir $(BUILD_DIR) | ||
| cp -a $(SRCS) ./$(BUILD_DIR)/ | ||
| find $(BUILD_DIR) -name '*.pem' -delete | ||
| find $(BUILD_DIR) -name '*.pyc' -delete | ||
| find $(BUILD_DIR) -name '.*.sw*' -delete | ||
| find $(BUILD_DIR) -type d -empty -delete | ||
|
Comment on lines
+36
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these steps be extracted into a generic target named clean? |
||
| find $(BUILD_DIR) | sort | ||
| cd $(BUILD_DIR); gcloud --project=$(PROJECT_ID) \ | ||
| builds submit \ | ||
| --tag gcr.io/$(PROJECT_ID)/$(PROJECT_NAME) | ||
|
|
||
| .PHONY: build | ||
|
|
||
| SECRETS_ENV=CLIENT_ID CLIENT_SECRET APP_ID | ||
| SECRETS_CENV=CLIENT_TOKEN | ||
|
|
||
| SECRETS_CMDLINE_ENV=$(shell echo $(SECRETS_ENV) | sed -e's/\([^ ]\+\) \?/\1=$(SECRETS_PREFIX)_\1:latest,/g' -e's/,$$//') | ||
| SECRETS_CMDLINE_CENV=$(shell echo $(SECRETS_CENV) | sed -e's/\([^ ]\+\) \?/,\1=COMMON_\1:latest,/g' -e's/,$$//') | ||
| SECRETS_CMDLINE_PEM=,/keys/app.private-key.pem=$(SECRETS_PREFIX)_CLIENT_KEY:latest | ||
|
|
||
| deploy: | ||
| gcloud --project=$(PROJECT_ID) beta \ | ||
| run deploy \ | ||
| $(PROJECT_NAME) \ | ||
| --image gcr.io/$(PROJECT_ID)/$(PROJECT_NAME) \ | ||
| --platform managed --region=$(REGION) \ | ||
| --allow-unauthenticated \ | ||
| --set-env-vars PROJECT_ID=$(PROJECT_ID),CLIENT_KEY=/keys/app.private-key.pem \ | ||
| --service-account=$(SERVICE_ACCOUNT)@$(PROJECT_ID).iam.gserviceaccount.com \ | ||
| --set-secrets=$(SECRETS_CMDLINE_ENV)$(SECRETS_CMDLINE_CENV)$(SECRETS_CMDLINE_PEM) | ||
|
|
||
| .PHONY: deploy | ||
|
|
||
| DATASTORE_EMULATOR_HOST=localhost:8081 | ||
| db: | ||
| gcloud beta emulators datastore start | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| indexes: | ||
| - kind: Token | ||
| properties: | ||
| - name: login | ||
| - name: created | ||
| direction: desc |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these variable names should not be abbreviated.
From the python style guide.
Function names, variable names, and filenames should be descriptive; eschew abbreviation. In particular, do not use abbreviations that are ambiguous or unfamiliar to readers outside your project, and do not abbreviate by deleting letters within a word.