Skip to content

Commit

Permalink
Merge branch 'master' into remove-fb-from-footer
Browse files Browse the repository at this point in the history
  • Loading branch information
patjouk committed Jul 9, 2018
2 parents 413ce45 + f6929e5 commit 5bed242
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 4 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,14 @@ Using the `static` tag in templates is supposed both in Django and Mezzanine, bu

### Deployment

### Review Apps
#### Review Apps

Opening a PR will automatically create a Review App in the `foundation-site` pipeline. It's not possible to use OAuth but you can still access the admin with `admin` as the username. To get the password, you need to go to the Heroku dashboard, click on the menu button next to your Review App and select `View initial app setup...`. The password is in the `Run scripts & scale dynos` log.
Opening a PR will automatically create a Review App in the `foundation-site` pipeline. It's not possible to use OAuth but you can still access the admin with `admin` as the username. Login are published in the `mofo-review-apps` Slack channel when the review app is ready.

##### Environment Variables

- `GITHUB_TOKEN`: GITHUB API authentication,
- `SLACK_WEBHOOK_RA`: Webhook to `mofo-review-apps`

#### Staging

Expand Down
6 changes: 6 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
"AWS_STORAGE_BUCKET_NAME": {
"required": true
},
"GITHUB_TOKEN": {
"required": true
},
"SLACK_WEBHOOK_RA": {
"required": true
},
"DEBUG": "False",
"CORS_WHITELIST": "*",
"XSS_PROTECTION": "True",
Expand Down
6 changes: 6 additions & 0 deletions env.default
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ CSP_CONNECT_SRC=*
CSP_MEDIA_SRC="'self'"
CSP_CHILD_SRC='self' https://www.youtube.com/ https://s3.amazonaws.com/
CSP_FORM_ACTION='self' https://www.mozilla.org/en-US/newsletter/


# REVIEW APPS SLACK BOT

GITHUB_TOKEN=""
SLACK_WEBHOOK_RA=""
60 changes: 58 additions & 2 deletions network-api/networkapi/management/commands/review_app_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
from django.core.management.base import BaseCommand
from factory import Faker
from django.contrib.auth.models import User
from django.conf import settings
import re

import requests


class Command(BaseCommand):
Expand All @@ -14,7 +18,7 @@ class Command(BaseCommand):
def handle(self, *args, **options):
try:
User.objects.get(username='admin')
self.stdout.write('super user already exists')
print('super user already exists')
except ObjectDoesNotExist:
password = Faker(
'password',
Expand All @@ -25,4 +29,56 @@ def handle(self, *args, **options):
lower_case=True
).generate({})
User.objects.create_superuser('admin', 'admin@example.com', password)
self.stdout.write(f'superuser created. Password: {password}')

reviewapp_name = settings.HEROKU_APP_NAME
m = re.search(r'\d+', reviewapp_name)
pr_number = m.group()

# Get PR's title from Github
token = settings.GITHUB_TOKEN
org = 'mozilla'
repo = 'foundation.mozilla.org'
r = requests.get(f'https://api.github.com/repos/{org}/{repo}/pulls/{pr_number}&access_token={token}')
try:
pr_title = ': ' + r.json()['title']
except KeyError:
pr_title = ''

slack_payload = {
'attachments': [
{
'fallback': 'New review app deployed: It will be ready in a minute!\n'
f'PR {pr_number}{pr_title}\n'
f'Login: admin\n'
f'Password: {password}\n'
f'URL: https://{reviewapp_name}.herokuapp.com',
'pretext': 'New review app deployed. It will be ready in a minute!',
'title': f'PR {pr_number}{pr_title}\n',
'text': 'Login: admin\n'
f'Password: {password}\n',
'color': '#7CD197',
'actions': [
{
'type': 'button',
'text': 'View review app',
'url': f'https://{reviewapp_name}.herokuapp.com'
},
{
'type': 'button',
'text': 'View PR on Github',
'url': f'https://github.com/mozilla/foundation.mozilla.org/pull/{pr_number}'
}
]
}
]
}

slack_webhook = settings.SLACK_WEBHOOK_RA
r = requests.post(f'{slack_webhook}',
json=slack_payload,
headers={'Content-Type': 'application/json'}
)

# Raise if post request was a 4xx or 5xx
r.raise_for_status()
print('Done!')
6 changes: 6 additions & 0 deletions network-api/networkapi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
USE_X_FORWARDED_HOST=(bool, False),
XSS_PROTECTION=bool,
REFERRER_HEADER_VALUE=(str, ''),
GITHUB_TOKEN=(str, ''),
SLACK_WEBHOOK_RA=(str, ''),
)

# Read in the environment
Expand Down Expand Up @@ -523,3 +525,7 @@ def show_toolbar(request):
DEBUG_TOOLBAR_CONFIG = {
"SHOW_TOOLBAR_CALLBACK": show_toolbar,
}

# Review apps' slack bot
GITHUB_TOKEN = env('GITHUB_TOKEN')
SLACK_WEBHOOK_RA = env('SLACK_WEBHOOK_RA')

0 comments on commit 5bed242

Please sign in to comment.