|
16 | 16 | HASHTAG_RE = re.compile("(?:^|\s)[##]{1}(\w+)", re.UNICODE) |
17 | 17 | MENTION_RE = re.compile("(?:^|\s)[@ @]{1}([^\s#<>[\]|{}]+)", re.UNICODE) |
18 | 18 |
|
| 19 | +_SECTION_TITLE_RE = re.compile("\/\*\s*(?P<section_title>.+)\s*\*\/" |
| 20 | + "(?P<real_summary>.*)", re.UNICODE) |
| 21 | + |
19 | 22 | NON_MAIN_NS = ['Talk', |
20 | 23 | 'User', |
21 | 24 | 'User talk', |
@@ -89,6 +92,28 @@ def parse_revs_from_url(url): |
89 | 92 | raise ValueError('unparsable url: %r' % (url,)) |
90 | 93 |
|
91 | 94 |
|
| 95 | +def parse_section_title(summary): |
| 96 | + """This function tries to extract the section title as it would be |
| 97 | + automatically generated into the commit message when a user clicks |
| 98 | + the edit button next to a section. The behavior is basically |
| 99 | + identical to MediaWiki's, which is to say that it is simple. If |
| 100 | + the commit message was generated otherwise or manually rewritten, |
| 101 | + this function will not automatically figure that out. |
| 102 | +
|
| 103 | + Returns a tuple of section_title and "real" commit message |
| 104 | + (message with the section title part removed). |
| 105 | + """ |
| 106 | + match = _SECTION_TITLE_RE.match(summary) |
| 107 | + if not match: |
| 108 | + return '', summary.strip() |
| 109 | + match_map = match.groupdict() |
| 110 | + section_title = match_map['section_title'] |
| 111 | + real_summary = match_map['real_summary'] |
| 112 | + section_title = section_title.strip() if section_title else '' |
| 113 | + real_summary = real_summary.strip() if real_summary else '' |
| 114 | + return section_title, real_summary |
| 115 | + |
| 116 | + |
92 | 117 | def parse_irc_message(message, ns_map=DEFAULT_NS_MAP): |
93 | 118 | ret = PARSE_EDIT_RE.match(message) |
94 | 119 | msg_dict = {'is_new': False, |
@@ -140,10 +165,13 @@ def parse_irc_message(message, ns_map=DEFAULT_NS_MAP): |
140 | 165 | msg_dict.setdefault('user', None) |
141 | 166 | msg_dict['is_anon'] = is_ip(msg_dict['user']) |
142 | 167 |
|
143 | | - if msg_dict['summary']: |
144 | | - msg_dict['hashtags'] = HASHTAG_RE.findall(msg_dict['summary']) |
145 | | - msg_dict['mentions'] = MENTION_RE.findall(msg_dict['summary']) |
| 168 | + summary = msg_dict['summary'] |
| 169 | + if summary: |
| 170 | + msg_dict['section'], msg_dict['parsed_summary'] = parse_section_title(summary) |
| 171 | + msg_dict['hashtags'] = HASHTAG_RE.findall(summary) |
| 172 | + msg_dict['mentions'] = MENTION_RE.findall(summary) |
146 | 173 | else: |
| 174 | + msg_dict['section'], msg_dict['parsed_summary'] = '', summary |
147 | 175 | msg_dict['hashtags'] = [] |
148 | 176 | msg_dict['mentions'] = [] |
149 | 177 |
|
|
0 commit comments