Merge lp:~lifeless/hydrazine/cron into lp:hydrazine

Proposed by Robert Collins
Status: Merged
Merge reported by: Martin Pool
Merged at revision: not available
Proposed branch: lp:~lifeless/hydrazine/cron
Merge into: lp:hydrazine
Diff against target: 197 lines (+70/-43)
2 files modified
feed-pqm (+69/-42)
hydrazine/__init__.py (+1/-1)
To merge this branch: bzr merge lp:~lifeless/hydrazine/cron
Reviewer Review Type Date Requested Status
Martin Pool Needs Resubmitting
Review via email: mp+23213@code.launchpad.net

Description of the change

Use the LP API 'queued' status to record things 'sent' to PQM, and add a cron mode we should run somewhere that will automatically send one (and only one) email to PQM to handle such proposals.

To post a comment you must log in.
lp:~lifeless/hydrazine/cron updated
68. By Robert Collins

Include the queuer as a prefix and the branch owner as a suffix on commit messages, to automate current practice.

69. By Robert Collins

Save the tabs, save the world.

70. By Robert Collins

Set queued revision id when queuing.

71. By Robert Collins

After sending merge proposals, remove them from the queue if they would not have been found originally.

72. By Robert Collins

Handle submitting the last pending proposal.

73. By Robert Collins

Remove --cron mode.

74. By Robert Collins

Add back manual email submission via 'e'.

75. By Robert Collins

Really do it.

Revision history for this message
Martin Pool (mbp) wrote :

I think this is obsolete until we continue with queue mode? But if you want to separate out some of this, you can.

review: Needs Resubmitting
Revision history for this message
Robert Collins (lifeless) wrote :

No, it should be mergable now, as-is, as a qualititative improvement.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'feed-pqm'
--- feed-pqm 2010-03-29 05:21:17 +0000
+++ feed-pqm 2010-04-20 07:20:40 +0000
@@ -16,12 +16,13 @@
1616
1717
18import datetime18import datetime
19import optparse
19import os20import os
20import subprocess
21import sys21import sys
2222
23from bzrlib.email_message import EmailMessage
23from bzrlib.config import GlobalConfig24from bzrlib.config import GlobalConfig
24from bzrlib.email_message import EmailMessage25from bzrlib import gpg
25from bzrlib.smtp_connection import SMTPConnection26from bzrlib.smtp_connection import SMTPConnection
2627
27import hydrazine28import hydrazine
@@ -46,7 +47,12 @@
46 n skip this, go to the next47 n skip this, go to the next
47 p previous48 p previous
48 q quit49 q quit
49 s send it to pqm!50 s submit approved merges to the queue (PQM reads from the launchpad
51 queue) for already queued merges this toggles in and out of queued,
52 setting a new queuer and putting it at the back of the queue.
53 Requires membership in the review team for the target branch.
54 e send in an approved merge via email. Requires GPG and email setup
55 appropriately in bazaar.conf, and your key in the PQM keyring.
5056
51Please send feedback to mbp@canonical.com57Please send feedback to mbp@canonical.com
52"""58"""
@@ -64,6 +70,7 @@
64 print ' %12s: %s' % ('message', mp.commit_message)70 print ' %12s: %s' % ('message', mp.commit_message)
65 print ' %12s: %s' % ('source', mp.source_branch.bzr_identity)71 print ' %12s: %s' % ('source', mp.source_branch.bzr_identity)
66 print ' %12s: %s' % ('target', mp.target_branch.bzr_identity)72 print ' %12s: %s' % ('target', mp.target_branch.bzr_identity)
73 print ' %12s: %s' % ('status', mp.queue_status)
67 show_datetime('created', mp.date_created)74 show_datetime('created', mp.date_created)
68 show_datetime('reviewed', mp.date_reviewed)75 show_datetime('reviewed', mp.date_reviewed)
69 print ' %12s: %s' % ('registrant', mp.registrant.name)76 print ' %12s: %s' % ('registrant', mp.registrant.name)
@@ -81,71 +88,77 @@
81 mp.lp_save()88 mp.lp_save()
8289
8390
84def send_mp(launchpad, mp):91def queue_mp(launchpad, mp):
85 if not mp.commit_message:92 if not mp.commit_message:
86 print "No message set? Use 'm'."93 print "No message set? Use 'm'."
87 return94 return
8895 if mp.queue_status == 'Queued':
89 # suggested subject should match the last comment on the mp so that gmail96 mp.setStatus(status='Approved')
90 # doesn't see it as a separate thread;97 mp.setStatus(status='Queued', revid=mp.reviewed_revid)
91 # <https://bugs.edge.launchpad.net/hydrazine/+bug/541586>98
92 subject = "Re: [Merge] %s into %s" % (99
93 mp.source_branch.bzr_identity,100def send_mp(launchpad, mp, send_mail=True):
94 mp.target_branch.bzr_identity)101 if not mp.commit_message:
95102 print "No message set - %s queued badly? Set a message first." % mp
103 return False
96 print "merge command to be signed:"104 print "merge command to be signed:"
97 print "Subject: %s" % subject
98 raw_message = (105 raw_message = (
99 "star-merge %s %s\n"106 "star-merge %s %s\n"
100 % (mp.source_branch.composePublicURL(scheme='http'),107 % (mp.source_branch.composePublicURL(scheme='http'),
101 mp.target_branch.composePublicURL(scheme='http')))108 mp.target_branch.composePublicURL(scheme='http')))
109 print raw_message
102110
111 config = GlobalConfig()
112 signer = gpg.GPGStrategy(config)
113 signed_message = signer.sign(raw_message.encode('utf8'))
103 try:114 try:
104 my_email = os.environ['EMAIL']115 my_email = os.environ['EMAIL']
105 except KeyError:116 except KeyError:
106 my_email = launchpad.me.preferred_email_address.email117 my_email = launchpad.me.preferred_email_address.email
107 print "EMAIL environment variable not set, using %s" % my_email118 print "EMAIL environment variable not set, using %s" % my_email
108 child = subprocess.Popen(119 # TODO: put in bug numbers as well.
109 ['gpg', '--clearsign', '-a'],120 commit_message = u"(%s) %s (%s)" % (launchpad.me.name, mp.commit_message,
110 stdin=subprocess.PIPE,121 mp.source_branch.owner.display_name)
111 stdout=subprocess.PIPE)122 message = EmailMessage(my_email, PQM_ADDRESS, commit_message,
112 signed_message = child.communicate(
113 raw_message)[0]
114 if child.returncode != 0:
115 print "gpg child failed"
116
117 message = EmailMessage(my_email, PQM_ADDRESS, mp.commit_message,
118 signed_message)123 signed_message)
119 config = GlobalConfig()124 if send_mail:
120 SMTPConnection(config).send_email(message)125 SMTPConnection(config).send_email(message)
121126 print "Sent!"
122 print "Sent!"127 else:
123128 print "Not sending email - disabled."
124 if False:129
125 # disabled, because some people think it's too noisy130 # suggested subject should match the last comment on the mp so that gmail
126 mp.createComment(content="Fed to pqm\n\n" + raw_message, 131 # doesn't see it as a separate thread;
127 subject=subject)132 # <https://bugs.edge.launchpad.net/hydrazine/+bug/541586>
128133 subject = "Re: [Merge] %s into %s" % (mp.source_branch.bzr_identity,
134 mp.target_branch.bzr_identity)
135 print "Recording that the proposal is submitted to PQM."
136 fed_pqm = "submitted to PQM by hand.\n"
137 mp.createComment(content=fed_pqm, subject=subject)
138 return True
129139
130140
131def main(argv):141def main(argv):
132 142 parser = optparse.OptionParser()
143 parser.add_option('--nomail', help="Do not send email commands", action="store_true", default=False)
144 parser.add_option('--queued', help="Examine already queued proposals", action="store_true", default=False)
145 opts, args = parser.parse_args()
133 launchpad = hydrazine.create_session()146 launchpad = hydrazine.create_session()
134 project = launchpad.projects[argv[1]]147 project = launchpad.projects[argv[1]]
135
136 print 'Looking for Approved mps in %s' % project
137 i = 0148 i = 0
138 all_mps = list(project.getMergeProposals(status=['Approved']))149 find_status = ['Approved']
139 if all_mps == []:150 if opts.queued:
140 print "Nothing approved to merge?"151 find_status.append('Queued')
141 while True:152 print 'Looking for %s mps in %s' % (find_status, project)
153 all_mps = list(project.getMergeProposals(status=find_status))
154 while len(all_mps):
142 mp = all_mps[i]155 mp = all_mps[i]
143 show_mp(mp)156 show_mp(mp)
144157
145 while True:158 while True:
146 whatnow = read_choice()159 whatnow = read_choice()
147 if whatnow == 'q':160 if whatnow == 'q':
148 return True161 return 0
149 elif whatnow in ('h', 'help', '?'):162 elif whatnow in ('h', 'help', '?'):
150 show_help()163 show_help()
151 elif whatnow == 'n':164 elif whatnow == 'n':
@@ -159,11 +172,25 @@
159 elif whatnow == 'm':172 elif whatnow == 'm':
160 set_message(mp)173 set_message(mp)
161 elif whatnow == 's':174 elif whatnow == 's':
162 send_mp(launchpad, mp)175 queue_mp(launchpad, mp)
176 if mp.queue_status not in find_status:
177 del all_mps[i]
178 if i == len(all_mps):
179 i -= 1
180 break
181 elif whatnow == 'e':
182 if send_mp(launchpad, mp, send_mail=not opts.nomail):
183 del all_mps[i]
184 if i == len(all_mps):
185 i -= 1
186 break
163 elif whatnow == '':187 elif whatnow == '':
164 continue188 continue
165 else:189 else:
166 print "Sorry, don't understand %r" % whatnow190 print "Sorry, don't understand %r" % whatnow
191 if not len(all_mps):
192 print "No remaining merge proposals matching status %r?" % find_status
193 return 0
167194
168195
169if __name__ == '__main__':196if __name__ == '__main__':
170197
=== modified file 'hydrazine/__init__.py'
--- hydrazine/__init__.py 2010-03-02 05:39:02 +0000
+++ hydrazine/__init__.py 2010-04-20 07:20:40 +0000
@@ -11,7 +11,7 @@
11 EDGE_SERVICE_ROOT,11 EDGE_SERVICE_ROOT,
12 )12 )
1313
14service_root = EDGE_SERVICE_ROOT14service_root = os.environ.get('LAUNCHPAD_API', EDGE_SERVICE_ROOT)
1515
1616
17def trace(s):17def trace(s):

Subscribers

People subscribed via source and target branches

to all changes: