|
1 |
# Redmine - project management software
|
|
2 |
# Copyright (C) 2006-2021 Jean-Philippe Lang
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or
|
|
5 |
# modify it under the terms of the GNU General Public License
|
|
6 |
# as published by the Free Software Foundation; either version 2
|
|
7 |
# of the License, or (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
17 |
|
|
18 |
namespace :redmine do
|
|
19 |
namespace :changesets do
|
|
20 |
desc 'Fetch changesets from the repositories'
|
|
21 |
task :fetch => :environment do
|
|
22 |
Repository.fetch_changesets
|
|
23 |
end
|
|
24 |
|
|
25 |
desc 'Sync all revisions in repositories related with all active project.'
|
|
26 |
task :reload => :environment do
|
|
27 |
Project.active.has_module(:repository).find_each do |project|
|
|
28 |
project.repositories.find_each do |repository|
|
|
29 |
detail = [
|
|
30 |
"PJ-ID #{repository.project_id}",
|
|
31 |
"Identifier #{repository.identifier}",
|
|
32 |
"URL #{repository.url}",
|
|
33 |
].join(", ")
|
|
34 |
changesets = repository.changesets
|
|
35 |
puts("Sync revisions: #{changesets.count}: #{detail}")
|
|
36 |
latest_changeset = changesets.first
|
|
37 |
changeset = latest_changeset
|
|
38 |
while changeset
|
|
39 |
revisions = repository.scm.revisions(nil,
|
|
40 |
changeset.identifier,
|
|
41 |
changeset.identifier)
|
|
42 |
revisions.each do |revision|
|
|
43 |
changeset.committer =
|
|
44 |
Changeset.to_utf8(revision.author,
|
|
45 |
repository.repo_log_encoding)
|
|
46 |
changeset.comments =
|
|
47 |
Changeset.normalize_comments(revision.message,
|
|
48 |
repository.repo_log_encoding)
|
|
49 |
changeset.user =
|
|
50 |
repository.find_committer_user(changeset.committer)
|
|
51 |
next unless changeset.changed?
|
|
52 |
|
|
53 |
changeset.issues = []
|
|
54 |
changeset.scan_for_issues
|
|
55 |
if changeset.save
|
|
56 |
puts("Sync revision: #{changeset.identifier}, #{detail}")
|
|
57 |
else
|
|
58 |
puts("Failed to sync revision: " +
|
|
59 |
"#{changeset.identifier}, #{detail}: " +
|
|
60 |
changeset.errors.to_s)
|
|
61 |
end
|
|
62 |
end
|
|
63 |
changeset = changeset.previous
|
|
64 |
end
|
|
65 |
end
|
|
66 |
end
|
|
67 |
end
|
|
68 |
end
|
|
69 |
end
|