Merge branch 'hh_gitea_upgrade' into feature_gitea_upgrade

This commit is contained in:
yystopf 2023-03-21 18:40:32 +08:00
commit 33606c8cd2
4 changed files with 12 additions and 8 deletions

View File

@ -262,7 +262,7 @@ class RepositoriesController < ApplicationController
archive_url = "/repos/#{@owner.login}/#{@repository.identifier}/archive/#{Addressable::URI.escape(params[:archive])}"
file_path = [domain, api_url, archive_url].join
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("?") if @repository.hidden?
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("?")
return render_not_found if !request.format.zip? && !request.format.gzip?

View File

@ -4,7 +4,7 @@ class Users::StatisticsController < Users::BaseController
# 近期活动统计
def activity
date_range = (1.week.ago.to_date..Date.today).to_a
commit_request = Gitea::User::HeadmapService.call(observed_user.login, 1.week.ago.to_date.to_time.to_i, Date.today.to_time.to_i)
commit_request = Gitea::User::HeadmapService.call(observed_user.login, 1.week.ago.to_date.to_time.to_i, Date.today.end_of_day.to_time.to_i, observed_user.gitea_token)
commit_data = commit_request[2]
@date_data = []
@issue_data = []
@ -14,8 +14,11 @@ class Users::StatisticsController < Users::BaseController
@date_data << date.strftime("%Y.%m.%d")
@issue_data << observed_user.issues.issue_issue.where("DATE(created_on) = ?", date).size
@pull_request_data << observed_user.pull_requests.where("DATE(created_at) = ?", date).size
date_commit_data = commit_data.blank? ? nil : commit_data.select{|item| item["timestamp"] == date.to_time.to_i}
@commit_data << (date_commit_data.blank? ? 0 : date_commit_data[0]["contributions"].to_i)
contribution = 0
commit_data.each do |item|
contribution += item["contributions"] if Time.at(item["timestamp"]).strftime("%Y-%m-%d") == date.to_s
end
@commit_data << contribution
end
render :json => {dates: @date_data, issues_count: @issue_data, pull_requests_count: @pull_request_data, commits_count: @commit_data}
end

View File

@ -1,10 +1,11 @@
class Gitea::User::HeadmapService < Gitea::ClientService
attr_reader :start_time, :end_time, :username
attr_reader :start_time, :end_time, :username, :token
def initialize(username, start_time, end_time)
def initialize(username, start_time, end_time, token=nil)
@username = username
@start_time = start_time
@end_time = end_time
@token = token
end
def call
@ -14,7 +15,7 @@ class Gitea::User::HeadmapService < Gitea::ClientService
private
def params
Hash.new.merge(start: start_time, end: end_time)
Hash.new.merge(start: start_time, end: end_time, token: token)
end
def url

View File

@ -1,3 +1,3 @@
json.array! @result_object["branch_name"] do |branch|
json.array! @result_object do |branch|
json.partial! "api/v1/projects/branches/simple_detail", branch: branch
end