Skip to content

Commit

Permalink
Merge 8644eec into 6179165
Browse files Browse the repository at this point in the history
  • Loading branch information
bobholt authored Feb 3, 2017
2 parents 6179165 + 8644eec commit c348bd8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 161 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ notifications:
email:
on_success: never
on_failure: always
webhooks: https://w3c-test.org/prbuildbot.py
164 changes: 3 additions & 161 deletions check_stability.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
from __future__ import print_function

import argparse
import json
import logging
import os
import re
import stat
import subprocess
import sys
import tarfile
import traceback
import zipfile
from cStringIO import StringIO
from collections import defaultdict
from ConfigParser import RawConfigParser
from io import BytesIO
from urlparse import urljoin
from tools.manifest import manifest

import requests
Expand Down Expand Up @@ -109,126 +106,8 @@ def __exit__(self, type, value, traceback):
print("travis_fold:end:%s" % self.name, file=sys.stderr)


class GitHub(object):

"""Interface for the GitHub API."""

def __init__(self, org, repo, token, product):
"""Set properties required for communicating with GH API on self."""
self.token = token
self.headers = {"Accept": "application/vnd.github.v3+json"}
self.auth = (self.token, "x-oauth-basic")
self.org = org
self.repo = repo
self.base_url = "https://api.github.com/repos/%s/%s/" % (org, repo)
self.product = product

def _headers(self, headers):
"""Extend existing HTTP headers and return new value."""
if headers is None:
headers = {}
rv = self.headers.copy()
rv.update(headers)
return rv

def post(self, url, data, headers=None):
"""Serialize and POST data to given URL."""
logger.debug("POST %s" % url)
if data is not None:
data = json.dumps(data)
resp = requests.post(
url,
data=data,
headers=self._headers(headers),
auth=self.auth
)
resp.raise_for_status()
return resp

def patch(self, url, data, headers=None):
"""Serialize and PATCH data to given URL."""
logger.debug("PATCH %s" % url)
if data is not None:
data = json.dumps(data)
resp = requests.patch(
url,
data=data,
headers=self._headers(headers),
auth=self.auth
)
resp.raise_for_status()
return resp

def get(self, url, headers=None):
"""Execute GET request for given URL."""
logger.debug("GET %s" % url)
resp = requests.get(
url,
headers=self._headers(headers),
auth=self.auth
)
resp.raise_for_status()
return resp

def post_comment(self, issue_number, body):
"""Create or update comment in appropriate GitHub pull request comments."""
user = self.get(urljoin(self.base_url, "/user")).json()
issue_comments_url = urljoin(self.base_url, "issues/%s/comments" % issue_number)
comments = self.get(issue_comments_url).json()
title_line = format_comment_title(self.product)
data = {"body": body}
for comment in comments:
if (comment["user"]["login"] == user["login"] and
comment["body"].startswith(title_line)):
comment_url = urljoin(self.base_url, "issues/comments/%s" % comment["id"])
self.patch(comment_url, data)
break
else:
self.post(issue_comments_url, data)


class GitHubCommentHandler(logging.Handler):

"""GitHub pull request comment handler.
Subclasses logging.Handler to add ability to post comments to GitHub.
"""

def __init__(self, github, pull_number):
"""Extend logging.Handler and set required properties on self."""
logging.Handler.__init__(self)
self.github = github
self.pull_number = pull_number
self.log_data = []

def emit(self, record):
"""Format record and add to log"""
try:
msg = self.format(record)
self.log_data.append(msg)
except Exception:
self.handleError(record)

def send(self):
"""Post log to GitHub and flush log."""
self.github.post_comment(self.pull_number, "\n".join(self.log_data))
self.log_data = []


class Browser(object):

"""Base browser class that sets a reference to a GitHub token."""

product = None
binary = None

def __init__(self, github_token):
"""Set GitHub token property on self."""
self.github_token = github_token


class Firefox(Browser):

class Firefox(object):
"""Firefox-specific interface.
Includes installation, webdriver installation, and wptrunner setup methods.
Expand Down Expand Up @@ -295,7 +174,7 @@ def wptrunner_args(self, root):
}


class Chrome(Browser):
class Chrome(object):
"""Chrome-specific interface.
Includes installation, webdriver installation, and wptrunner setup methods.
Expand Down Expand Up @@ -400,28 +279,6 @@ def unzip(fileobj):
os.chmod(info.filename, perm)


def setup_github_logging(args):
"""Set up and return GitHub comment handler.
:param args: the parsed arguments passed to the script
"""
gh_handler = None
if args.comment_pr:
github = GitHub(args.user, "web-platform-tests", args.gh_token, args.product)
try:
pr_number = int(args.comment_pr)
except ValueError:
pass
else:
gh_handler = GitHubCommentHandler(github, pr_number)
gh_handler.setLevel(logging.INFO)
logger.debug("Setting up GitHub logging")
logger.addHandler(gh_handler)
else:
logger.warning("No PR number found; not posting to GitHub")
return gh_handler


class pwd(object):
"""Create context for temporarily changing present working directory."""
def __init__(self, dir):
Expand Down Expand Up @@ -695,10 +552,6 @@ def get_parser():
default=10,
type=int,
help="Number of times to run tests")
parser.add_argument("--gh-token",
action="store",
default=os.environ.get("GH_TOKEN"),
help="OAuth token to use for accessing GitHub api")
parser.add_argument("--comment-pr",
action="store",
default=os.environ.get("TRAVIS_PULL_REQUEST"),
Expand Down Expand Up @@ -733,12 +586,6 @@ def main():

os.chdir(args.root)

if args.gh_token:
gh_handler = setup_github_logging(args)
else:
logger.warning("Can't log to GitHub")
gh_handler = None

browser_name = args.product.split(":")[0]

with TravisFold("browser_setup"):
Expand Down Expand Up @@ -767,7 +614,7 @@ def main():
install_wptrunner()
do_delayed_imports()

browser = browser_cls(args.gh_token)
browser = browser_cls()
browser.install()
browser.install_webdriver()

Expand Down Expand Up @@ -823,11 +670,6 @@ def main():
else:
logger.info("No tests run.")

try:
if gh_handler:
gh_handler.send()
except Exception:
logger.error(traceback.format_exc())
return retcode


Expand Down
1 change: 1 addition & 0 deletions dom/collections/HTMLCollection-empty-name.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
assert_false("" in c, "Empty string should not be in the collection.");
assert_equals(c[""], undefined, "Named getter should return undefined for empty string.");
assert_equals(c.namedItem(""), null, "namedItem should return null for empty string.");
assert_equals(1, 1)
}, "Empty string as a name for Document.getElementsByTagName");

test(function() {
Expand Down
3 changes: 3 additions & 0 deletions lint.whitelist
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ TRAILING WHITESPACE:webgl/tools/*.patch
PRINT STATEMENT:check_stability.py
W3C-TEST.ORG:check_stability.py

# Travis
W3C-TEST.ORG:.travis.yml

# Git submodules are not currently scanned
*:tools/*
*:resources/*

0 comments on commit c348bd8

Please sign in to comment.