Пример #1
0
    def get(self, url_path):
        def notify_admins(user, new_url):
            from google.appengine.api.mail import send_mail_to_admins
            mail = user.email()
            subject = "SymPy bot notification"
            body = "New upload URL " + new_url
            send_mail_to_admins(sender=mail, subject=subject, body=body)

        from google.appengine.api import users
        user = users.get_current_user()
        is_admin = users.is_current_user_admin()
        rows = []
        upload_url = ""
        if user:
            if is_admin:
                if self.request.get("generate"):
                    import sha
                    rand_string = os.urandom(10)
                    sha_hash = sha.new(rand_string)
                    new_record = UploadURL(url_path=sha_hash.hexdigest(),
                                           user=user.nickname())
                    new_record.put()
                    new_url = self.request.host_url + "/upload_pull/" + \
                        sha_hash.hexdigest()
                    notify_admins(user, new_url)
                if self.request.get("populate"):
                    taskqueue.add(url="/worker", queue_name="github")
                rows = UploadURL.all()
                last_row = rows.order("-created_at").get()
                if last_row:
                    upload_url = (last_row.url_path)
                else:
                    upload_url = ("")

        self.render(
            "upload_url.html", {
                "user": user,
                "upload_url": upload_url,
                "is_admin": is_admin,
                "rows": rows,
                "login_url": users.create_login_url("/upload_pull"),
                "logout_url": users.create_logout_url("/upload_pull"),
            })
Пример #2
0
    def get(self, url_path):

        def notify_admins(user, new_url):
            from google.appengine.api.mail import send_mail_to_admins
            mail = user.email()
            subject = "SymPy bot notification"
            body = "New upload URL " + new_url
            send_mail_to_admins(sender=mail, subject=subject, body=body)

        from google.appengine.api import users
        user = users.get_current_user()
        is_admin = users.is_current_user_admin()
        rows = []
        upload_url = ""
        if user:
            if is_admin:
                if self.request.get("generate"):
                    import sha
                    rand_string = os.urandom(10)
                    sha_hash = sha.new(rand_string)
                    new_record = UploadURL(url_path=sha_hash.hexdigest(), user=user.nickname())
                    new_record.put()
                    new_url = self.request.host_url + "/upload_pull/" + \
                        sha_hash.hexdigest()
                    notify_admins(user, new_url)
                if self.request.get("populate"):
                    taskqueue.add(url="/worker", queue_name="github")
                rows = UploadURL.all()
                last_row = rows.order("-created_at").get()
                if last_row:
                    upload_url = (last_row.url_path)
                else:
                    upload_url = ("")

        self.render("upload_url.html", {"user": user,
                                        "upload_url": upload_url,
                                        "is_admin": is_admin,
                                        "rows": rows,
                                        "login_url": users.create_login_url("/upload_pull"),
                                        "logout_url": users.create_logout_url("/upload_pull"),
                                       }
                   )
Пример #3
0
 def post(self, url_path):
     last_row = UploadURL.all().order("-created_at").get()
     if last_row:
         if last_row.url_path == url_path:
             try:
                 payload = json.loads(self.request.get("payload"))
                 logging.info(payload)
             except json.JSONDecodeError:
                 self.error(400)
                 self.response.out.write("Incorrect request format\n")
             user_repo = payload["repository"]["full_name"]
             # Download complete pull request with information about mergeability
             pull_request = github_get_pull_request(user_repo,
                                                    payload["number"])
             num = payload["number"]
             # Get the old entity or create a new one:
             p = PullRequest.all()
             p.filter("num =", int(num))
             p = p.get()
             if p is None:
                 p = PullRequest(num=num)
             # Update all data that we can from GitHub:
             p.url = pull_request["html_url"]
             p.state = pull_request["state"]
             p.title = pull_request["title"]
             p.body = pull_request["body"]
             p.mergeable = pull_request["mergeable"]
             if pull_request["head"]["repo"]:
                 p.repo = pull_request["head"]["repo"]["url"]
             p.branch = pull_request["head"]["ref"]
             p.author_name = pull_request["user"].get("name", "")
             p.author_email = pull_request["user"].get("email", "")
             created_at = pull_request["created_at"]
             created_at = datetime.strptime(created_at,
                                            "%Y-%m-%dT%H:%M:%SZ")
             p.created_at = created_at
             u = User.all()
             u.filter("login ="******"user"]["login"])
             u = u.get()
             if u is None:
                 u = User(login=pull_request["user"]["login"])
                 u.id = pull_request["user"]["id"]
                 u.avatar_url = pull_request["user"]['avatar_url']
                 u.url = pull_request["user"]["url"]
                 u.put()
             p.author = u
             p.put()
         else:
             self.error(404)
             self.response.out.write("Requesting URL doesn't exist\n")
     else:
         self.error(500)
         self.response.out.write("URL for posting data not defined yet\n")
Пример #4
0
 def post(self, url_path):
     last_row = UploadURL.all().order("-created_at").get()
     if last_row:
         if last_row.url_path == url_path:
             try:
                 payload = json.loads(self.request.get("payload"))
                 logging.info(payload)
             except json.JSONDecodeError:
                 self.error(400)
                 self.response.out.write("Incorrect request format\n")
             user_repo = payload["repository"]["full_name"]
             # Download complete pull request with information about mergeability
             pull_request = github_get_pull_request(user_repo, payload["number"])
             num = payload["number"]
             # Get the old entity or create a new one:
             p = PullRequest.all()
             p.filter("num =", int(num))
             p = p.get()
             if p is None:
                 p = PullRequest(num=num)
             # Update all data that we can from GitHub:
             p.url = pull_request["html_url"]
             p.state = pull_request["state"]
             p.title = pull_request["title"]
             p.body = pull_request["body"]
             p.mergeable = pull_request["mergeable"]
             if pull_request["head"]["repo"]:
                 p.repo = pull_request["head"]["repo"]["url"]
             p.branch = pull_request["head"]["ref"]
             p.author_name = pull_request["user"].get("name", "")
             p.author_email = pull_request["user"].get("email", "")
             created_at = pull_request["created_at"]
             created_at = datetime.strptime(created_at, "%Y-%m-%dT%H:%M:%SZ")
             p.created_at = created_at
             u = User.all()
             u.filter("login ="******"user"]["login"])
             u = u.get()
             if u is None:
                 u = User(login=pull_request["user"]["login"])
                 u.id = pull_request["user"]["id"]
                 u.avatar_url = pull_request["user"]['avatar_url']
                 u.url = pull_request["user"]["url"]
                 u.put()
             p.author = u
             p.put()
         else:
             self.error(404)
             self.response.out.write("Requesting URL doesn't exist\n")
     else:
         self.error(500)
         self.response.out.write("URL for posting data not defined yet\n")