forked from douban/code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_ticket.py
More file actions
120 lines (107 loc) · 4.85 KB
/
update_ticket.py
File metadata and controls
120 lines (107 loc) · 4.85 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# -*- coding: utf-8 -*-
from vilya.libs.store import store
from vilya.models.consts import (
TICKET_NODE_TYPE_OPEN, TICKET_NODE_TYPE_CLOSE,
TICKET_NODE_TYPE_MERGE, TICKET_NODE_TYPE_COMMIT,
TICKET_NODE_TYPE_COMMENT, TICKET_NODE_TYPE_CODEREVIEW)
from vilya.models.ticket import Ticket
from vilya.models.pull import PullRequest
def get_node(author, type, id, ticket_id, time):
rs = store.execute("select id, author, type, type_id, ticket_id, created_at "
"from ticket_nodes "
"where author=%s and type=%s and type_id=%s and ticket_id=%s and created_at=%s",
(author, type, id, ticket_id, time))
if rs and rs[0]:
return True
def update_commits(from_id=None):
# update commit
if from_id:
rs = store.execute("select id, author, time, ticket_id "
"from codedouban_ticket_commits where id > %s",
from_id)
else:
rs = store.execute("select id, author, time, ticket_id "
"from codedouban_ticket_commits")
for r in rs:
id, author, time, ticket_id = r
if not get_node(author, TICKET_NODE_TYPE_COMMIT, id, ticket_id, time):
print id, author, time, ticket_id
store.execute("insert into ticket_nodes "
"(author, type, type_id, ticket_id, created_at) "
"value (%s, %s, %s, %s, %s)",
(author, TICKET_NODE_TYPE_COMMIT, id, ticket_id, time))
store.commit()
print "update %s commits" % len(rs)
def update_comments(from_id=None):
# update comment
if from_id:
rs = store.execute("select id, author, time, ticket_id "
"from codedouban_ticket_comment where id > %s",
from_id)
else:
rs = store.execute("select id, author, time, ticket_id "
"from codedouban_ticket_comment")
for r in rs:
id, author, time, ticket_id = r
print id, author, time, ticket_id
if not get_node(author, TICKET_NODE_TYPE_COMMENT, id, ticket_id, time):
print id, author, time, ticket_id
store.execute("insert into ticket_nodes "
"(author, type, type_id, ticket_id, created_at) "
"value (%s, %s, %s, %s, %s)",
(author, TICKET_NODE_TYPE_COMMENT, id, ticket_id, time))
store.commit()
print "update %s comments" % len(rs)
def update_codereviews(from_id=None):
# update codereview
if from_id:
rs = store.execute("select id, author, time, ticket_id "
"from codedouban_ticket_codereview where id > %s",
from_id)
else:
rs = store.execute("select id, author, time, ticket_id "
"from codedouban_ticket_codereview")
for r in rs:
id, author, time, ticket_id = r
if not get_node(author, TICKET_NODE_TYPE_CODEREVIEW, id, ticket_id, time):
print id, author, time, ticket_id
store.execute("insert into ticket_nodes "
"(author, type, type_id, ticket_id, created_at) "
"value (%s, %s, %s, %s, %s)",
(author, TICKET_NODE_TYPE_CODEREVIEW, id, ticket_id, time))
store.commit()
print "update %s reviews" % len(rs)
def main():
rs = store.execute("select id "
"from codedouban_ticket")
for r in rs:
id, = r
ticket = Ticket.get(id)
# update merge
pullreq = PullRequest.get_by_ticket(ticket)
author = pullreq.merge_by or pullreq.to_proj.owner_id
time = pullreq.merge_time
ticket_id = ticket.id
id = 0
if not get_node(author, TICKET_NODE_TYPE_MERGE, id, ticket_id, time) and time:
print id, author, time, ticket_id
store.execute("insert into ticket_nodes "
"(author, type, type_id, ticket_id, created_at) "
"value (%s, %s, %s, %s, %s)",
(author, TICKET_NODE_TYPE_MERGE, id, ticket_id, time))
store.commit()
# update close
author = ticket.close_by or ticket.author
time = ticket.closed
ticket_id = ticket.id
id = 0
if not get_node(author, TICKET_NODE_TYPE_CLOSE, id, ticket_id, time) and time:
print id, author, time, ticket_id
store.execute("insert into ticket_nodes "
"(author, type, type_id, ticket_id, created_at) "
"value (%s, %s, %s, %s, %s)",
(author, TICKET_NODE_TYPE_CLOSE, id, ticket_id, time))
store.commit()
print "update %s close & merge pulls" % len(rs)
if __name__ == "__main__":
main()