[062892]: / scripts / migrations / 034-update_subscriptions_ticket_and_mr_titles.py  Maximize  Restore  History

Download this file

76 lines (65 with data), 2.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import logging
import re
import sys
from tg import tmpl_context as c
from bson import ObjectId
from ming.odm import session
from ming.odm import ThreadLocalODMSession
from allura import model as M
from forgetracker import model as TM
log = logging.getLogger(__name__)
def main():
task = sys.argv[-1]
c.project = None
# Fix ticket artifcat titles
title = re.compile('^Ticket [0-9]')
subs_tickets = M.Mailbox.query.find(dict(artifact_title=title)).all()
log.info('Found total %d old artifact titles (tickets).', len(subs_tickets))
for sub in subs_tickets:
if not sub.artifact_index_id:
log.info('No artifact_index_id on %s', sub)
continue
ticket = TM.Ticket.query.get(_id=ObjectId(sub.artifact_index_id.split('#')[1]))
if not ticket:
log.info('Could not find ticket for %s', sub)
continue
new_title = 'Ticket #%d: %s' % (ticket.ticket_num, ticket.summary)
log.info('"%s" --> "%s"', sub.artifact_title, new_title)
if(task != 'diff'):
sub.artifact_title = new_title
session(sub).flush(sub)
# Fix merge request artifact titles
title = re.compile('^Merge request: ')
subs_mrs = M.Mailbox.query.find(dict(artifact_title=title)).all()
log.info('Found total %d old artifact titles (merge_requests).', len(subs_tickets))
for sub in subs_mrs:
if not sub.artifact_index_id:
log.info('No artifact_index_id on %s', sub)
continue
merge_request = M.MergeRequest.query.get(_id=ObjectId(sub.artifact_index_id.split('#')[1]))
if not merge_request:
log.info('Could not find merge request for %s', sub)
continue
new_title = 'Merge Request #%d: %s' % (merge_request.request_number, merge_request.summary)
log.info('"%s" --> "%s"', sub.artifact_title, new_title)
if task != 'diff':
sub.artifact_title = new_title
session(sub).flush(sub)
if __name__ == '__main__':
main()