blob: 1d312ae347241c9102448a1865c4e8e158dd5058 [file] [log] [blame]
Monty Taylor6c9634c2012-07-28 11:27:47 -05001#!/usr/bin/env python
2# Copyright (c) 2012 OpenStack, LLC.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16# This is designed to be called by a gerrit hook. It searched new
17# patchsets for strings like "bug FOO" and updates corresponding Launchpad
18# bugs status.
19
20import argparse
21import re
22import subprocess
23import smtplib
24
25from email.mime.text import MIMEText
26
27BASE_DIR = '/home/gerrit2/review_site'
28EMAIL_TEMPLATE = """
29Hi, I'd like you to take a look at this patch for potential
30documentation impact.
31%s
32
33Log:
34%s
35"""
36DEST_ADDRESS = 'openstack-docs@lists.openstack.org'
37
38def process_impact(git_log, args):
39 """Notify doc team of doc impact"""
40 email_content = EMAIL_TEMPLATE % (args.change_url, git_log)
41 msg = MIMEText(email_content)
42 msg['Subject'] = '[%s] DocImpact review request' % args.project
43 msg['From'] = 'gerrit2@review.openstack.org'
44 msg['To'] = DEST_ADDRESS
45
46 s = smtplib.SMTP('localhost')
47 s.sendmail('gerrit2@review.openstack.org', DEST_ADDRESS, msg.as_string())
48 s.quit()
49
50def docs_impacted(git_log):
51 """Determine if a changes log indicates there is a doc impact"""
52 impact_regexp = r'DocImpact'
53 return re.search(impact_regexp, git_log, re.IGNORECASE)
54
55def extract_git_log(args):
56 """Extract git log of all merged commits"""
57 cmd = ['git',
58 '--git-dir=' + BASE_DIR + '/git/' + args.project + '.git',
59 'log', '--no-merges', args.commit + '^1..' + args.commit]
60 return subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
61
62
63def main():
64 parser = argparse.ArgumentParser()
65 parser.add_argument('hook')
66 #common
67 parser.add_argument('--change', default=None)
68 parser.add_argument('--change-url', default=None)
69 parser.add_argument('--project', default=None)
70 parser.add_argument('--branch', default=None)
71 parser.add_argument('--commit', default=None)
72 #change-merged
73 parser.add_argument('--submitter', default=None)
74 #patchset-created
75 parser.add_argument('--uploader', default=None)
76 parser.add_argument('--patchset', default=None)
77
78 args = parser.parse_args()
79
80 # Get git log
81 git_log = extract_git_log(args)
82
83 # Process doc_impacts found in git log
84 if docs_impacted(git_log):
85 process_impact(git_log, args)
86
87
88if __name__ == '__main__':
89 main()