diff --git a/.env.sample b/.env.sample index c381797..29c0208 100644 --- a/.env.sample +++ b/.env.sample @@ -11,6 +11,7 @@ GH_SECRET=moresecrets GH_ORG=29205 GH_ORG_NAME=localytics GH_REPOS=repo1,repo2 +GH_COMMENT=true LANGS=rb,js;rb MODE=proxy MONGO_URI=mongodb://heroku_appxyz:abcd@ds031978.mongolab.com:31978/heroku_appxyz diff --git a/app.json b/app.json index b286f75..a00c77d 100644 --- a/app.json +++ b/app.json @@ -43,6 +43,10 @@ "GH_REPOS": { "description": "Comma-separated Github repo names to track coverage for" }, + "GH_COMMENT": { + "description": "Whether to comment on GitHub PRs", + "value": "true" + }, "LANGS": { "description": "Comma-separated language file extensions (such as rb,js) to collect coverage for (semicolon-separated for multiple repos, one per repo)" }, diff --git a/app.py b/app.py index e4bd89b..4b0773d 100644 --- a/app.py +++ b/app.py @@ -18,10 +18,12 @@ LANGS = dict(zip(constants.get('GH_REPOS').split(','), constants.get('LANGS').split(';'))) CURRENT = dict(zip(constants.get('GH_REPOS').split(','), constants.get('CURRENT').split(';'))) -try: - s3 = S3(constants.get('AWS_ACCESS_KEY'), constants.get('AWS_SECRET_KEY'), constants.get('AWS_BUCKET')) -except: - s3 = None +s3 = None +if constants.get('GH_COMMENT').lower() == 'true': + try: + s3 = S3(constants.get('AWS_ACCESS_KEY'), constants.get('AWS_SECRET_KEY'), constants.get('AWS_BUCKET')) + except: + pass collections = zip(constants.get('GH_REPOS').split(','), constants.get('STORAGE_COLLECTIONS').split(',')) storages = {} @@ -50,7 +52,7 @@ def preprocess_request(): return redirect(url_for('login_view')) if session.get('next'): return redirect(session.pop('next')) - if not s3: + if constants.get('GH_COMMENT').lower() == 'true' and not s3: flash('Your S3 keys are invalid!', 'danger') return 'Your S3 keys are invalid!' diff --git a/helpers/githubbot.py b/helpers/githubbot.py index 9a5e778..9b86e7f 100644 --- a/helpers/githubbot.py +++ b/helpers/githubbot.py @@ -14,6 +14,7 @@ def __init__(self, constants, repo_name, langs, current): self.current = current.split(',') self.constants = constants self.cache = defaultdict(dict) + self.post_comments = constants.get('GH_COMMENT').lower() == 'true' def past_comment(self, pr): cached = self.cache['comments'].get(pr.id) @@ -96,6 +97,9 @@ def comment(self, pull_request_id, message, url, args, storage, coverage_diffs, self.post_comment(body, pr) def post_comment(self, body, pr): + if not self.post_comments: + return + past_comment = self.past_comment(pr) if past_comment: past_comment.edit(body)