forked from nomlab/nomrat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RedmineGetter.rb
executable file
·191 lines (156 loc) · 5.77 KB
/
RedmineGetter.rb
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# -*- coding: utf-8 -*-
## Created : 2011/10/31 -Y.Kimura
## Modified : 2013/04/11 -Y.Kimura
## Ruby Ver : 1.8.7
## Get&Return next Itr and message for tweet or mail
#####################
require 'rubygems'
require 'open-uri'
require 'time'
require 'date'
$KCODE = "UTF8"
#####################
class RedmineGetter
def initialize
@new_itr = ""
@itr_date = Date.today
@sours = ""
@itr_page_address = ""
end
def new_itr
@new_itr
end
def itr_date
@itr_date
end
##----------------------------------------------------------------------
## set the recent Itr page
##----------------------------------------------------------------------
def get_itr
### GET next_itr
error_message = ""
redmine_page = "http://redmine.swlab.cs.okayama-u.ac.jp/projects/lastnote"
begin
open( redmine_page ){|f|
f.each_line{|line|
@sours += line
}
}
rescue
error_message << "Error: fail to Get redmine/lastnote page.\n"
end
### GET newItr from redmine
itrs = @sours.scan( /class=\"wiki\-page\">最新イテレーション\s\((Itr[\d]*)\)/ )
@new_itr = itrs.first.to_s
if( itrs != [])
@itr_page_address = redmine_page + "/wiki/" + @new_itr
else
error_message << "Error: fail to Make itr_address.\n"
end
### SET sours
@sours = ""
begin
open( @itr_page_address ){|f|
f.each_line{|line|
@sours += line
}
}
rescue
error_message << "Error: fail to GET redmine/next_meeting.\n"
end
##----------------------------------------------------------------------
## set next meeting date and author
##----------------------------------------------------------------------
itr_note = ""
date_next = nil
date_before = nil
writer = nil
@sours.each {|line|
itr_note = line
break if(line =~ /期間/)
}
begin
if(itr_note =~ /期間[:|:][\s]*([\d]+\-[\d]+\-[\d]+)[^\d]*([\d]+\-[\d]+\-[\d]+)/)
date_before = $1
date_next = $2
end
if(itr_note =~ /書記[:|:][\s]*([^<]*)/)
writer = $1
end
rescue
error_message << "Error: fail to set next meeting date.\n"
end
date_arr = date_next.split("-")
@itr_date = Date.new( date_arr[0].to_i, date_arr[1].to_i, date_arr[2].to_i )
##----------------------------------------------------------------------
## set tweet speach
##----------------------------------------------------------------------
speach = ""
if(@itr_date - Date.today == 3)
speach = "GN開発打合せ3日前です.書記の#{writer}さんは今イテレーションのwikiのページを確認してください.->(#{@itr_page_address})"
end
if(@itr_date - Date.today == 2)
speach = "GN開発打合せ2日前です.GNグループの皆様は各自チケットの更新を確認してください."
end
### output error message
if( error_message == "" )
return speach
else
errors = Time.now.strftime("%Y/%m/%d : ") + "\n"
open("errorlog.txt", "w+"){|f|
errors << error_message
f.write errors
}
return ""
end
end # method( get_itr ) end
###----------------------------------------------------------------------
### SEND MAIL
###----------------------------------------------------------------------
def get_ticket
mail_message = ""
### Set updated ticket
if( /<p>\(更新あり\)(.*)<\/p>/ =~ @sours )
string_non_updateds = $1.to_s
non_updateds = Array.new
non_updateds = string_non_updateds.scan( /br \/><a href=\"[^\"]*\" class=\"[^\"]*\" title="([^\"]*)\s\(([^\"]*)\)">#([\d]+)<\/a>([^<]*)</ )
mail_message << "* 更新あり\n"
non_updateds.each{|elem| # [ 0:Title, 1:status , 2:ticket_number, 3:strings]
mail_message << " + ##{elem[2]} #{elem[0]}\n" # #ticketnum : Title
user = " ".ljust(20)
if( elem[3] =~ /([a-zA-Z]+\s[\a-zA-Z]+)$/ )
user = $1.ljust(20)
end
mail_message << " (#{elem[1]}) #{user} [[ http://redmine.swlab.cs.okayama-u.ac.jp/issues/#{elem[2]} ]]\n"
}
end
### Set non_updated ticket
if( /<p>\(更新なし\)(.*)<\/p>/ =~ @sours )
string_non_updateds = $1.to_s
non_updateds = Array.new
non_updateds = string_non_updateds.scan( /br \/><a href=\"[^\"]*\" class=\"[^\"]*\" title="([^\"]*)\s\(([^\"]*)\)">#([\d]+)<\/a>([^<]*)</ )
mail_message << "* 更新なし\n"
non_updateds.each{|elem| # [ 0:Title, 1:status , 2:ticket_number, 3:strings]
mail_message << " + ##{elem[2]} #{elem[0]}\n" # #ticketnum : Title
user = " ".ljust(20)
if( elem[3] =~ /([a-zA-Z]+\s[\a-zA-Z]+)$/ )
user = $1.ljust(20)
end
mail_message << " (#{elem[1]}) #{user} [[ http://redmine.swlab.cs.okayama-u.ac.jp/issues/#{elem[2]} ]]\n"
}
end
### Send mail to GN member
message = "GNグループの皆さまへ\n\n"
message << "GN開発打合せ2日前です.\n今イテレーションのチケットは以下の通りです.\n\n"
if(mail_message == "")
message << "・・・チケットの記述の形式が異なります.\n"
else
message << "----------------------------------------------------------------------------------------\n"
message << mail_message
message << "----------------------------------------------------------------------------------------\n"
end
message << "\nなお,今イテレーションにおけるチケットに関しましては,以下をご参照ください.\n"
message << @itr_page_address
return message
end # method( get_ticket ) end
end # class end