Skip to content

Commit 784ec52

Browse files
committed
Split GithubApp into it's own library, upgrade dependencies
1 parent f981b79 commit 784ec52

File tree

6 files changed

+54
-147
lines changed

6 files changed

+54
-147
lines changed

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
44

55
.PHONY: all fresh fulluninstall install dependencies clean
66

7-
all: dependencies
7+
all: application
88

99
fresh: clean dependencies
1010

@@ -16,6 +16,11 @@ dependencies:
1616
if [ ! -d $(ROOT_DIR)/venv ]; then python3 -m venv $(ROOT_DIR)/venv; fi
1717
source $(ROOT_DIR)/venv/bin/activate; yes w | pip install -e .
1818

19+
application:
20+
if [ ! -d $(ROOT_DIR)/venv ]; then python3 -m venv $(ROOT_DIR)/venv; fi
21+
source $(ROOT_DIR)/venv/bin/activate; yes w | pip install -r requirements.txt
22+
1923
clean:
20-
rm -rf $(ROOT_DIR)/env;
24+
rm -rf $(ROOT_DIR)/venv;
2125
rm -rf $(ROOT_DIR)/gitconsensusservice/*.pyc;
26+
rm -rf $(ROOT_DIR)/gitconsensusservice.egg-info;

gitconsensusservice/cli.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import click
2-
import re
3-
from gitconsensusservice.services import github
42
import yaml
5-
from gitconsensus.repository import Repository
3+
from gitconsensusservice import app
4+
from services.githubapp import gh
5+
from jobs import consensus
66

77

88
@click.group()
@@ -14,50 +14,48 @@ def cli(ctx):
1414

1515
@cli.command(short_help="List installation IDs available to this application.")
1616
def installs():
17-
installs = github.get_installations()
17+
installs = gh.get_installations()
1818
for install in installs:
1919
click.echo(install)
2020

2121

2222
@cli.command(short_help="List details about a specific installation.")
2323
@click.argument('install_id')
2424
def install(install_id):
25-
dump(github.get_installation(install_id))
25+
dump(get_githubapp_install(install_id).get_details())
2626

2727

2828
@cli.command(short_help="Get an authentication token for the provided installation.")
2929
@click.argument('install_id')
3030
def install_token(install_id):
31-
token = github.get_installation_token(install_id)
32-
click.echo(token)
31+
dump(get_githubapp_install(install_id).get_auth_token())
3332

3433

35-
@cli.command(short_help="Get an authentication token for the provided installation.")
34+
@cli.command(short_help="List all repositories for an installation.")
3635
@click.argument('install_id')
3736
def install_repos(install_id):
38-
token = github.get_installation_repositories(install_id)
39-
dump(token)
37+
dump(get_githubapp_install(install_id).get_repositories())
4038

4139

4240
@cli.command(short_help="List details about the current application.")
4341
def application():
44-
dump(github.get_app())
42+
dump(gh.get_app())
4543

4644

4745
@cli.command(short_help="Get JWT Authentication Token for this application.")
4846
def jwt():
49-
click.echo(github.get_jwt())
47+
click.echo(gh.get_jwt())
5048

5149

5250
@cli.command(short_help="List all open pull requests for the specific install and repository.")
5351
@click.argument('install_id')
5452
@click.argument('username')
5553
@click.argument('repository_name')
5654
def prs(install_id, username, repository_name):
57-
dump(github.list_prs(install_id, username, repository_name))
55+
dump(get_githubapp_install(install_id).list_prs(username, repository_name))
5856

5957

60-
@cli.command(short_help="Display detailed information about a specific pull request")
58+
@cli.command(short_help="Display detailed information about a specific pull request.")
6159
@click.argument('install_id')
6260
@click.argument('username')
6361
@click.argument('repository_name')
@@ -77,9 +75,18 @@ def pr(install_id, username, repository_name, pull_request):
7775
click.echo("Last Update: %s" % (request.hoursSinceLastUpdate(),))
7876

7977

78+
@cli.command(short_help="Process pull requests for all installations.")
79+
@click.option('--synchronous/--no-synchronous', default=True)
80+
def process(synchronous):
81+
consensus.process_installs(synchronous)
82+
83+
84+
def get_githubapp_install(install_id):
85+
return gh.get_installation(install_id)
86+
87+
8088
def get_repository(install_id, username, repository_name):
81-
client = github.get_github3_client(install_id)
82-
return Repository(username, repository_name, client)
89+
return get_githubapp_install(install_id).get_repository(username, repository_name)
8390

8491

8592
def dump(obj):

gitconsensusservice/services/github.py

Lines changed: 0 additions & 126 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from github3apps import GithubApp, GithubAppInstall
2+
from gitconsensus.repository import Repository
3+
from gitconsensusservice import app
4+
5+
6+
class GithubConsensusApp(GithubApp):
7+
def get_installation(self, installation_id):
8+
return GithubConsensusAppInstall(self, installation_id)
9+
10+
11+
class GithubConsensusAppInstall(GithubAppInstall):
12+
def get_repository(self, username, repository_name):
13+
client = self.get_github3_client()
14+
return Repository(username, repository_name, client)
15+
16+
17+
gh = GithubConsensusApp(app.config['GITHUB_APP_ID'], app.config['GITHUB_PRIVATE_KEY'])

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
asn1crypto==0.24.0
2+
celery==4.1.0
23
certifi==2018.1.18
34
cffi==1.11.4
45
chardet==3.0.4
56
click==5.1
67
cryptography==2.1.4
78
Flask==0.12.2
8-
gitconsensus==0.4.0
9-
-e [email protected]:tedivm/GitConsensusService.git@962d31e6154fa58964dd264038abb747e0aa1bd9#egg=gitconsensusservice
9+
gitconsensus=0.5.0
1010
github3.py==0.9.6
11+
github3apps.py==0.1.0
1112
idna==2.6
1213
itsdangerous==0.24
1314
Jinja2==2.10

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@
4444
],
4545

4646
install_requires=[
47-
'cryptography>=2.1.4,<3',
47+
'celery>=4.1,<5',
4848
'click>=5.0,<6.0',
49+
'cryptography>=2.1.4,<3',
4950
'Flask>=0.12.2',
51+
'gitconsensus>=0.5.0,<0.6'
5052
'github3.py>=0.9.6,<0.10',
53+
'github3apps.py>=0.1.0',
5154
'pyjwt>=1.5.3,<2',
5255
'PyYAML>=3.12,<3.13',
5356
'requests>=2.18.0,<2.19',

0 commit comments

Comments
 (0)