Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
GladeDiviney committed Mar 25, 2016
0 parents commit 88d4554
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.json
*.pyc
*.swp
15 changes: 15 additions & 0 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
runtime: python27
api_version: 1
threadsafe: true

skip_files:
- ^.*\.json
- ^dev/.*

handlers:
- url: /.*
script: zenchart.app

libraries:
- name: jinja2
version: latest
6 changes: 6 additions & 0 deletions base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body>
{% block body %}{% endblock %}
</body>
</html>
1 change: 1 addition & 0 deletions dev/devenv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$(echo $PATH|grep -q google_appengine) || export PATH=$PATH:~/bin/google_appengine
3 changes: 3 additions & 0 deletions dev/update
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
# ID from https://console.cloud.google.com/home/dashboard
appcfg.py -A zengraph-1260 -V v1 update .
23 changes: 23 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<html>
<body>
{% if repos %}
<h1>Repositories</h1>
<ul>
{% for repo in repos %}
<li><a href="{{repo.url()}}">{{repo.name}}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No repos found</p>
{% endif %}

<h1>Add a repo</h1>
<form action="/addRepo" method="post">
<div>Github Repository Name: <input type="text" name="repoName"></div>
<div>Github User Name: <input type="text" name="githubUser"></div>
<div>Github Access Token: <input type="text" name="githubToken"></div>
<div>Zenhub Access Token: <input type="text" name="zenhubToken"></div>
<div><input type="submit" value="Add"></div>
</form>
</body>
</html>
16 changes: 16 additions & 0 deletions index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
indexes:

# AUTOGENERATED

# This index.yaml is automatically updated whenever the dev_appserver
# detects that a new type of query is run. If you want to manage the
# index.yaml file manually, remove the above marker line (the line
# saying "# AUTOGENERATED"). If you want to manage some indexes
# manually, move them above the marker line. The index.yaml file is
# automatically uploaded to the admin console when you next deploy
# your application using appcfg.py.

- kind: Repo
ancestor: yes
properties:
- name: name
9 changes: 9 additions & 0 deletions repo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "base.html" %}
{% block body %}
<h1><a href="/">Home</a> >> {{ repo.name }}<h1>


<form action="{{ repo.url() + '/delete' }}" method="post">
<div><input type="submit" value="Delete this repo"></div>
<form>
{% endblock %}
71 changes: 71 additions & 0 deletions zenchart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/python
import os
import webapp2, jinja2, logging
import urllib, cgi
from google.appengine.ext import ndb

JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'],
autoescape=True)

# TODO: In the future this should come from the current user id
repoKey = ndb.Key('Repo', 'allrepos')

class Auth(ndb.Model):
zenhubToken = ndb.StringProperty()
githubUser = ndb.StringProperty()
githubToken = ndb.StringProperty()

class Issue(ndb.Model):
number = ndb.IntegerProperty(indexed=True)
repoName = ndb.StringProperty(indexed=True)
data = ndb.JsonProperty()
updated = ndb.DateTimeProperty(auto_now=True)

class Repo(ndb.Model):
auth = ndb.StructuredProperty(Auth)
name = ndb.StringProperty(indexed=True)
data = ndb.JsonProperty()
updated = ndb.DateTimeProperty(auto_now=True)
def url(self):
return '/repo/%s' % urllib.quote(str(self.key.id()), safe='')

class MainPage(webapp2.RequestHandler):
def get(self):
repos = Repo.query(ancestor = repoKey).order(Repo.name).fetch(50)
self.response.write(JINJA_ENVIRONMENT.get_template('index.html').render({'repos': repos}))

class AddRepo(webapp2.RequestHandler):
def post(self):
name = self.request.get('repoName')
repo = Repo(parent=repoKey)
repo.name = name
repo.auth = Auth()
repo.auth.zenhubToken = self.request.get('zenhubToken')
repo.auth.githubToken = self.request.get('githubToken')
repo.auth.githubUser = self.request.get('githubUser')
repo.put()
self.redirect(repo.url())

class RepoPage(webapp2.RequestHandler):
def get(self, id):
repo = Repo.get_by_id(int(id), parent=repoKey)
if not repo:
self.response.set_status(404)
else:
self.response.write(JINJA_ENVIRONMENT.get_template('repo.html').render({'repo': repo}))

class DeleteRepoPage(webapp2.RequestHandler):
def post(self, id):
repo = Repo.get_by_id(int(id), parent=repoKey)
if repo:
repo.key.delete()
self.redirect('/')

app = webapp2.WSGIApplication([
('/', MainPage),
('/addRepo', AddRepo),
webapp2.Route(r'/repo/<id:\d+>', RepoPage),
webapp2.Route(r'/repo/<id:\d+>/delete', DeleteRepoPage),
],debug=True)

0 comments on commit 88d4554

Please sign in to comment.