Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Add a "snooze" label to an issue, and github-snooze-button will remove the label
* a pull request receives a comment on a diff, or
* a pull request branch is updated.

github-snooze-button can operate in two modes: deployed to AWS Lambda, or polling a Amazon SQS queue locally.
github-snooze-button runs on AWS Lambda.

## Configuration file

Expand Down Expand Up @@ -50,15 +50,6 @@ The AWS credentials in the config file are sent to Github and used to push notif

And now you're live.

## Option 2: Polling mode

1. Generate a Github authentication token with `public_repo` and `admin:repo_hook` scopes.
1. In AWS IAM, create a Amazon AWS user with all the AmazonSQS* and AmazonSNS* policies (and possibly fewer?)
1. Install github-snooze-button: `pip install git+https://github.com/tdsmith/github-snooze-button.git`
1. Launch with `snooze_listen /path/to/config.ini`

Note that the queue will continue collecting events unless you disconnect the repository from SNS.

## Teardown

The fastest way to disable github-snooze-button is by deleting the Amazon SNS service from your repository's "Webhooks & services" configuration page. It will be automatically recreated the next time you run snooze in either mode.
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5'
],
install_requires=['boto3', 'requests'],
install_requires=['boto3', 'requests', 'six'],
entry_points={
'console_scripts': [
'snooze_listen = snooze.snooze:main',
'snooze_deploy = snooze.deploy_lambda:main',
],
},
Expand Down
5 changes: 0 additions & 5 deletions snooze/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
# flake8:noqa
from .snooze import *
from .repository_listener import *
from .config import *
from .version import __version__
45 changes: 41 additions & 4 deletions snooze/deploy_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import argparse
import glob
import json
import logging
import os
import shutil
Expand All @@ -13,8 +14,11 @@
import boto3
from botocore.exceptions import ClientError
import pkg_resources
import requests
import six

import snooze
from .config import parse_config
from .constants import GITHUB_HEADERS, LISTEN_EVENTS


LAMBDA_ROLE_TRUST_POLICY = """\
Expand Down Expand Up @@ -57,6 +61,39 @@ def create_or_get_lambda_role():
return role


def connect_github_to_sns(aws_key, aws_secret, aws_region,
github_username, github_token, repository_name,
sns_topic_arn, events, **_):
"""Connects a Github repository to a SNS topic.

Args:
sns_topic_arn: ARN of an existing SNS topic
events (list<str> | str): Github webhook events to monitor for
activity, from https://developer.github.com/webhooks/#events.

Returns: None
"""
auth = requests.auth.HTTPBasicAuth(github_username, github_token)
if isinstance(events, six.string_types):
events = [events]
payload = {
"name": "amazonsns",
"config": {
"aws_key": aws_key,
"aws_secret": aws_secret,
"sns_topic": sns_topic_arn,
"sns_region": aws_region,
},
"events": events,
}
r = requests.post(
"https://api.github.com/repos/{}/hooks".format(repository_name),
data=json.dumps(payload),
headers=GITHUB_HEADERS,
auth=auth)
r.raise_for_status()


def create_deployment_packages(config):
"""Builds deployment packages for each configured repository.

Expand Down Expand Up @@ -171,7 +208,7 @@ def main():
parser.add_argument("config")
args = parser.parse_args()

config = snooze.parse_config(args.config)
config = parse_config(args.config)
create_deployment_packages(config)
iam_role = create_or_get_lambda_role()

Expand All @@ -180,9 +217,9 @@ def main():
# set up SNS topic and connect Github
sns = boto3.resource("sns", region_name=repo["aws_region"])
topic = sns.create_topic(Name=repository_name.replace("/", "__"))
snooze.connect_github_to_sns(
connect_github_to_sns(
sns_topic_arn=topic.arn,
events=snooze.constants.LISTEN_EVENTS,
events=LISTEN_EVENTS,
**repo)

# upload a Lambda package
Expand Down
172 changes: 0 additions & 172 deletions snooze/repository_listener.py

This file was deleted.

53 changes: 0 additions & 53 deletions snooze/snooze.py

This file was deleted.

Loading