[error msg] git_mirror.rb:112:1: C: Metrics/ClassLength: Class has too many lines. [101/100] class MirrorMain ... ^^^^^^^^^^^^^^^^ git_mirror.rb:192:3: C: Metrics/AbcSize: Assignment Branch Condition size for handle_feedback is too high. [<4, 17, 6> 18.47/15] def handle_feedback ... ^^^^^^^^^^^^^^^^^^^ git_mirror.rb:286:3: C: Metrics/AbcSize: Assignment Branch Condition size for reload_fork_info is too high. [<5, 17, 2> 17.83/15] def reload_fork_info(upstream_repos) ... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ git_mirror.rb:293:121: C: Layout/LineLength: Line is too long. [149/120] changed_files = %x(git -C /srv/git/#{@git_info[upstream_repos]['belong']}/#{upstream_repos}.git diff --name-only #{old_commit}...#{new_commit}) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ git_mirror.rb:328:3: C: Metrics/AbcSize: Assignment Branch Condition size for update_stat_new_refs is too high. [<6, 14, 2> 15.36/15] def update_stat_new_refs(git_repo) ... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ git_mirror.rb:508:7: C: Naming/PredicateName: Rename is_upstream_repo? to upstream_repo?. def is_upstream_repo?(git_repo) ^^^^^^^^^^^^^^^^^
Signed-off-by: Li Yuanchao lyc163mail@163.com --- lib/git_mirror.rb | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-)
diff --git a/lib/git_mirror.rb b/lib/git_mirror.rb index 5ba9154..c967c8b 100644 --- a/lib/git_mirror.rb +++ b/lib/git_mirror.rb @@ -199,14 +199,7 @@ class MirrorMain update_fork_stat(git_repo, feedback_info[:possible_new_refs]) return unless feedback_info[:possible_new_refs]
- return reload_fork_info(git_repo) if is_upstream_repo?(git_repo) - - new_refs = check_new_refs(git_repo) - return if new_refs[:heads].empty? - - feedback_info[:new_refs] = new_refs - send_message(feedback_info) - new_refs_log(git_repo, new_refs[:heads].length) if last_commit_new?(git_repo) + handle_feedback_new_refs(git_repo, feedback_info) end
def do_push(fork_key) @@ -283,14 +276,19 @@ class MirrorMain return new_refs end
+ def get_change_files(upstream_repos) + old_commit = @git_info[upstream_repos][:cur_refs][:heads]['refs/heads/master'] + new_refs = check_new_refs(upstream_repos) + new_commit = new_refs[:heads]['refs/heads/master'] + mirror_dir = "/srv/git/#{@git_info[upstream_repos]['belong']}/#{upstream_repos}.git" + %x(git -C #{mirror_dir} diff --name-only #{old_commit}...#{new_commit}) + end + def reload_fork_info(upstream_repos) if @git_info[upstream_repos][:cur_refs].empty? @git_info[upstream_repos][:cur_refs] = get_cur_refs(upstream_repos) else - old_commit = @git_info[upstream_repos][:cur_refs][:heads]['refs/heads/master'] - new_refs = check_new_refs(upstream_repos) - new_commit = new_refs[:heads]['refs/heads/master'] - changed_files = %x(git -C /srv/git/#{@git_info[upstream_repos]['belong']}/#{upstream_repos}.git diff --name-only #{old_commit}...#{new_commit}) + changed_files = get_change_files(upstream_repos) reload(changed_files, @git_info[upstream_repos]['belong']) end end @@ -325,13 +323,17 @@ class MirrorMain @fork_stat[git_repo][:offset_fetch] = offset_fetch + 1 end
+ def update_new_refs_info(git_repo, offset_new_refs) + @fork_stat[git_repo][:new_refs_time][offset_new_refs] = Time.now.to_s + @fork_stat[git_repo][:offset_new_refs] = offset_new_refs + 1 + @fork_stat[git_repo][:new_refs_count] = update_new_refs_count(@fork_stat[git_repo][:new_refs_count]) + end + def update_stat_new_refs(git_repo) @fork_stat[git_repo][:priority] += 1 offset_new_refs = @fork_stat[git_repo][:offset_new_refs] offset_new_refs = 0 if offset_new_refs >= 10 - @fork_stat[git_repo][:new_refs_time][offset_new_refs] = Time.now.to_s - @fork_stat[git_repo][:offset_new_refs] = offset_new_refs + 1 - @fork_stat[git_repo][:new_refs_count] = update_new_refs_count(@fork_stat[git_repo][:new_refs_count]) + update_new_refs_info(git_repo, offset_new_refs) end
def update_fork_stat(git_repo, possible_new_refs) @@ -471,6 +473,17 @@ end class MirrorMain WEEK_SECONDS = 604800
+ def handle_feedback_new_refs(git_repo, feedback_info) + return reload_fork_info(git_repo) if upstream_repo?(git_repo) + + new_refs = check_new_refs(git_repo) + return if new_refs[:heads].empty? + + feedback_info[:new_refs] = new_refs + send_message(feedback_info) + new_refs_log(git_repo, new_refs[:heads].length) if last_commit_new?(git_repo) + end + def merge_defaults(object_key, object, belong) return object if object_key == belong
@@ -505,7 +518,7 @@ class MirrorMain return url end
- def is_upstream_repo?(git_repo) + def upstream_repo?(git_repo) @upstreams['upstreams'].each do |repo| return true if git_repo == repo['git_repo'] end
- new_refs = check_new_refs(git_repo)
- return if new_refs[:heads].empty?
- feedback_info[:new_refs] = new_refs
- send_message(feedback_info)
- new_refs_log(git_repo, new_refs[:heads].length) if last_commit_new?(git_repo)
handle_feedback_new_refs(git_repo, feedback_info) end
def do_push(fork_key)
@@ -283,14 +276,19 @@ class MirrorMain return new_refs end
- def get_change_files(upstream_repos)
- old_commit = @git_info[upstream_repos][:cur_refs][:heads]['refs/heads/master']
- new_refs = check_new_refs(upstream_repos)
- new_commit = new_refs[:heads]['refs/heads/master']
- mirror_dir = "/srv/git/#{@git_info[upstream_repos]['belong']}/#{upstream_repos}.git"
- %x(git -C #{mirror_dir} diff --name-only #{old_commit}...#{new_commit})
you can use ruby-git instead of os command
Thanks, Luan Shengde
- end
- def reload_fork_info(upstream_repos) if @git_info[upstream_repos][:cur_refs].empty? @git_info[upstream_repos][:cur_refs] = get_cur_refs(upstream_repos) else
old_commit = @git_info[upstream_repos][:cur_refs][:heads]['refs/heads/master']
new_refs = check_new_refs(upstream_repos)
new_commit = new_refs[:heads]['refs/heads/master']
changed_files = %x(git -C /srv/git/#{@git_info[upstream_repos]['belong']}/#{upstream_repos}.git diff --name-only #{old_commit}...#{new_commit})
end endchanged_files = get_change_files(upstream_repos) reload(changed_files, @git_info[upstream_repos]['belong'])
@@ -325,13 +323,17 @@ class MirrorMain @fork_stat[git_repo][:offset_fetch] = offset_fetch + 1 end
- def update_new_refs_info(git_repo, offset_new_refs)
- @fork_stat[git_repo][:new_refs_time][offset_new_refs] = Time.now.to_s
- @fork_stat[git_repo][:offset_new_refs] = offset_new_refs + 1
- @fork_stat[git_repo][:new_refs_count] = update_new_refs_count(@fork_stat[git_repo][:new_refs_count])
- end
- def update_stat_new_refs(git_repo) @fork_stat[git_repo][:priority] += 1 offset_new_refs = @fork_stat[git_repo][:offset_new_refs] offset_new_refs = 0 if offset_new_refs >= 10
- @fork_stat[git_repo][:new_refs_time][offset_new_refs] = Time.now.to_s
- @fork_stat[git_repo][:offset_new_refs] = offset_new_refs + 1
- @fork_stat[git_repo][:new_refs_count] = update_new_refs_count(@fork_stat[git_repo][:new_refs_count])
update_new_refs_info(git_repo, offset_new_refs) end
def update_fork_stat(git_repo, possible_new_refs)
@@ -471,6 +473,17 @@ end class MirrorMain WEEK_SECONDS = 604800
- def handle_feedback_new_refs(git_repo, feedback_info)
- return reload_fork_info(git_repo) if upstream_repo?(git_repo)
- new_refs = check_new_refs(git_repo)
- return if new_refs[:heads].empty?
- feedback_info[:new_refs] = new_refs
- send_message(feedback_info)
- new_refs_log(git_repo, new_refs[:heads].length) if last_commit_new?(git_repo)
- end
- def merge_defaults(object_key, object, belong) return object if object_key == belong
@@ -505,7 +518,7 @@ class MirrorMain return url end
- def is_upstream_repo?(git_repo)
- def upstream_repo?(git_repo) @upstreams['upstreams'].each do |repo| return true if git_repo == repo['git_repo'] end
-- 2.23.0
On Mon, Mar 29, 2021 at 06:44:19PM +0800, Luan Shengde wrote:
- new_refs = check_new_refs(git_repo)
- return if new_refs[:heads].empty?
- feedback_info[:new_refs] = new_refs
- send_message(feedback_info)
- new_refs_log(git_repo, new_refs[:heads].length) if last_commit_new?(git_repo)
handle_feedback_new_refs(git_repo, feedback_info) end
def do_push(fork_key)
@@ -283,14 +276,19 @@ class MirrorMain return new_refs end
- def get_change_files(upstream_repos)
- old_commit = @git_info[upstream_repos][:cur_refs][:heads]['refs/heads/master']
- new_refs = check_new_refs(upstream_repos)
- new_commit = new_refs[:heads]['refs/heads/master']
- mirror_dir = "/srv/git/#{@git_info[upstream_repos]['belong']}/#{upstream_repos}.git"
- %x(git -C #{mirror_dir} diff --name-only #{old_commit}...#{new_commit})
you can use ruby-git instead of os command
That can be another choice.
Thanks, Yuanchao