Skip to content

Instantly share code, notes, and snippets.

Avatar

Grant McConnaughey grantmcconnaughey

View GitHub Profile
View lintly-with-arguments.yaml
- uses: grantmcconnaughey/lintly-flake8-github-action@v1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
failIf: any
args: "--ignore=E121,E123 ."
@grantmcconnaughey
grantmcconnaughey / views.py
Last active May 2, 2019
Handling GitHub webhooks with Django
View views.py
import hashlib
import hmac
import httplib
import json
from django.conf import settings
from django.http import HttpResponse, HttpResponseForbidden
from django.views.decorators.csrf import csrf_exempt
View get_projects_v2.py
# This dict lives in its own file
git_clients = {
GITHUB: GitHubBackend,
DUMMY: DummyGitBackend
}
def get_projects(self, service):
# Dynamic based on the service
GitBackend = git_clients[service]
git_client = GitBackend(user=self)
View get_projects.py
def get_projects(self):
client = Github(self.access_token)
owner_logins = set(org.login for org in client.get_user().get_orgs())
owner_logins.add(self.username)
return Project.objects.filter(owner__login__in=owner_logins)
View add_projects_v2.html
<a href="{% url "project:add_projects" service %}" class="btn btn-primary">
<em class="icon-plus"></em> Add Projects
</a>
View service_context_processor.py
# Future git services will go here
GITHUB = 'gh'
DUMMY = 'dummy'
def service(request):
services = (GITHUB, DUMMY)
the_service = None
for _service in services:
if request.path.startswith('/{}/'.format(_service)):
the_service = _service
View add_projects.html
<a href="{% url "project:add_projects" "gh" %}" class="btn btn-primary">
<em class="icon-plus"></em> Add Projects
</a>
View dashboard.py
@login_required
def dashboard(request, service):
projects = request.user.get_projects(service)
return render(request, 'project/dashboard.html', {'projects': projects})
View lint_project_v2.py
def __init__(self):
self.linter = self.get_linter()
def lint_entire_project(self):
"""Lints the local repo and returns the violations found."""
self.state = BUILD_RUNNING
self.save()
violations = self.linter.lint()
View lint_project_v1.py
def lint_entire_project(self, local_repo_path):
"""Runs quality checks on the local repo and returns the output as a string."""
self.state = BUILD_RUNNING
self.save()
process = subprocess.Popen(['flake8', local_repo_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False)
You can’t perform that action at this time.