I'm looking for a part-time remote job.

Hire me


I'm the author of:

Mastering Redmine is a comprehensive guide with tips, tricks and best practices, and an easy-to-learn structure.

Check the book's project or

Buy the book

Social pages of the book:

By buying this book you also donate to Redmine (see this page).


Follow me:

git_hosting_patch_2.diff

Requires previous patch. - Isaiah Softleigh, 06 Mar 2015 17:07

Download (8.24 KB)

View differences:

app/controllers/download_svn_revision_controller.rb~
1
class DownloadSvnRevisionController < ApplicationController
2
  unloadable
3

  
4
  before_filter :require_login
5
  before_filter :set_repository_variable
6
  before_filter :set_project_variable
7
  #before_filter :can_download_svn_revision
8

  
9
  #helper :git_hosting
10

  
11

  
12
  def index
13
    commit = nil
14
    format = params[:download_format]
15

  
16
    if !params[:rev]
17
      rev = "master"
18
    else
19
      rev = params[:rev]
20
    end
21

  
22

  
23
    project_name = @repository.name.to_s.parameterize.to_s
24

  
25
    cmd_args = ""
26

  
27
    case format
28
      when 'tar' then
29
        extension = 'tar'
30
        content_type = 'application/x-tar'
31
        cmd_args << "tar -cvf #{project_name}-#{rev}.#{extension} #{project_name}-#{rev}"
32
      when 'tar.gz' then
33
        extension = 'tar.gz'
34
        content_type = 'application/x-gzip'
35
        cmd_args << "tar -zcvf #{project_name}-#{rev}.#{extension} #{project_name}-#{rev}"
36
      when 'zip' then
37
        extension = 'zip'
38
        content_type = 'application/x-zip'
39
        cmd_args << "zip -r #{project_name}-#{rev}.#{extension} #{project_name}-#{rev}"
40
    end
41

  
42
    #begin
43
      #system("echo '#{@repository.url} #{project_name}-#{rev}.#{extension}' > log/logging.log")
44
      system("svn export #{@repository.url} #{project_name}-#{rev}; #{cmd_args}")
45
      content = "#{project_name}-#{rev}.#{extension}"
46
    #rescue => e
47
      #flash.now[:error] = l(:git_archive_timeout, :timeout => e.message)
48
     # render_404
49
      #return
50
    #end
51
    if(File.file?("#{project_name}-#{rev}.#{extension}"))
52
      send_file(content, :filename => "#{project_name}-#{rev}.#{extension}", :type => content_type)
53
    end
54
 end
55

  
56

  
57
  private
58

  
59

  
60
  def can_download_svn_revision
61
    render_403 unless view_context.user_allowed_to(:download_svn_revision, @project)
62
  end
63

  
64

  
65
  def set_repository_variable
66
    @repository = Repository.find_by_id(params[:repository_id])
67
    if @repository.nil?
68
      render_404
69
    end
70
  end
71

  
72

  
73
  def set_project_variable
74
    @project = @repository.project
75
    if @project.nil?
76
      render_404
77
    end
78
  end
79

  
80
end
app/views/repositories/_download_revision.erb
31 31

  
32 32
  <% end %>
33 33
<% end %>
34

  
35

  
36
<% if defined?(SCMCreator) == 'constant' && SCMCreator.class == Class %>
37
 <% if @repository.is_a?(Repository::Subversion)%>
38
  <% if (@project.active? && User.current.allowed_to?(:download_svn_revision, @project)) || (!@project.active? &&  User.current.allowed_to?(:download_svn_revision, nil, :global => true)) %>
39

  
40
    <div style="clear: both;"></div>
41

  
42
    <div id="svn_hosting_download_buttons">
43
      <ul>
44
        <li>
45
          <%= link_to "<i class=\"fa fa-download\"></i>".html_safe + l(:label_download_format, :archive_format => '.tar'),
46
                      download_svn_revision_path(@repository.id, :rev => @rev, :download_format => 'tar'),
47
                      :class => 'button' %>
48
        </li>
49

  
50
        <li>
51
          <%= link_to "<i class=\"fa fa-download\"></i>".html_safe + l(:label_download_format, :archive_format => '.tar.gz'),
52
                      download_svn_revision_path(@repository.id, :rev => @rev, :download_format => 'tar.gz'),
53
                      :class => 'button' %>
54
        </li>
55

  
56
        <li>
57
          <%= link_to "<i class=\"fa fa-download\"></i>".html_safe + l(:label_download_format, :archive_format => '.zip'),
58
                      download_svn_revision_path(@repository.id, :rev => @rev, :download_format => 'zip'),
59
                      :class => 'button' %>
60
        </li>
61
      </ul>
62
    </div>
63

  
64
    <% content_for :header_tags do %>
65
      <%= stylesheet_link_tag 'font_awesome', :plugin => 'redmine_git_hosting' %>
66
    <% end %>
67

  
68
  <% end %>
69
 <% end %>
70
<% end %>
app/views/repositories/stats.html.erb
1
<% if !(@repository.is_a? Repository::Git) %>
2
<h2><%= l(:label_statistics) %></h2>
3

  
4
<p>
5
<%= tag("embed",
6
        :type => "image/svg+xml", :src => url_for(:controller => 'repositories',
7
        :action => 'graph', :id => @project,
8
        :repository_id => @repository.identifier_param,
9
        :graph => "commits_per_month")) %>
10
</p>
11
<p>
12
<%= tag("embed",
13
        :type => "image/svg+xml", :src => url_for(:controller => 'repositories',
14
        :action => 'graph', :id => @project,
15
        :repository_id => @repository.identifier_param,
16
        :graph => "commits_per_author")) %>
17
</p>
18

  
19
<p><%= link_to l(:button_back), :action => 'show', :id => @project %></p>
20

  
21
<% html_title(l(:label_repository), l(:label_statistics)) -%>
22

  
23
<% else %>
24

  
1 25
<h2><%= l(:label_statistics) %></h2>
2 26

  
3 27
<% content_for :header_tags do %>
......
141 165
<p><%= link_to l(:button_back), :action => 'show', :id => @project %></p>
142 166

  
143 167
<% html_title(l(:label_repository), l(:label_statistics)) -%>
168

  
169
<% end %>
lib/redmine_git_hosting/patches/repository_patch.rb
33 33

  
34 34
      module InstanceMethods
35 35

  
36
        def global_statistics
37
          total_commits = Changeset.where("repository_id = ?", self.id).count
38
          first_commit  = Changeset.where("repository_id = ?", self.id).order('commit_date ASC').first
39
          last_commit   = Changeset.where("repository_id = ?", self.id).order('commit_date ASC').last
40
          active_for    = (last_commit.commit_date - first_commit.commit_date).to_i
41
          committers    = Changeset.where("repository_id = ?", self.id).where("user_id IS NOT NULL").select(:user_id).uniq.count
42
          committers   += Changeset.where("repository_id = ?", self.id).where(user_id: nil).select(:committer).uniq.count
43

  
44
          data = {}
45
          data[l(:label_total_commits)]               = total_commits
46
          data[l(:label_total_contributors)]          = committers
47
          data[l(:label_first_commit_date)]           = first_commit.commit_date
48
          data[l(:label_latest_commit_date)]          = last_commit.commit_date
49
          data[l(:label_active_for)]                  = "#{active_for} #{l(:label_active_days)}"
50
          data[l(:label_average_commit_per_day)]      = total_commits.fdiv(active_for).round(2)
51
          data[l(:label_average_contributor_commits)] = total_commits.fdiv(committers).round(2)
52

  
53
          return data
54
        end
36
         def global_statistics
37
           total_commits = Changeset.where("repository_id = ?", self.id).count
38
           first_commit  = Changeset.where("repository_id = ?", self.id).order('commit_date ASC').first
39
           last_commit   = Changeset.where("repository_id = ?", self.id).order('commit_date ASC').last
40
           active_for    = (last_commit.commit_date - first_commit.commit_date).to_i
41
           committers    = Changeset.where("repository_id = ?", self.id).where("user_id IS NOT NULL").select(:user_id).uniq.count
42
           committers   += Changeset.where("repository_id = ?", self.id).where(user_id: nil).select(:committer).uniq.count
43

  
44
           data = {}
45
           data[l(:label_total_commits)]               = total_commits
46
           data[l(:label_total_contributors)]          = committers
47
           data[l(:label_first_commit_date)]           = first_commit.commit_date
48
           data[l(:label_latest_commit_date)]          = last_commit.commit_date
49
           data[l(:label_active_for)]                  = "#{active_for} #{l(:label_active_days)}"
50
           data[l(:label_average_commit_per_day)]      = total_commits.fdiv(active_for).round(2)
51
           data[l(:label_average_contributor_commits)] = total_commits.fdiv(committers).round(2)
52

  
53
           return data
54
         end
55 55

  
56 56

  
57 57
        def commits_per_hours
Terms of use | Privacy policy