Skip to content
This repository was archived by the owner on Mar 14, 2023. It is now read-only.

Commit b20a8aa

Browse files
committed
override the configs directory inside docker
1 parent 6957c09 commit b20a8aa

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ RUN pip install .
1717

1818
EXPOSE 80
1919
ENV HIGHFIVE_PORT 80
20+
ENV HIGHFIVE_CONFIG_DIR /highfive/highfive/configs
2021

2122
CMD highfive

highfive/app.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import waitress
1414

1515

16-
def create_app(config, webhook_secret=None):
16+
def create_app(config, webhook_secret=None, config_dir=None):
1717
app = flask.Flask(__name__)
1818

1919
# The canonical URL is /webhook, but other URLs are accepted for backward
@@ -41,7 +41,7 @@ def new_pr():
4141
except (KeyError, ValueError), _:
4242
return 'Error: missing or invalid payload\n', 400
4343
try:
44-
handler = HighfiveHandler(Payload(payload), config)
44+
handler = HighfiveHandler(Payload(payload), config, config_dir)
4545
return handler.run(flask.request.headers['X-GitHub-Event'])
4646
except UnsupportedRepoError:
4747
return 'Error: this repository is not configured!\n', 400
@@ -57,15 +57,16 @@ def index():
5757
@click.option('--port', default=8000)
5858
@click.option('--github-token', required=True)
5959
@click.option("--webhook-secret")
60-
def cli(port, github_token, webhook_secret):
60+
@click.option("--config-dir")
61+
def cli(port, github_token, webhook_secret, config_dir):
6162
try:
6263
config = Config(github_token)
6364
except InvalidTokenException:
6465
print 'error: invalid github token provided!'
6566
sys.exit(1)
6667
print 'Found a valid GitHub token for user @' + config.github_username
6768

68-
app = create_app(config, webhook_secret)
69+
app = create_app(config, webhook_secret, config_dir)
6970
waitress.serve(app, port=port)
7071

7172

highfive/newpr.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ class UnsupportedRepoError(IOError):
4747
pass
4848

4949
class HighfiveHandler(object):
50-
def __init__(self, payload, config):
50+
def __init__(self, payload, config, config_dir=None):
5151
self.payload = payload
5252

5353
self.integration_user = config.github_username
5454
self.integration_token = config.github_token
5555

56-
self.repo_config = self.load_repo_config()
56+
self.repo_config = self.load_repo_config(config_dir)
5757

58-
def load_repo_config(self):
58+
def load_repo_config(self, config_dir):
5959
'''Load the repository configuration.'''
6060
(org, repo) = self.payload['repository', 'full_name'].split('/')
6161
try:
62-
return self._load_json_file(os.path.join(org, repo) + '.json')
62+
return self._load_json_file(config_dir, os.path.join(org, repo) + '.json')
6363
except IOError:
6464
raise UnsupportedRepoError
6565

@@ -75,10 +75,11 @@ def run(self, event):
7575
else:
7676
return 'Unsupported webhook event.\n'
7777

78-
def _load_json_file(self, name):
79-
configs_dir = os.path.join(os.path.dirname(__file__), 'configs')
78+
def _load_json_file(self, config_dir, name):
79+
if not config_dir:
80+
config_dir = os.path.join(os.path.dirname(__file__), 'configs')
8081

81-
with open(os.path.join(configs_dir, name)) as config:
82+
with open(os.path.join(config_dir, name)) as config:
8283
return json.load(config)
8384

8485
def modifies_submodule(self, diff):

0 commit comments

Comments
 (0)