From 8c794635d7b89ac04f67d7b175e5ca7311a55bde Mon Sep 17 00:00:00 2001 From: Josh Rosen Date: Mon, 1 Sep 2014 19:39:11 -0700 Subject: [PATCH] Auto-detect components based on changed files. Display issues under multiple components and add extra components. Closes #10. --- main.py | 10 ++++++++- sparkprs/models.py | 50 ++++++++++++++++++++++++++++---------------- templates/index.html | 10 ++++----- 3 files changed, 46 insertions(+), 24 deletions(-) diff --git a/main.py b/main.py index 4b9850d..e853030 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import json +from collections import defaultdict from dateutil.parser import parse as parse_datetime from dateutil import tz from datetime import datetime @@ -59,6 +60,13 @@ def main(): homepage = memcache.get("homepage", namespace=VERSION) if IS_DEV_APPSERVER or homepage is None: issues = Issue.query(Issue.state == "open").order(-Issue.updated_at).fetch() - homepage = render_template('index.html', session=session, issues=issues) + issues_by_component = defaultdict(list) + for issue in issues: + for component in issue.components: + issues_by_component[component].append(issue) + # Display the groups in the order listed in Issues._components + grouped_issues = [(c[0], issues_by_component[c[0]]) for c in Issue._components] + homepage = render_template('index.html', session=session, + grouped_issues=grouped_issues) memcache.set("homepage", value=homepage, time=60, namespace=VERSION) return homepage diff --git a/sparkprs/models.py b/sparkprs/models.py index 5e39152..d05c360 100644 --- a/sparkprs/models.py +++ b/sparkprs/models.py @@ -4,6 +4,7 @@ from github_api import raw_request, PULLS_BASE, ISSUES_BASE import json import logging +import re from sparkprs.utils import parse_pr_title, is_jenkins_command, contains_jenkins_command @@ -43,25 +44,38 @@ class Issue(ndb.Model): TAG_REGEX = r"\[[^\]]*\]" + _components = [ + # (name, pr_title_regex, filename_regex) + ("Core", "core", "^core/"), + ("Python", "python|pyspark", "python"), + ("YARN", "yarn", "yarn"), + ("Mesos", "mesos", "mesos"), + ("Web UI", "webui|(web ui)", "spark/ui/"), + ("Build", "build", "(pom\.xml)|project"), + ("Docs", "docs", "docs|README"), + ("EC2", "ec2", "ec2"), + ("SQL", "sql", "sql"), + ("MLlib", "mllib", "mllib"), + ("GraphX", "graphx|pregel", "graphx"), + ("Streaming", "stream|flume|kafka|twitter|zeromq", "streaming"), + ] + @property - def component(self): - # TODO: support multiple components - title = ((self.pr_json and self.pr_json["title"]) or self.title).lower() - if "sql" in title: - return "SQL" - elif "mllib" in title: - return "MLlib" - elif "graphx" in title or "pregel" in title: - return "GraphX" - elif "yarn" in title: - return "YARN" - elif ("stream" in title or "flume" in title or "kafka" in title - or "twitter" in title or "zeromq" in title): - return "Streaming" - elif "python" in title or "pyspark" in title: - return "Python" - else: - return "Core" + def components(self): + """ + Returns the list of components used to classify this pull request. + + Components are identified automatically based on the files that the pull request + modified and any tags added to the pull request's title (such as [GraphX]). + """ + components = [] + title = ((self.pr_json and self.pr_json["title"]) or self.title) + modified_files = [f["filename"] for f in (self.files_json or [])] + for (component_name, pr_title_regex, filename_regex) in Issue._components: + if re.search(pr_title_regex, title, re.IGNORECASE) or \ + any(re.search(filename_regex, f, re.I) for f in modified_files): + components.append(component_name) + return components or ["Core"] @property def parsed_title(self): diff --git a/templates/index.html b/templates/index.html index 4669100..f8264d6 100644 --- a/templates/index.html +++ b/templates/index.html @@ -35,18 +35,18 @@

Spark Pull Requests

- {% for group in issues | groupby('component') %} + {% for (component, issues) in grouped_issues %}
+ id="{{component | replace(' ', '')}}"> @@ -59,7 +59,7 @@

Spark Pull Requests

- {% for issue in group.list %} + {% for issue in issues %}
Number Jenkins Updated