diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 192977c32..686345deb 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -217,6 +217,21 @@ class RepositoriesController < ApplicationController end end + def replace_file + #删除 + delete_interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, params[:delete_file].merge(identifier: @project.identifier)) + return render_error(delete_interactor.error) unless delete_interactor.success? + #新建 + interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) + if interactor.success? + @file = interactor.result + render_result(0, "替换成功") + else + render_error(interactor.error) + end + + end + def delete_file interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, params.merge(identifier: @project.identifier)) if interactor.success? diff --git a/app/libs/custom_regexp.rb b/app/libs/custom_regexp.rb index 6012382b2..b735a631b 100644 --- a/app/libs/custom_regexp.rb +++ b/app/libs/custom_regexp.rb @@ -10,6 +10,7 @@ module CustomRegexp IP = /^((\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/ URL_REGEX = /\A(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?\z/i - REPOSITORY_NAME_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9\-\_\.]+[a-zA-Z0-9]$/ #只含有数字、字母、下划线不能以下划线开头和结尾 + # REPOSITORY_NAME_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9\-\_\.]+[a-zA-Z0-9]$/ #只含有数字、字母、下划线不能以下划线开头和结尾 + REPOSITORY_NAME_REGEX = /^[a-zA-Z0-9\-\_\.]+[a-zA-Z0-9]$/ #只含有数字、字母、下划线不能以下划线开头和结尾 MD_REGEX = /^.+(\.[m|M][d|D])$/ end diff --git a/app/views/repositories/_contributor.json.jbuilder b/app/views/repositories/_contributor.json.jbuilder index ea8a5ae30..b0547eba3 100644 --- a/app/views/repositories/_contributor.json.jbuilder +++ b/app/views/repositories/_contributor.json.jbuilder @@ -1,19 +1,19 @@ -user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"]}-#{contributor["email"]}") +user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"] || contributor["login"]}-#{contributor["email"]}") if user.blank? - json.contributions contributor["commits"] + json.contributions contributor["commits"] || contributor["contributions"] json.login nil json.type nil - json.name contributor["name"].downcase + json.name (contributor["name"] || contributor["login"]).to_s.downcase json.email contributor["email"] - json.image_url User::Avatar.get_letter_avatar_url(contributor["name"]) - json.contribution_perc User.new(login: contributor["name"], mail: contributor["email"]).simple_contribution_perc(project, contributor["contribution_perc"]) + json.image_url User::Avatar.get_letter_avatar_url(contributor["name"] || contributor["login"]) + json.contribution_perc User.new(login: (contributor["name"] || contributor["login"]), mail: contributor["email"]).simple_contribution_perc(project, contributor["contribution_perc"]) else - json.contributions contributor["commits"] + json.contributions contributor["commits"] || contributor["contributions"] json.id user["id"] json.login user["login"] json.email user["email"] json.type user["type"] - json.name user["name"].downcase + json.name (user["name"] || contributor["name"] || contributor["login"]).to_s.downcase json.image_url user["avatar_url"] db_user = User.find_by_id(user["id"]) json.contribution_perc db_user.simple_contribution_perc(project, contributor["contribution_perc"]) if db_user.present? diff --git a/config/routes.rb b/config/routes.rb index 0e760fbe9..f36aaa165 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -526,6 +526,7 @@ Rails.application.routes.draw do get :tags get :contributors post :create_file + post :replace_file put :update_file delete :delete_file post :repo_hook