Browse Source

更改:贡献占比展示在贡献者页面

pull/330/head
yystopf 3 years ago
parent
commit
4b5df918fc
2 changed files with 5 additions and 8 deletions
  1. +3
    -1
      app/models/concerns/watchable.rb
  2. +2
    -7
      app/views/repositories/_contributor.json.jbuilder

+ 3
- 1
app/models/concerns/watchable.rb View File

@@ -45,11 +45,13 @@ module Watchable
score = cal_perc(balance_user, balance_all)
else
contributors = []
result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier,{q_name: self.login, q_email: self.mail})
result = Gitea::Repository::Contributors::GetService.call(@user, @project.identifier,{q_name: @user.login, q_email: @user.mail})
user_contribution = result[:body][0]
commits_all = result[:total_contributions]
score = cal_perc(user_contribution["contributions"], commits_all)
end

(score * 100).round(1).to_s + "%"
end

def contribution_perc(project)


+ 2
- 7
app/views/repositories/_contributor.json.jbuilder View File

@@ -6,12 +6,7 @@ if user.blank?
json.type nil
json.name contributor["login"]
json.image_url User::Avatar.get_letter_avatar_url(contributor["login"])
if @cache_result.present?
db_user = User.find_by_id(contributor["id"])
if db_user.present?
json.contribution_perc db_user.contribution_perc(project)
end
end
json.contribution_perc User.new(login: contributor["login"], mail: contributor["email"]).simple_contribution_perc(project)
else
json.contributions contributor["contributions"]
# json.gid contributor["id"]
@@ -21,6 +16,6 @@ else
json.image_url user["avatar_url"]
db_user = User.find_by_id(user["id"])
if db_user.present?
json.contribution_perc db_user.contribution_perc(project)
json.contribution_perc db_user.simple_contribution_perc(project)
end
end

Loading…
Cancel
Save