Skip to content

Commit

Permalink
Add webhook for update repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
KuzenkovAG committed Jun 30, 2023
1 parent 423e33d commit 57b9ff5
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 3 deletions.
Empty file added hmom3/apps/webhooks/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions hmom3/apps/webhooks/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class WebhooksConfig(AppConfig):
name = 'apps.webhooks'
Empty file.
9 changes: 9 additions & 0 deletions hmom3/apps/webhooks/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path

from . import views

app_name = 'webhooks'

urlpatterns = [
path('pull/', views.pull_repo, name='pull'),
]
15 changes: 15 additions & 0 deletions hmom3/apps/webhooks/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import git
from django.http import HttpResponse
from django.conf import settings
from http import HTTPStatus


def pull_repo(request):
"""Get secret key, and pull repo to get changes from GitHub."""
secret = request.headers.get('X-Hub-Signature')
if request.method == 'POST' and secret == settings.SECRET_KEY:
repo = git.Repo('/home/momonline/hmom3')
origin = repo.remotes.origin
origin.pull()
return HttpResponse('Updated.', status=HTTPStatus.OK)
return HttpResponse('Wrong event.', status=HTTPStatus.BAD_REQUEST)
5 changes: 2 additions & 3 deletions hmom3/hmom3/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'apps.stats.apps.StatsConfig',
'apps.about.apps.AboutConfig',
'apps.market.apps.MarketConfig',
'apps.webhooks.apps.WebhooksConfig'
]

AUTH_USER_MODEL = 'users.User'
Expand Down Expand Up @@ -115,8 +116,7 @@
if DEBUG:
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
else:
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

STATIC_ROOT = os.path.join('/home/momonline/hmom3/static/')

# Login
LOGIN_URL = 'users:login'
Expand All @@ -133,7 +133,6 @@ def show_toolbar(request):
"SHOW_TOOLBAR_CALLBACK": show_toolbar,
}


"""Game balance settings."""
# Resources
DEF_GOLD_AMOUNT = 1000
Expand Down
1 change: 1 addition & 0 deletions hmom3/hmom3/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
path('statics/', include('apps.stats.urls', namespace='stats')),
path('about/', include('apps.about.urls', namespace='about')),
path('market/', include('apps.market.urls', namespace='market')),
path('hooks/', include('apps.webhooks.urls', namespace='webhooks')),
path('management/', admin.site.urls),
]

Expand Down

0 comments on commit 57b9ff5

Please sign in to comment.