From ba84cc7098fa0e310b7d4564367c5af01988191e Mon Sep 17 00:00:00 2001 From: shenmo7192 Date: Tue, 14 Jun 2022 23:30:06 +0800 Subject: [PATCH 01/67] =?UTF-8?q?Update=20README.md=20*fix:=20Issue?= =?UTF-8?q?=E7=9A=84=E4=B8=AD=E6=96=87=E7=BF=BB=E8=AF=91=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c2988e289..26761e767 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ GitLink(确实开源)是中国计算机学会(CCF)官方指定的开源 - **分布式协作开发**:基于Git打造分布式代码托管环境,提供免费公、私有代码仓库,支持在线文件编辑、代码分支管理、协作贡献统计、代码仓库复刻(Fork)、贡献合并请求(PR)、群智贡献审阅等功能,让您的项目在这里健康、快速的成长! -- **一站式过程管理**:提供易修(Issue)、里程碑、通知提醒、标签归档等多样化任务管理工具,支持各类开发任务的发布、指派与跟踪,同时提供在线Wiki文档、组织多粒度管理等功能,为您搭建一站式的项目过程管理环境,让您的团队协作更高效、过程更透明! +- **一站式过程管理**:提供疑修(Issue)、里程碑、通知提醒、标签归档等多样化任务管理工具,支持各类开发任务的发布、指派与跟踪,同时提供在线Wiki文档、组织多粒度管理等功能,为您搭建一站式的项目过程管理环境,让您的团队协作更高效、过程更透明! - **高效流水线运维**:融合DevOps思想,提供轻量级的工作流引擎(Engine),打通编码、测试、构建、部署等开发运维环节;支持自定义配置、代码静态扫描、构建自动触发、容器镜像托管等功能,同时支持接入第三方运维工具,让您的代码更加快速、可靠地形成高质量的产品! From 2ac6cdf69d9a32ff5084b49936e9dd6bdcd0cc80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Fri, 2 Sep 2022 11:15:35 +0800 Subject: [PATCH 02/67] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - Dockerfile | 33 +++++++++++++++++ Gemfile | 4 +-- Gemfile.lock | 24 +++++++++++-- README.md | 88 +++++++++++++++++++++++++++++++--------------- docker-compose.yml | 13 ++++--- 6 files changed, 125 insertions(+), 38 deletions(-) create mode 100644 Dockerfile diff --git a/.gitignore b/.gitignore index 2eac1d277..4a01bd5ec 100644 --- a/.gitignore +++ b/.gitignore @@ -81,7 +81,6 @@ db/bak/ docker/ educoder.sql redis_data/ -Dockerfile dump.rdb .tags* ceshi_user.xlsx diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..236e36935 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM ubuntu:18.04 + +RUN apt update + +RUN apt install -y openssl libssl-dev imagemagick git ruby-dev nodejs libmariadb-dev libmysqlclient-dev shared-mime-info libpq-dev libxml2-dev libxslt-dev +RUN DEBIAN_FRONTEND="noninteractive" apt -y install tzdata +RUN ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime + +WORKDIR /home/app/gitlink + +ADD ./ /home/app/gitlink + +RUN gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/ + +RUN gem update --system + +RUN gem install bundler +RUN gem install rake + +RUN rm -rf Gemfile.lock + +#RUN cp config/configuration.yml.example config/configuration.yml +#RUN cp config/database.yml.example config/database.yml +#RUN touch config/redis.yml +#RUN touch config/elasticsearch.yml + +RUN bundle install + +EXPOSE 4000 +RUN rails s -p 4000 -b '0.0.0.0' + + + diff --git a/Gemfile b/Gemfile index 3da6f273d..9ae0f0505 100644 --- a/Gemfile +++ b/Gemfile @@ -98,9 +98,9 @@ gem 'font-awesome-sass', '4.7.0' gem 'rails-i18n', '~> 5.1' # job -gem 'sidekiq' +gem 'sidekiq',"5.2.8" gem 'sinatra' -gem "sidekiq-cron", "~> 1.1" +gem "sidekiq-cron", "1.2.0" # batch insert gem 'bulk_insert' diff --git a/Gemfile.lock b/Gemfile.lock index e27c504aa..ee0c909a3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -106,6 +106,8 @@ GEM activerecord (>= 3.1.0, < 7) diff-lcs (1.3) diffy (3.3.0) + domain_name (0.5.20190701) + unf (>= 0.0.5, < 1.0.0) doorkeeper (5.5.1) railties (>= 5) doorkeeper-jwt (0.4.1) @@ -133,6 +135,8 @@ GEM fugit (1.4.1) et-orbi (~> 1.1, >= 1.1.8) raabro (~> 1.4) + gitea-client (0.10.5) + rest-client (~> 2.1.0) globalid (0.4.2) activesupport (>= 4.2.0) grape-entity (0.7.1) @@ -143,6 +147,9 @@ GEM harmonious_dictionary (0.0.1) hashie (3.6.0) htmlentities (4.3.4) + http-accept (1.7.0) + http-cookie (1.0.5) + domain_name (~> 0.5) i18n (1.8.2) concurrent-ruby (~> 1.0) io-like (0.3.1) @@ -180,6 +187,9 @@ GEM mimemagic (~> 0.3.2) maruku (0.7.3) method_source (0.9.2) + mime-types (3.4.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2022.0105) mimemagic (0.3.10) nokogiri (~> 1) rake @@ -193,6 +203,7 @@ GEM mustermann (1.1.1) ruby2_keywords (~> 0.0.1) mysql2 (0.5.3) + netrc (0.11.0) nio4r (2.5.2) nokogiri (1.10.8) mini_portile2 (~> 2.4.0) @@ -292,6 +303,11 @@ GEM regexp_parser (1.7.0) request_store (1.5.0) rack (>= 1.4) + rest-client (2.1.0) + http-accept (>= 1.7.0, < 2.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 4.0) + netrc (~> 0.8) reverse_markdown (1.4.0) nokogiri roo (2.8.3) @@ -418,6 +434,9 @@ GEM thread_safe (~> 0.1) uglifier (4.2.0) execjs (>= 0.3.0, < 3) + unf (0.1.4) + unf_ext + unf_ext (0.0.8.2) unicode-display_width (1.6.1) web-console (3.7.0) actionview (>= 5.0) @@ -459,6 +478,7 @@ DEPENDENCIES enumerize faraday (~> 0.15.4) font-awesome-sass (= 4.7.0) + gitea-client (~> 0.10.2) grape-entity (~> 0.7.1) groupdate (~> 4.1.0) harmonious_dictionary (~> 0.0.1) @@ -496,8 +516,8 @@ DEPENDENCIES sass-rails (~> 5.0) searchkick selenium-webdriver - sidekiq - sidekiq-cron (~> 1.1) + sidekiq (= 5.2.8) + sidekiq-cron (= 1.2.0) simple_form simple_xlsx_reader sinatra diff --git a/README.md b/README.md index 26761e767..ef86a4c35 100644 --- a/README.md +++ b/README.md @@ -34,18 +34,52 @@ GitLink(确实开源)是中国计算机学会(CCF)官方指定的开源 * imagemagick ### 步骤 - -(1)克隆稳定版本 +(1)安装 Rails 必要的一些三方库: +- Mac OS X +```bash + brew install imagemagick ghostscript libxml2 libxslt libiconv ``` + +- Ubuntu +```bash +sudo apt-get update +sudo apt-get install -y openssl libssl-dev imagemagick git ruby-dev nodejs libmariadb-dev libmysqlclient-dev shared-mime-info libpq-dev libxml2-dev libxslt-dev +sudo DEBIAN_FRONTEND="noninteractive" apt-get install -y tzdata +sudo ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime +``` + +(2)安装 Ruby, Rails 运行环境:[如何快速正确的安装 Ruby, Rails 运行环境](https://ruby-china.org/wiki/install_ruby_guide) +```bash +#检验环境是否正确 +ruby -v +#ruby 2.4.x ... + +gem -v +#3.x.x + +bundle -v +#Bundler version 2.x.x + +rails -v +#Rails 5.2.x +``` + +(3)克隆稳定版本 +```bash git clone -b master https://gitlink.org.cn/Gitlink/forgeplus.git ``` -(2)安装依赖包 +(4)安装依赖包 ```bash -cd forgeplus && bundle install +#进入目录 +cd forgeplus +#删除Gemfile.lock +rm -rf Gemfile.lock +#安装依赖包 +bundle install ``` -(3)配置初始化文件:进入项目根目录执行以下命令 +(5)配置初始化文件:进入项目根目录执行以下命令 ```bash cp config/configuration.yml.example config/configuration.yml cp config/database.yml.example config/database.yml @@ -53,8 +87,8 @@ touch config/redis.yml touch config/elasticsearch.yml ``` -(4)配置数据库:数据库配置信息请查看/config/database.yml文件,项目默认采用mysql数据库, 如需更改,请自行修改配置信息,默认配置如下 -```bash +(6)配置数据库:数据库配置信息请查看/config/database.yml文件,项目默认采用mysql数据库, 如需更改,请自行修改配置信息,默认配置如下 +```yaml default: &default adapter: mysql2 host: 127.0.0.1 @@ -63,7 +97,7 @@ default: &default password: 123456 ``` -(5)配置gitea服务(可选):如需要部署自己的gitea平台,请参考[gitea官方平台文档](https://docs.gitea.io/zh-cn/install-from-binary/)。因目前gitea平台api受限,暂时推荐从forge平台获取[gitea部署文件](https://www.gitlink.org.cn/Gitlink/gitea-binary)进行部署 +(7)配置gitea服务(可选):如需要部署自己的gitea平台,请参考[gitea官方平台文档](https://docs.gitea.io/zh-cn/install-from-binary/)。因目前gitea平台api受限,暂时推荐从forge平台获取[gitea部署文件](https://www.gitlink.org.cn/Gitlink/gitea-binary)进行部署 - 配置gitea服务步骤: @@ -71,7 +105,7 @@ default: &default -- 修改forge平台的 config/configuration.yml中的gitea服务指向地址,如: -```ruby +```yaml gitea: access_key_id: 'root' access_key_secret: 'password' @@ -79,61 +113,59 @@ gitea: base_url: '/api/v1' ``` -(6)安装redis环境:请自行搜索各平台如何安装部署redis环境 +(8)配置/config/database.yml文件(安装redis环境:请自行搜索各平台如何安装部署redis环境) +```yaml +default: &default + url: redis://localhost:6379 + db: 1 -(7)安装imagemagick插件: -- Mac OS X -```bash - brew install imagemagick ghostscript +production: + <<: *default + url: redis://localhost:6379 ``` -- Linux -```bash -sudo apt-get install -y imagemagick -``` - -(8)创建数据库:开发环境为development, 生成环境为production +(9)创建数据库:开发环境为development, 生成环境为production ```bash rails db:create RAILS_ENV=development ``` -(9)导入数据表结构 +(10)导入数据表结构 ```bash bundle exec rake sync_table_structure:import_csv ``` -(10)执行migrate迁移文件:开发环境为development, 生成环境为production +(11)执行migrate迁移文件:开发环境为development, 生成环境为production ```bash rails db:migrate RAILS_ENV=development ``` -(11)clone前端代码:将前端代码克隆到public/react目录下,目录结构应该是: public/react/build +(12)clone前端代码:将前端代码克隆到public/react目录下,目录结构应该是: public/react/build ```bash git clone -b standalone https://gitlink.org.cn/Gitlink/build.git ``` -(12)启动redis(此处以macOS系统为例) +(13)启动redis(此处以macOS系统为例) ```bash redis-server& ``` -(13)启动sidekiq:开发环境为development, 生成环境为production +(14)启动sidekiq:开发环境为development, 生成环境为production ```bash bundle exec sidekiq -C config/sidekiq.yml -e production -d ``` -(14)启动rails服务 +(15)启动rails服务 ```bash rails s ``` -(15)浏览器访问:在浏览器中输入如下地址访问 +(16)浏览器访问:在浏览器中输入如下地址访问 ```bash http://localhost:3000/ ``` -(16)其他说明:通过页面注册以第一个用户为平台管理员用户 +(17)其他说明:通过页面注册以第一个用户为平台管理员用户 ## 页面展示 diff --git a/docker-compose.yml b/docker-compose.yml index 16f600df4..ef066bc16 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,7 +13,7 @@ services: MYSQL_DATABASE: educoder redis: - image: redis:3.2 + image: redis:6.2.5 container_name: redis restart: always ports: @@ -22,14 +22,17 @@ services: - ./redis_data:/data web: - image: guange/educoder:latest - command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 4000 -b '0.0.0.0'" + image: gitlink-ubuntu18.04:latest + build: + context: ../ + dockerfile: Dockerfile +# command: bash -c "rm -f tmp/pids/server.pid && rails s -p 4000 -b '0.0.0.0'" stdin_open: true tty: true volumes: - - .:/app + - .:/home/app/gitlink ports: - "4000:4000" depends_on: - mysql - - redis \ No newline at end of file + - redis From 6857f733841e25e55f1ca4d6f287fa12831bd6fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Fri, 2 Sep 2022 11:26:24 +0800 Subject: [PATCH 03/67] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ef86a4c35..2e84b704d 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ rails db:migrate RAILS_ENV=development (12)clone前端代码:将前端代码克隆到public/react目录下,目录结构应该是: public/react/build ```bash -git clone -b standalone https://gitlink.org.cn/Gitlink/build.git +git clone -b master https://gitlink.org.cn/Gitlink/build.git ``` (13)启动redis(此处以macOS系统为例) From 88ff9abe49aced630f0f398c91cccab079febff7 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 22 Sep 2022 16:47:28 +0800 Subject: [PATCH 04/67] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2e84b704d..f9f9cc977 100644 --- a/README.md +++ b/README.md @@ -210,3 +210,4 @@ http://localhost:3000/ - [Git常用命令](https://git-scm.com/) ## 许可证协议 +MulanPSL-2.0 From cf1f78b4933fb4742f17a6746d347e4d794eada8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 22 Sep 2022 16:51:56 +0800 Subject: [PATCH 05/67] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index f9f9cc977..2e84b704d 100644 --- a/README.md +++ b/README.md @@ -210,4 +210,3 @@ http://localhost:3000/ - [Git常用命令](https://git-scm.com/) ## 许可证协议 -MulanPSL-2.0 From 7c80f74e261e5d8011ffbbe5538ea97bdb74a8c4 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 6 Jan 2023 11:16:50 +0800 Subject: [PATCH 06/67] =?UTF-8?q?fixed=20=E4=BB=A3=E7=A0=81=E8=B4=A1?= =?UTF-8?q?=E7=8C=AE=E8=80=85email?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../projects/code_stats/index.json.jbuilder | 2 +- .../v1/users/_commit_user_email.json.jbuilder | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 app/views/api/v1/users/_commit_user_email.json.jbuilder diff --git a/app/views/api/v1/projects/code_stats/index.json.jbuilder b/app/views/api/v1/projects/code_stats/index.json.jbuilder index d438e2624..0b64270f7 100644 --- a/app/views/api/v1/projects/code_stats/index.json.jbuilder +++ b/app/views/api/v1/projects/code_stats/index.json.jbuilder @@ -6,7 +6,7 @@ json.deletions @result_object["deletions"] json.commit_count_in_all_branches @result_object["commit_count_in_all_branches"] json.authors @result_object["authors"].each do |author| json.author do - json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(author), name: author['name'] } + json.partial! 'api/v1/users/commit_user_email', locals: { user: render_cache_commit_author(author), name: author['name'], email: author['email'] } end json.commits author["commits"] json.additions author["additions"] diff --git a/app/views/api/v1/users/_commit_user_email.json.jbuilder b/app/views/api/v1/users/_commit_user_email.json.jbuilder new file mode 100644 index 000000000..c4963628a --- /dev/null +++ b/app/views/api/v1/users/_commit_user_email.json.jbuilder @@ -0,0 +1,22 @@ +if user.present? + if user.is_a?(Hash) + json.id user["id"] + json.login user["login"] + json.name user["name"] + json.type user["type"] + json.image_url user["avatar_url"] + else + json.id user.id + json.login user.login + json.name user.real_name + json.type user&.type + json.image_url url_to_avatar(user) + end +else + json.id nil + json.login name + json.name name + json.email email + json.type nil + json.image_url User::Avatar.get_letter_avatar_url(name) +end From fdb713b76d28843480aef787ee8074b9779412d0 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 9 Jan 2023 15:14:51 +0800 Subject: [PATCH 07/67] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=E7=94=A8=E6=88=B7=E9=82=AE=E7=AE=B1=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E6=97=A7=E7=9A=84cache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/users/update_email_service.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/services/api/v1/users/update_email_service.rb b/app/services/api/v1/users/update_email_service.rb index d17f101fd..d2d5fd735 100644 --- a/app/services/api/v1/users/update_email_service.rb +++ b/app/services/api/v1/users/update_email_service.rb @@ -31,6 +31,7 @@ class Api::V1::Users::UpdateEmailService < ApplicationService change_user_email excute_data_to_gitea excute_change_email_from_gitea + remove_old_cache_for_user end return gitea_data @@ -68,4 +69,8 @@ class Api::V1::Users::UpdateEmailService < ApplicationService $gitea_client.delete_user_emails({body: {emails: [@old_mail]}.to_json, query: request_params}) $gitea_client.post_user_emails({body: {emails: [@mail]}.to_json, query: request_params}) end + + def remove_old_cache_for_user + $redis_cache.hdel("v2-owner-common:#{@user.login}-#{@old_mail}") + end end \ No newline at end of file From dfe56d9f758c25fb9b676aec2965475a8d83482a Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 9 Jan 2023 15:39:49 +0800 Subject: [PATCH 08/67] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/users/update_email_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/users/update_email_service.rb b/app/services/api/v1/users/update_email_service.rb index d2d5fd735..7317b2fe6 100644 --- a/app/services/api/v1/users/update_email_service.rb +++ b/app/services/api/v1/users/update_email_service.rb @@ -71,6 +71,6 @@ class Api::V1::Users::UpdateEmailService < ApplicationService end def remove_old_cache_for_user - $redis_cache.hdel("v2-owner-common:#{@user.login}-#{@old_mail}") + $redis_cache.del("v2-owner-common:#{@user.login}-#{@old_mail}") end end \ No newline at end of file From 4f92b298898984e46ef778bd6f3daffdb849d265 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 31 Jan 2023 14:19:07 +0800 Subject: [PATCH 09/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=BB=BA?= =?UTF-8?q?=E6=9C=A8=E8=B4=A6=E5=8F=B7=E7=A6=81=E6=AD=A2=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 1 + app/services/api/v1/users/update_email_service.rb | 1 + app/services/api/v1/users/update_phone_service.rb | 1 + 3 files changed, 3 insertions(+) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 4a104129b..0d1660a0f 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -213,6 +213,7 @@ class AccountsController < ApplicationController def change_password @user = User.find_by(login: params[:login]) + return render_error("此用户禁止修改密码!") if @user.id.to_i === 104691 return render_error("未找到相关用户!") if @user.blank? return render_error("旧密码不正确") unless @user.check_password?(params[:old_password]) diff --git a/app/services/api/v1/users/update_email_service.rb b/app/services/api/v1/users/update_email_service.rb index 7841a7100..9418cac6f 100644 --- a/app/services/api/v1/users/update_email_service.rb +++ b/app/services/api/v1/users/update_email_service.rb @@ -18,6 +18,7 @@ class Api::V1::Users::UpdateEmailService < ApplicationService end def call + raise Error, "此用户禁止修改邮箱." if @user.id.to_i === 104691 raise Error, errors.full_messages.join(",") unless valid? raise Error, "密码不正确." unless @user.check_password?(@password) exist_owner = Owner.find_by(mail: @mail) diff --git a/app/services/api/v1/users/update_phone_service.rb b/app/services/api/v1/users/update_phone_service.rb index e41178e3d..ed53d7eb5 100644 --- a/app/services/api/v1/users/update_phone_service.rb +++ b/app/services/api/v1/users/update_phone_service.rb @@ -15,6 +15,7 @@ class Api::V1::Users::UpdatePhoneService < ApplicationService end def call + raise Error, "此用户禁止修改手机号." if @user.id.to_i === 104691 raise Error, errors.full_messages.join(",") unless valid? raise Error, "密码不正确." unless @user.check_password?(@password) exist_owner = Owner.find_by(phone: @phone) From 0229d99e74a5455427b95b06b33676c2ec930b7a Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 1 Feb 2023 14:25:55 +0800 Subject: [PATCH 10/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E7=AE=A1=E7=90=86=E6=8E=92=E8=A1=8C=E6=A6=9C=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/projects_rank_controller.rb | 14 ++++ .../admins/users_rank_controller.rb | 15 ++++ .../cache/v2/project_date_rank_service.rb | 11 +++ app/views/admins/projects_rank/index.html.erb | 74 +++++++++++++++++++ app/views/admins/shared/_sidebar.html.erb | 6 ++ app/views/admins/users_rank/index.html.erb | 74 +++++++++++++++++++ config/routes.rb | 2 + 7 files changed, 196 insertions(+) create mode 100644 app/controllers/admins/projects_rank_controller.rb create mode 100644 app/controllers/admins/users_rank_controller.rb create mode 100644 app/views/admins/projects_rank/index.html.erb create mode 100644 app/views/admins/users_rank/index.html.erb diff --git a/app/controllers/admins/projects_rank_controller.rb b/app/controllers/admins/projects_rank_controller.rb new file mode 100644 index 000000000..b92037caa --- /dev/null +++ b/app/controllers/admins/projects_rank_controller.rb @@ -0,0 +1,14 @@ +class Admins::ProjectsRankController < Admins::BaseController + + def index + @rank_date = rank_date + @date_rank = $redis_cache.zrevrange("v2-project-rank-#{rank_date}", 0, -1, withscores: true) + end + + private + + def rank_date + params.fetch(:date, Date.today.to_s) + end + +end \ No newline at end of file diff --git a/app/controllers/admins/users_rank_controller.rb b/app/controllers/admins/users_rank_controller.rb new file mode 100644 index 000000000..2c7a62ae5 --- /dev/null +++ b/app/controllers/admins/users_rank_controller.rb @@ -0,0 +1,15 @@ +class Admins::UsersRankController < Admins::BaseController + + def index + @rank_date = rank_date + @date_rank = $redis_cache.zrevrange("v2-user-rank-#{rank_date}", 0, -1, withscores: true) + end + + private + + def rank_date + params.fetch(:date, Date.today.to_s) + end + + +end \ No newline at end of file diff --git a/app/services/cache/v2/project_date_rank_service.rb b/app/services/cache/v2/project_date_rank_service.rb index 9d8ffca90..2ada442a8 100644 --- a/app/services/cache/v2/project_date_rank_service.rb +++ b/app/services/cache/v2/project_date_rank_service.rb @@ -28,6 +28,10 @@ class Cache::V2::ProjectDateRankService < ApplicationService "v2-project-rank-#{@rank_date.to_s}" end + def project_rank_statistic_key + "v2-project-statistic:#{@project_id}-#{@rank_date.to_s}" + end + def project_rank $redis_cache.zscore(project_rank_key, @project_id) end @@ -35,24 +39,31 @@ class Cache::V2::ProjectDateRankService < ApplicationService def set_project_rank if @visits.present? $redis_cache.zincrby(project_rank_key, @visits.to_i * 1, @project_id) + $redis_cache.hincrby(project_rank_statistic_key, "visits", @visits.to_i) end if @watchers.present? $redis_cache.zincrby(project_rank_key, @watchers.to_i * 5, @project_id) + $redis_cache.hincrby(project_rank_statistic_key, "watchers", @watchers.to_i) end if @praises.present? $redis_cache.zincrby(project_rank_key, @praises.to_i * 5, @project_id) + $redis_cache.hincrby(project_rank_statistic_key, "praises", @praises.to_i) end if @forks.present? $redis_cache.zincrby(project_rank_key, @forks.to_i * 10, @project_id) + $redis_cache.hincrby(project_rank_statistic_key, "forks", @forks.to_i) end if @issues.present? $redis_cache.zincrby(project_rank_key, @issues.to_i * 5, @project_id) + $redis_cache.hincrby(project_rank_statistic_key, "issues", @issues.to_i) end if @pullrequests.present? $redis_cache.zincrby(project_rank_key, @pullrequests.to_i * 10, @project_id) + $redis_cache.hincrby(project_rank_statistic_key, "pullrequests", @pullrequests.to_i) end if @commits.present? $redis_cache.zincrby(project_rank_key, @commits.to_i * 5, @project_id) + $redis_cache.hincrby(project_rank_statistic_key, "commits", @commits.to_i) end $redis_cache.zscore(project_rank_key, @project_id) diff --git a/app/views/admins/projects_rank/index.html.erb b/app/views/admins/projects_rank/index.html.erb new file mode 100644 index 000000000..056e0a0da --- /dev/null +++ b/app/views/admins/projects_rank/index.html.erb @@ -0,0 +1,74 @@ +<% define_admin_breadcrumbs do %> + <% add_admin_breadcrumb('项目排行榜', admins_path) %> +<% end %> + + +
+ <%= form_tag(admins_projects_rank_index_path, method: :get, class: 'form-inline search-form flex-1', id: 'project-rank-date-form') do %> +
+ + <% dates_array = (0..30).to_a.map { |item| [(Date.today-item.days).to_s, (Date.today-item.days).to_s] } %> + <%= select_tag(:date, options_for_select(dates_array, params[:date]), class:"form-control",id: "project-rank-date-select")%> +
+ <% end %> + +
+ +
+ + + + + + + + + + + + + + + + + <% @date_rank.each_with_index do |item, index| %> + + + <% project_common = $redis_cache.hgetall("v2-project-common:#{item[0]}") %> + <% owner_common = $redis_cache.hgetall("v2-owner-common:#{project_common["owner_id"]}")%> + + + + <% project_date_statistic_key = "v2-project-statistic:#{item[0]}-#{@rank_date}"%> + <% if $redis_cache.exists(project_date_statistic_key)%> + <% visits = $redis_cache.hget(project_date_statistic_key, "visits") %> + + <% watchers = $redis_cache.hget(project_date_statistic_key, "watchers") %> + + <% praises = $redis_cache.hget(project_date_statistic_key, "praises") %> + + <% forks = $redis_cache.hget(project_date_statistic_key, "forks") %> + + <% issues = $redis_cache.hget(project_date_statistic_key, "issues") %> + + <% pullrequests = $redis_cache.hget(project_date_statistic_key, "pullrequests") %> + + <% commits = $redis_cache.hget(project_date_statistic_key, "commits") %> + + <% else %> + + <% end %> + + <% end %> + +
排名项目得分访问数关注数点赞数fork数疑修数合并请求数提交数
<%= index + 1%> + /<%= project_common["identifier"]%>"> + <%= project_common["name"] %> + + <%= item[1] %><%= visits || 0 %><%= watchers || 0 %><%= praises || 0 %><%= forks || 0 %><%= issues || 0 %><%= pullrequests || 0 %><%= commits || 0 %>暂无数据
+
+ \ No newline at end of file diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index d3a752909..88ba91205 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -14,6 +14,12 @@
  • <%= sidebar_item(admins_path, '概览', icon: 'dashboard', controller: 'admins-dashboards') %>
  • +
  • + <%= sidebar_item_group('#user-submenu', '排行榜', icon: 'user') do %> +
  • <%= sidebar_item(admins_users_rank_index_path, '用户排行榜', icon: 'user', controller: 'admins-users_rank') %>
  • +
  • <%= sidebar_item(admins_projects_rank_index_path, '项目排行榜', icon: 'user', controller: 'admins-projects_rank') %>
  • + <% end %> +
  • <%= sidebar_item_group('#user-submenu', '用户', icon: 'user') do %>
  • <%= sidebar_item(admins_users_path, '用户列表', icon: 'user', controller: 'admins-users') %>
  • diff --git a/app/views/admins/users_rank/index.html.erb b/app/views/admins/users_rank/index.html.erb new file mode 100644 index 000000000..9fa5a5aec --- /dev/null +++ b/app/views/admins/users_rank/index.html.erb @@ -0,0 +1,74 @@ +<% define_admin_breadcrumbs do %> + <% add_admin_breadcrumb('用户排行榜', admins_path) %> +<% end %> + + +
    + <%= form_tag(admins_users_rank_index_path, method: :get, class: 'form-inline search-form flex-1', id: 'user-rank-date-form') do %> +
    + + <% dates_array = (0..30).to_a.map { |item| [(Date.today-item.days).to_s, (Date.today-item.days).to_s] } %> + <%= select_tag(:date, options_for_select(dates_array, params[:date]), class:"form-control",id: "user-rank-date-select")%> +
    + <% end %> + +
    + +
    + + + + + + + + + + + + + + + <% @date_rank.each_with_index do |item, index| %> + + + <% owner_common = $redis_cache.hgetall("v2-owner-common:#{item[0]}")%> + + <% user_date_statistic_key = "v2-user-statistic:#{item[0]}-#{@rank_date}"%> + <% follow_count = $redis_cache.hget(user_date_statistic_key, "follow-count") || 0 %> + <% pullrequest_count = $redis_cache.hget(user_date_statistic_key, "pullrequest-count") || 0 %> + <% issues_count = $redis_cache.hget(user_date_statistic_key, "issue-count") || 0 %> + <% project_count = $redis_cache.hget(user_date_statistic_key, "project-count") || 0 %> + <% fork_count = $redis_cache.hget(user_date_statistic_key, "fork-count") || 0 %> + <% project_watchers_count = $redis_cache.hget(user_date_statistic_key, "project-watcher-count") || 0 %> + <% project_praises_count = $redis_cache.hget(user_date_statistic_key, "project-praise-count") || 0 %> + <% project_language = $redis_cache.hget(user_date_statistic_key, "project-language") %> + <% project_languages_count = project_language.nil? || project_language == "{}" ? 0 : JSON.parse(project_language).length %> + + <% influence = (60.0 + follow_count.to_i / (follow_count.to_i + 20.0) * 40.0).to_i %> + <% contribution = (60.0 + pullrequest_count.to_i / (pullrequest_count.to_i + 20.0) * 40.0).to_i %> + <% activity = (60.0 + issues_count.to_i / (issues_count.to_i + 80.0) * 40.0).to_i %> + <% experience = 10 * project_count.to_i + 5 * fork_count.to_i + project_watchers_count.to_i + project_praises_count.to_i %> + <% experience = (60.0 + experience / (experience + 100.0) * 40.0).to_i %> + <% language = (60.0 + project_languages_count.to_i / (project_languages_count.to_i + 5.0) * 40.0).to_i %> + <% score = influence+ contribution + activity + experience + language%> + + + + + + + + <% end %> + +
    排名用户得分影响力贡献度活跃度项目经验语言能力
    <%= index + 1%> + "> + <%= owner_common["name"] %> + + <%= score %><%= influence%><%= contribution%><%= activity%><%= experience%><%= language%>
    +
    + \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 233b40a82..b4e856640 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -716,6 +716,8 @@ Rails.application.routes.draw do get :visits_static end end + resources :users_rank, only: [:index] + resources :projects_rank, only: [:index] resources :sites resources :edu_settings resources :project_languages From 112ee39efda3832cd1138959b2ec92e68db60757 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 1 Feb 2023 14:50:12 +0800 Subject: [PATCH 11/67] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=8E=92?= =?UTF-8?q?=E8=A1=8C=E6=A6=9C=E6=95=B0=E6=8D=AE=E4=B8=8D=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E5=B7=B2=E5=88=A0=E9=99=A4=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admins/projects_rank_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/admins/projects_rank_controller.rb b/app/controllers/admins/projects_rank_controller.rb index b92037caa..c4f968da4 100644 --- a/app/controllers/admins/projects_rank_controller.rb +++ b/app/controllers/admins/projects_rank_controller.rb @@ -2,6 +2,8 @@ class Admins::ProjectsRankController < Admins::BaseController def index @rank_date = rank_date + deleted_data = $redis_cache.smembers("v2-project-rank-deleted") + $redis_cache.zrem("v2-project-rank-#{rank_date}", deleted_data) unless deleted_data.blank? @date_rank = $redis_cache.zrevrange("v2-project-rank-#{rank_date}", 0, -1, withscores: true) end From 913eb62923c5bcad6a5a1c3e885405900977fab4 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 1 Feb 2023 15:44:40 +0800 Subject: [PATCH 12/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=8E=92?= =?UTF-8?q?=E8=A1=8C=E6=A6=9C=E6=AF=8F=E6=97=A5=E7=BB=9F=E8=AE=A1=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=AE=BE=E7=BD=AE=E4=B8=80=E4=B8=AA=E8=BF=87=E6=9C=9F?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/cache/v2/project_date_rank_service.rb | 4 ++++ app/services/cache/v2/user_date_rank_service.rb | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/app/services/cache/v2/project_date_rank_service.rb b/app/services/cache/v2/project_date_rank_service.rb index 2ada442a8..9df69bbb4 100644 --- a/app/services/cache/v2/project_date_rank_service.rb +++ b/app/services/cache/v2/project_date_rank_service.rb @@ -67,5 +67,9 @@ class Cache::V2::ProjectDateRankService < ApplicationService end $redis_cache.zscore(project_rank_key, @project_id) + + # 设置过期时间(一个月) + $redis_cache.expireat(project_rank_key, (@rank_date+30.days).to_time.to_i) + $redis_cache.expireat(project_rank_statistic_key, (@rank_date+30.days).to_time.to_i) end end \ No newline at end of file diff --git a/app/services/cache/v2/user_date_rank_service.rb b/app/services/cache/v2/user_date_rank_service.rb index a3351b724..b669e4d67 100644 --- a/app/services/cache/v2/user_date_rank_service.rb +++ b/app/services/cache/v2/user_date_rank_service.rb @@ -115,5 +115,9 @@ class Cache::V2::UserDateRankService < ApplicationService $redis_cache.zadd(user_rank_key, score-300, @user_id) if score > 300 $redis_cache.zscore(user_rank_key, @user_id) + + # 设置过期时间(一个月) + $redis_cache.expireat(user_rank_key, (@rank_date+30.days).to_time.to_i) + $redis_cache.expireat(user_date_statistic_key, (@rank_date+30.days).to_time.to_i) end end \ No newline at end of file From 785ae1364965c9ac1845c06307d2a7add4aacc96 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 1 Feb 2023 17:03:16 +0800 Subject: [PATCH 13/67] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E5=BC=80=E9=80=9A=E5=BB=BA=E6=9C=A8DevOps=20job=E5=BB=B6?= =?UTF-8?q?=E8=BF=9F5=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 2 +- app/jobs/migrate_remote_repository_job.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 53f6d1aea..52c776477 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -53,7 +53,7 @@ class ProjectsController < ApplicationController ActiveRecord::Base.transaction do Projects::CreateForm.new(project_params).validate! @project = Projects::CreateService.new(current_user, project_params).call - OpenProjectDevOpsJob.perform_later(@project&.id, current_user.id) + OpenProjectDevOpsJob.set(wait: 5.seconds).perform_later(@project&.id, current_user.id) end rescue Exception => e uid_logger_error(e.message) diff --git a/app/jobs/migrate_remote_repository_job.rb b/app/jobs/migrate_remote_repository_job.rb index 5e56901a0..696607ae3 100644 --- a/app/jobs/migrate_remote_repository_job.rb +++ b/app/jobs/migrate_remote_repository_job.rb @@ -15,7 +15,7 @@ class MigrateRemoteRepositoryJob < ApplicationJob ## open jianmu devops project_id = repo&.project&.id puts "############ mirror project_id,user_id: #{project_id},#{user_id} ############" - OpenProjectDevOpsJob.perform_later(project_id, user_id) if project_id.present? && user_id.present? + OpenProjectDevOpsJob.set(wait: 5.seconds).perform_later(project_id, user_id) if project_id.present? && user_id.present? puts "############ mirror status: #{repo.mirror.status} ############" else repo&.mirror&.failed! From 2668630f2ac548d98429b293e244fcaafdfa576d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 1 Feb 2023 17:23:48 +0800 Subject: [PATCH 14/67] =?UTF-8?q?=E9=A1=B9=E7=9B=AEfored=5Fcount=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=97=B6updated=5Fon=E5=90=8C=E6=97=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project.rb | 2 +- app/services/projects/fork_service.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index a8816bd76..e1670bf53 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -188,7 +188,7 @@ class Project < ApplicationRecord forked_project = self.forked_from_project if forked_project.present? forked_project.decrement(:forked_count, 1) - forked_project.update_column(:forked_count, forked_project.forked_count) + forked_project.update_attribute(:forked_count, forked_project.forked_count) end end diff --git a/app/services/projects/fork_service.rb b/app/services/projects/fork_service.rb index 837775d36..f8b38df47 100644 --- a/app/services/projects/fork_service.rb +++ b/app/services/projects/fork_service.rb @@ -29,7 +29,7 @@ class Projects::ForkService < ApplicationService ProjectUnit.init_types(clone_project.id) - @project.update_column('forked_count', @project&.forked_count.to_i + 1) + @project.update_attribute('forked_count', @project&.forked_count.to_i + 1) new_repository.update_column('url', result['clone_url']) if result ForkUser.create(project_id: @project.id, fork_project_id: clone_project.id, user_id: clone_project.user_id) From a03d1efcb0dbee9e30d3cb3cd0b280f634b13b4f Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 2 Feb 2023 14:05:40 +0800 Subject: [PATCH 15/67] =?UTF-8?q?fixed=20=E5=A6=82=E6=9E=9C=E6=9C=89?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=85=B3=E9=94=AE=E5=AD=97=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?ES=E6=90=9C=E7=B4=A2=E7=BB=93=E6=9E=9C=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/queries/projects/list_query.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index 447ab5070..c4c81957b 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -22,10 +22,12 @@ class Projects::ListQuery < ApplicationQuery sort_direction = params[:sort_direction] || "desc" collection = optimize_sorting(collection, sort) if params[:category_id].present? - custom_sort(collection, sort, sort_direction) - - # scope = scope.reorder("projects.#{sort} #{sort_direction}") - # scope + # 如果有搜索关键字根据ES搜索结果排序 + if params[:search].present? && @ids.present? + collection.reorder(Arel.sql("FIELD(projects.id,#{@ids.join(',')})")) + else + custom_sort(collection, sort, sort_direction) + end end def filter_projects(collection) @@ -38,10 +40,10 @@ class Projects::ListQuery < ApplicationQuery end def by_search(items) - ids = Projects::ElasticsearchService.call(params[:search]) + @ids = Projects::ElasticsearchService.call(params[:search]) items = items.where(platform: 'forge') - if ids.present? - items = items.where(id: ids).by_name_or_identifier(params[:search]) + if @ids.present? + items = items.where(id: @ids).by_name_or_identifier(params[:search]) else items = items.by_name_or_identifier(params[:search]) end From 9fe3b5ae3ef0ee17ba4fe5bad98c9cea2a39d6ee Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 2 Feb 2023 18:10:26 +0800 Subject: [PATCH 16/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Acode=5Fstats?= =?UTF-8?q?=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/code_stats_controller.rb | 2 +- .../api/v1/projects/code_stats/list_service.rb | 8 ++++++-- .../v1/projects/code_stats/index.json.jbuilder | 15 ++++++++------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/controllers/api/v1/projects/code_stats_controller.rb b/app/controllers/api/v1/projects/code_stats_controller.rb index 7ec671f3c..333cfe86a 100644 --- a/app/controllers/api/v1/projects/code_stats_controller.rb +++ b/app/controllers/api/v1/projects/code_stats_controller.rb @@ -2,7 +2,7 @@ class Api::V1::Projects::CodeStatsController < Api::V1::BaseController before_action :require_public_and_member_above, only: [:index] def index - @result_object = Api::V1::Projects::CodeStats::ListService.call(@project, {ref: params[:ref]}, current_user&.gitea_token) + @result_object = Api::V1::Projects::CodeStats::ListService.call(@project, {page: page, limit, limit, ref: params[:ref]}, current_user&.gitea_token) puts @result_object end end \ No newline at end of file diff --git a/app/services/api/v1/projects/code_stats/list_service.rb b/app/services/api/v1/projects/code_stats/list_service.rb index 84f4bac36..fa9d68bec 100644 --- a/app/services/api/v1/projects/code_stats/list_service.rb +++ b/app/services/api/v1/projects/code_stats/list_service.rb @@ -1,6 +1,6 @@ class Api::V1::Projects::CodeStats::ListService < ApplicationService - attr_reader :project, :ref, :owner, :repo, :token + attr_reader :project, :ref, :owner, :repo, :token, :page, :limit attr_accessor :gitea_data def initialize(project, params, token=nil) @@ -9,6 +9,8 @@ class Api::V1::Projects::CodeStats::ListService < ApplicationService @owner = project&.owner.login @repo = project&.identifier @token = token + @page = params[:page] + @limit = params[:limit] end def call @@ -20,7 +22,9 @@ class Api::V1::Projects::CodeStats::ListService < ApplicationService private def request_params param = { - access_token: token + access_token: token, + page: page, + limit: limit } param.merge!(ref: ref) if ref.present? diff --git a/app/views/api/v1/projects/code_stats/index.json.jbuilder b/app/views/api/v1/projects/code_stats/index.json.jbuilder index 0b64270f7..ecb4767e4 100644 --- a/app/views/api/v1/projects/code_stats/index.json.jbuilder +++ b/app/views/api/v1/projects/code_stats/index.json.jbuilder @@ -1,10 +1,11 @@ -json.author_count @result_object["author_count"] -json.commit_count @result_object["commit_count"] -json.change_files @result_object["change_files"] -json.additions @result_object["additions"] -json.deletions @result_object["deletions"] -json.commit_count_in_all_branches @result_object["commit_count_in_all_branches"] -json.authors @result_object["authors"].each do |author| +json.total_count @result_object[:total_data].to_i +json.author_count @result_object[:data]["author_count"] +json.commit_count @result_object[:data]["commit_count"] +json.change_files @result_object[:data]["change_files"] +json.additions @result_object[:data]["additions"] +json.deletions @result_object[:data]["deletions"] +json.commit_count_in_all_branches @result_object[:data]["commit_count_in_all_branches"] +json.authors @result_object[:data]["authors"].each do |author| json.author do json.partial! 'api/v1/users/commit_user_email', locals: { user: render_cache_commit_author(author), name: author['name'], email: author['email'] } end From 87412643cdbcec523ccbd40a1ac1edd519d65e79 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 2 Feb 2023 18:13:02 +0800 Subject: [PATCH 17/67] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/code_stats_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/projects/code_stats_controller.rb b/app/controllers/api/v1/projects/code_stats_controller.rb index 333cfe86a..f8f3725cb 100644 --- a/app/controllers/api/v1/projects/code_stats_controller.rb +++ b/app/controllers/api/v1/projects/code_stats_controller.rb @@ -2,7 +2,7 @@ class Api::V1::Projects::CodeStatsController < Api::V1::BaseController before_action :require_public_and_member_above, only: [:index] def index - @result_object = Api::V1::Projects::CodeStats::ListService.call(@project, {page: page, limit, limit, ref: params[:ref]}, current_user&.gitea_token) + @result_object = Api::V1::Projects::CodeStats::ListService.call(@project, {page: page, limit: limit, ref: params[:ref]}, current_user&.gitea_token) puts @result_object end end \ No newline at end of file From bfe14352c0a1ddb8ae9dbf2a1cfa28a8e48f7c08 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 2 Feb 2023 18:30:07 +0800 Subject: [PATCH 18/67] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Acodestats?= =?UTF-8?q?=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/code_stats_controller.rb | 2 +- .../api/v1/projects/code_stats/list_service.rb | 6 +----- .../v1/projects/code_stats/index.json.jbuilder | 15 +++++++-------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/app/controllers/api/v1/projects/code_stats_controller.rb b/app/controllers/api/v1/projects/code_stats_controller.rb index f8f3725cb..7ec671f3c 100644 --- a/app/controllers/api/v1/projects/code_stats_controller.rb +++ b/app/controllers/api/v1/projects/code_stats_controller.rb @@ -2,7 +2,7 @@ class Api::V1::Projects::CodeStatsController < Api::V1::BaseController before_action :require_public_and_member_above, only: [:index] def index - @result_object = Api::V1::Projects::CodeStats::ListService.call(@project, {page: page, limit: limit, ref: params[:ref]}, current_user&.gitea_token) + @result_object = Api::V1::Projects::CodeStats::ListService.call(@project, {ref: params[:ref]}, current_user&.gitea_token) puts @result_object end end \ No newline at end of file diff --git a/app/services/api/v1/projects/code_stats/list_service.rb b/app/services/api/v1/projects/code_stats/list_service.rb index fa9d68bec..a5e330e21 100644 --- a/app/services/api/v1/projects/code_stats/list_service.rb +++ b/app/services/api/v1/projects/code_stats/list_service.rb @@ -9,8 +9,6 @@ class Api::V1::Projects::CodeStats::ListService < ApplicationService @owner = project&.owner.login @repo = project&.identifier @token = token - @page = params[:page] - @limit = params[:limit] end def call @@ -22,9 +20,7 @@ class Api::V1::Projects::CodeStats::ListService < ApplicationService private def request_params param = { - access_token: token, - page: page, - limit: limit + access_token: token } param.merge!(ref: ref) if ref.present? diff --git a/app/views/api/v1/projects/code_stats/index.json.jbuilder b/app/views/api/v1/projects/code_stats/index.json.jbuilder index ecb4767e4..0b64270f7 100644 --- a/app/views/api/v1/projects/code_stats/index.json.jbuilder +++ b/app/views/api/v1/projects/code_stats/index.json.jbuilder @@ -1,11 +1,10 @@ -json.total_count @result_object[:total_data].to_i -json.author_count @result_object[:data]["author_count"] -json.commit_count @result_object[:data]["commit_count"] -json.change_files @result_object[:data]["change_files"] -json.additions @result_object[:data]["additions"] -json.deletions @result_object[:data]["deletions"] -json.commit_count_in_all_branches @result_object[:data]["commit_count_in_all_branches"] -json.authors @result_object[:data]["authors"].each do |author| +json.author_count @result_object["author_count"] +json.commit_count @result_object["commit_count"] +json.change_files @result_object["change_files"] +json.additions @result_object["additions"] +json.deletions @result_object["deletions"] +json.commit_count_in_all_branches @result_object["commit_count_in_all_branches"] +json.authors @result_object["authors"].each do |author| json.author do json.partial! 'api/v1/users/commit_user_email', locals: { user: render_cache_commit_author(author), name: author['name'], email: author['email'] } end From 3f78899c58d8b742e0f3af061bd763f7950608d4 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 3 Feb 2023 10:53:24 +0800 Subject: [PATCH 19/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Abranch?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- .../api/v1/projects/branches_controller.rb | 6 ++- .../api/v1/projects/branches/list_service.rb | 40 +++++++++++++++++++ .../_simple_gitea_detail.json.jbuilder | 2 +- .../v1/projects/branches/index.json.jbuilder | 4 ++ 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 app/services/api/v1/projects/branches/list_service.rb create mode 100644 app/views/api/v1/projects/branches/index.json.jbuilder diff --git a/Gemfile b/Gemfile index e37371108..2a431701b 100644 --- a/Gemfile +++ b/Gemfile @@ -139,4 +139,4 @@ gem 'doorkeeper' gem 'doorkeeper-jwt' -gem 'gitea-client', '~> 0.11.1' \ No newline at end of file +gem 'gitea-client', '~> 0.11.4' \ No newline at end of file diff --git a/app/controllers/api/v1/projects/branches_controller.rb b/app/controllers/api/v1/projects/branches_controller.rb index bc4919616..33346573c 100644 --- a/app/controllers/api/v1/projects/branches_controller.rb +++ b/app/controllers/api/v1/projects/branches_controller.rb @@ -1,5 +1,9 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController - before_action :require_public_and_member_above, only: [:all] + before_action :require_public_and_member_above, only: [:index, :all] + + def index + @result_object = Api::V1::Projects::Branches::ListService.call(@project, {name: params[:name], page: page, limit: limit}, current_user&.gitea_token) + end def all @result_object = Api::V1::Projects::Branches::AllListService.call(@project, current_user&.gitea_token) diff --git a/app/services/api/v1/projects/branches/list_service.rb b/app/services/api/v1/projects/branches/list_service.rb new file mode 100644 index 000000000..e5c6fe442 --- /dev/null +++ b/app/services/api/v1/projects/branches/list_service.rb @@ -0,0 +1,40 @@ +class Api::V1::Projects::Branches::ListService < ApplicationService + + attr_accessor :project, :token, :owner, :repo, :name, :page, :limit + attr_accessor :gitea_data + + def initialize(project, params, token=nil) + @project = project + @owner = project&.owner.login + @repo = project&.identifier + @token = token + @name = params[:name] + @page = params[:page] + @limit = params[:limit] + end + + def call + load_gitea_data + + gitea_data + end + + private + def request_params + params = { + access_token: token, + page: page, + limit: limit + } + params.merge!({name: name}) if name.present? + + params + end + + def load_gitea_data + puts request_params + @gitea_data = $gitea_client.get_repos_branches_by_owner_repo(owner, repo, {query: request_params}) rescue nil + puts @gitea_data + raise Error, '获取分支列表失败!' unless @gitea_data.is_a?(Hash) + end +end \ No newline at end of file diff --git a/app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder b/app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder index 70fac8238..6a35b782e 100644 --- a/app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder +++ b/app/views/api/v1/projects/branches/_simple_gitea_detail.json.jbuilder @@ -18,7 +18,7 @@ json.protected branch['protected'] json.user_can_push branch['user_can_push'] json.user_can_merge branch['user_can_merge'] json.commit_id branch['commit_id'] -json.commit_time_from_now time_from_now(branch['commit_time'].to_time) +json.commit_time_from_now time_from_now(branch['commit']['timestamp'].to_time) json.commit_time branch['commit_time'] json.default_branch branch['default_branch'] json.http_url render_http_url(@project) diff --git a/app/views/api/v1/projects/branches/index.json.jbuilder b/app/views/api/v1/projects/branches/index.json.jbuilder new file mode 100644 index 000000000..cfb9bb647 --- /dev/null +++ b/app/views/api/v1/projects/branches/index.json.jbuilder @@ -0,0 +1,4 @@ +json.total_count @result_object[:total_data].to_i +json.branches @result_object[:data].each do |branch| + json.partial! "api/v1/projects/branches/simple_gitea_detail", branch: branch +end \ No newline at end of file From f2cdba29eaa2727a825f9094f44174f45e79d219 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 3 Feb 2023 13:45:32 +0800 Subject: [PATCH 20/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=E9=BB=98=E8=AE=A4=E5=88=86=E6=94=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/branches_controller.rb | 11 ++++ .../v1/projects/branches/create_service.rb | 7 ++- .../branches/update_default_branch_service.rb | 55 +++++++++++++++++++ config/routes/api.rb | 3 +- 4 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 app/services/api/v1/projects/branches/update_default_branch_service.rb diff --git a/app/controllers/api/v1/projects/branches_controller.rb b/app/controllers/api/v1/projects/branches_controller.rb index 33346573c..f16aa8373 100644 --- a/app/controllers/api/v1/projects/branches_controller.rb +++ b/app/controllers/api/v1/projects/branches_controller.rb @@ -15,6 +15,17 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController @result_object = Api::V1::Projects::Branches::CreateService.call(@project, branch_params, current_user&.gitea_token) end + before_action :require_manager_above, only: [:update_default_branch] + + def update_default_branch + @result_object = Api::V1::Projects::Branches::UpdateDefaultBranchService.call(@project, params[:default_branch], current_user&.gitea_token) + if @result_object + return render_ok + else + return render_error('更新默认分支失败!') + end + end + private def branch_params params.require(:branch).permit(:new_branch_name, :old_branch_name) diff --git a/app/services/api/v1/projects/branches/create_service.rb b/app/services/api/v1/projects/branches/create_service.rb index 2837dfcf4..eae3779f8 100644 --- a/app/services/api/v1/projects/branches/create_service.rb +++ b/app/services/api/v1/projects/branches/create_service.rb @@ -18,7 +18,7 @@ class Api::V1::Projects::Branches::CreateService < ApplicationService def call raise Error, errors.full_messages.join(",") unless valid? - check_new_branch_exist + check_branch_exist excute_data_to_gitea gitea_data @@ -43,9 +43,10 @@ class Api::V1::Projects::Branches::CreateService < ApplicationService raise Error, '创建分支失败!' unless @gitea_data.is_a?(Hash) end - def check_new_branch_exist + def check_branch_exist result = $gitea_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil raise Error, '查询分支名称失败!' unless result.is_a?(Hash) - raise Error, '分支已存在!' if result['branch_name'].include?(@new_branch_name) + raise Error, '旧分支不存在!' if !result['branch_name'].include?(@old_branch_name) + raise Error, '新分支已存在!' if result['branch_name'].include?(@new_branch_name) end end \ No newline at end of file diff --git a/app/services/api/v1/projects/branches/update_default_branch_service.rb b/app/services/api/v1/projects/branches/update_default_branch_service.rb new file mode 100644 index 000000000..5c220aa5d --- /dev/null +++ b/app/services/api/v1/projects/branches/update_default_branch_service.rb @@ -0,0 +1,55 @@ +class Api::V1::Projects::Branches::UpdateDefaultBranchService < ApplicationService + include ActiveModel::Model + + attr_accessor :project, :token, :owner, :repo, :new_default_branch + attr_accessor :gitea_data + + validates :new_default_branch, presence: true + + def initialize(project, new_default_branch, token=nil) + @project = project + @owner = project&.owner.login + @repo = project&.identifier + @new_default_branch = new_default_branch + @token = token + end + + def call + raise Error, errors.full_messages.join(",") unless valid? + + check_branch_exist + update_project + excute_data_to_gitea + + gitea_data + end + + private + def request_params + { + access_token: token + } + end + + def request_body + { + default_branch: new_default_branch + } + end + + def update_project + @project.attributes = request_body + raise Error, '更新默认分支失败!' unless @project.save + end + + def excute_data_to_gitea + @gitea_data = $gitea_client.patch_repos_by_owner_repo(owner, repo, {body: request_body.to_json, query: request_params}) rescue nil + raise Error, '更新默认分支失败!' unless @gitea_data.is_a?(Hash) + end + + def check_branch_exist + result = $gitea_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil + raise Error, '查询分支名称失败!' unless result.is_a?(Hash) + raise Error, '新默认分支不存在!' if !result['branch_name'].include?(@new_default_branch) + end +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 19531526e..92f18e2d7 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -48,7 +48,8 @@ defaults format: :json do end resources :branches, only:[:index, :create] do collection do - get :all + get :all + patch :update_default_branch end end resources :commits, only: [:index] From 8b90164247e9ea7b1c37e6f014ff1d6867370312 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 3 Feb 2023 15:03:59 +0800 Subject: [PATCH 21/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=88=86=E6=94=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/branches_controller.rb | 11 ++++- .../v1/projects/branches/delete_service.rb | 42 +++++++++++++++++++ config/routes/api.rb | 2 +- 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 app/services/api/v1/projects/branches/delete_service.rb diff --git a/app/controllers/api/v1/projects/branches_controller.rb b/app/controllers/api/v1/projects/branches_controller.rb index f16aa8373..5d685a4a9 100644 --- a/app/controllers/api/v1/projects/branches_controller.rb +++ b/app/controllers/api/v1/projects/branches_controller.rb @@ -9,12 +9,21 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController @result_object = Api::V1::Projects::Branches::AllListService.call(@project, current_user&.gitea_token) end - before_action :require_operate_above, only: [:create] + before_action :require_operate_above, only: [:create, :destroy] def create @result_object = Api::V1::Projects::Branches::CreateService.call(@project, branch_params, current_user&.gitea_token) end + def destroy + @result_object = Api::V1::Projects::Branches::DeleteService.call(@project, params[:id], current_user&.gitea_token) + if @result_object + return render_ok + else + return render_error('删除分支失败!') + end + end + before_action :require_manager_above, only: [:update_default_branch] def update_default_branch diff --git a/app/services/api/v1/projects/branches/delete_service.rb b/app/services/api/v1/projects/branches/delete_service.rb new file mode 100644 index 000000000..c6ff5f80e --- /dev/null +++ b/app/services/api/v1/projects/branches/delete_service.rb @@ -0,0 +1,42 @@ +class Api::V1::Projects::Branches::DeleteService < ApplicationService + include ActiveModel::Model + + attr_accessor :project, :token, :owner, :repo, :branch_name + attr_accessor :gitea_data + + validates :branch_name, presence: true + + def initialize(project, branch_name, token=nil) + @project = project + @owner = project&.owner.login + @repo = project&.identifier + @branch_name = branch_name + @token = token + end + + def call + raise Error, errors.full_messages.join(",") unless valid? + + # check_branch_exist + excute_data_to_gitea + + true + end + + private + def request_params + { + access_token: token + } + end + + def excute_data_to_gitea + @gitea_data = $gitea_client.delete_repos_branches_by_owner_repo_branch(owner, repo, branch_name, {query: request_params}) rescue nil + end + + def check_branch_exist + result = $gitea_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil + raise Error, '查询分支名称失败!' unless result.is_a?(Hash) + raise Error, '分支不存在!' if !result['branch_name'].include?(@branch_name) + end +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 92f18e2d7..6fb9f3500 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -46,7 +46,7 @@ defaults format: :json do get :hooktasks end end - resources :branches, only:[:index, :create] do + resources :branches, only:[:index, :create, :destroy] do collection do get :all patch :update_default_branch From 4bc945028b1730cadba62e4183c930002ba87630 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 3 Feb 2023 15:50:33 +0800 Subject: [PATCH 22/67] =?UTF-8?q?fixed=20=E9=A1=B9=E7=9B=AE=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E7=94=A8=E6=88=B7=E5=90=8D=E5=A4=B1=E8=B4=A5=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/queries/projects/list_query.rb | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index ec1dcda3c..e1c03a75c 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -11,7 +11,7 @@ class Projects::ListQuery < ApplicationQuery end def call - collection = Project.all + collection = main_collection collection = filter_projects(collection) sort = params[:sort_by] || "updated_on" @@ -26,15 +26,24 @@ class Projects::ListQuery < ApplicationQuery def filter_projects(collection) collection = by_pinned(collection) - collection = by_search(collection) + collection = by_search(collection) if params[:search].present? collection = by_project_type(collection) collection = by_project_category(collection) collection = by_project_language(collection) collection end + def main_collection + collection = Project.visible + # 增加私有组织中项目过滤 + collection = collection.joins("left join organization_extensions on organization_extensions.organization_id = projects.user_id") + .where("organization_extensions.visibility is null or organization_extensions.visibility in (0,1)") + .where("projects.user_id > 0") + collection + end + def by_search(items) - items.visible.by_name_or_identifier(params[:search]) + items.by_name_or_identifier(params[:search]).or(main_collection.where(user_id: Owner.like(params[:search]).pluck(:id))) end def by_project_type(items) @@ -67,5 +76,14 @@ class Projects::ListQuery < ApplicationQuery relations end end - + + def by_recommend(items) + params[:recommend].to_s == "true" ? items.where(recommend: true) : items + end + + def exclude_fork(items) + return items if params[:exclude_forked].blank? + params[:exclude_forked].to_s == "true" ? items.where("forked_from_project_id is null") : items.where("forked_from_project_id is not null") + end + end From 2772b97e32ebdcd740736ab9f5988a2dd75028f6 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 3 Feb 2023 18:03:57 +0800 Subject: [PATCH 23/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E5=88=97=E8=A1=A8=E5=92=8C=E5=88=A0=E9=99=A4=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- .../api/v1/projects/tags_controller.rb | 18 ++++++++ .../v1/projects/branches/delete_service.rb | 2 +- .../api/v1/projects/tags/delete_service.rb | 42 +++++++++++++++++++ .../api/v1/projects/tags/list_service.rb | 36 ++++++++++++++++ .../_simple_gitea_index_detail.json.jbuilder | 26 ++++++++++++ .../api/v1/projects/tags/index.json.jbuilder | 4 ++ config/routes/api.rb | 1 + 8 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 app/controllers/api/v1/projects/tags_controller.rb create mode 100644 app/services/api/v1/projects/tags/delete_service.rb create mode 100644 app/services/api/v1/projects/tags/list_service.rb create mode 100644 app/views/api/v1/projects/tags/_simple_gitea_index_detail.json.jbuilder create mode 100644 app/views/api/v1/projects/tags/index.json.jbuilder diff --git a/Gemfile b/Gemfile index 2a431701b..45a83fd28 100644 --- a/Gemfile +++ b/Gemfile @@ -139,4 +139,4 @@ gem 'doorkeeper' gem 'doorkeeper-jwt' -gem 'gitea-client', '~> 0.11.4' \ No newline at end of file +gem 'gitea-client', '~> 0.11.5' \ No newline at end of file diff --git a/app/controllers/api/v1/projects/tags_controller.rb b/app/controllers/api/v1/projects/tags_controller.rb new file mode 100644 index 000000000..9764225d4 --- /dev/null +++ b/app/controllers/api/v1/projects/tags_controller.rb @@ -0,0 +1,18 @@ +class Api::V1::Projects::TagsController < Api::V1::BaseController + before_action :require_public_and_member_above, only: [:index] + + def index + @result_object = Api::V1::Projects::Tags::ListService.call(@project, {page: page, limit: limit}, current_user&.gitea_token) + end + + before_action :require_operate_above, only: [:destroy] + + def destroy + @result_object = Api::V1::Projects::Tags::DeleteService.call(@project, params[:id], current_user&.gitea_token) + if @result_object + return render_ok + else + return render_error('删除标签失败!') + end + end +end \ No newline at end of file diff --git a/app/services/api/v1/projects/branches/delete_service.rb b/app/services/api/v1/projects/branches/delete_service.rb index c6ff5f80e..ab9fee157 100644 --- a/app/services/api/v1/projects/branches/delete_service.rb +++ b/app/services/api/v1/projects/branches/delete_service.rb @@ -17,7 +17,7 @@ class Api::V1::Projects::Branches::DeleteService < ApplicationService def call raise Error, errors.full_messages.join(",") unless valid? - # check_branch_exist + check_branch_exist excute_data_to_gitea true diff --git a/app/services/api/v1/projects/tags/delete_service.rb b/app/services/api/v1/projects/tags/delete_service.rb new file mode 100644 index 000000000..ee383a5bd --- /dev/null +++ b/app/services/api/v1/projects/tags/delete_service.rb @@ -0,0 +1,42 @@ +class Api::V1::Projects::Tags::DeleteService < ApplicationService + include ActiveModel::Model + + attr_accessor :project, :token, :owner, :repo, :tag_name + attr_accessor :gitea_data + + validates :tag_name, presence: true + + def initialize(project, tag_name, token=nil) + @project = project + @owner = project&.owner.login + @repo = project&.identifier + @tag_name = tag_name + @token = token + end + + def call + raise Error, errors.full_messages.join(",") unless valid? + + check_tag_exist + excute_data_to_gitea + + true + end + + private + def request_params + { + access_token: token + } + end + + def excute_data_to_gitea + @gitea_data = $gitea_client.delete_repos_tags_by_owner_repo_tag(owner, repo, tag_name, {query: request_params}) rescue nil + end + + def check_tag_exist + result = $gitea_client.get_repos_tag_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil + raise Error, '查询标签名称失败!' unless result.is_a?(Array) + raise Error, '标签不存在!' if !result.include?(@tag_name) + end +end \ No newline at end of file diff --git a/app/services/api/v1/projects/tags/list_service.rb b/app/services/api/v1/projects/tags/list_service.rb new file mode 100644 index 000000000..a7743fe00 --- /dev/null +++ b/app/services/api/v1/projects/tags/list_service.rb @@ -0,0 +1,36 @@ +class Api::V1::Projects::Tags::ListService < ApplicationService + + attr_accessor :project, :token, :owner, :repo, :page, :limit + attr_accessor :gitea_data + + def initialize(project, params, token=nil) + @project = project + @owner = project&.owner.login + @repo = project&.identifier + @token = token + @page = params[:page] + @limit = params[:limit] + end + + def call + load_gitea_data + + gitea_data + end + + private + def request_params + params = { + access_token: token, + page: page, + limit: limit + } + + params + end + + def load_gitea_data + @gitea_data = $gitea_client.get_repos_tags_by_owner_repo(owner, repo, {query: request_params}) rescue nil + raise Error, '获取标签列表失败!' unless @gitea_data.is_a?(Hash) + end +end \ No newline at end of file diff --git a/app/views/api/v1/projects/tags/_simple_gitea_index_detail.json.jbuilder b/app/views/api/v1/projects/tags/_simple_gitea_index_detail.json.jbuilder new file mode 100644 index 000000000..6dada8204 --- /dev/null +++ b/app/views/api/v1/projects/tags/_simple_gitea_index_detail.json.jbuilder @@ -0,0 +1,26 @@ +if tag.present? && tag.is_a?(Hash) + json.name tag['name'] + json.id tag['id'] + json.zipball_url render_zip_url(@owner, @repository, tag['name']) + json.tarball_url render_tar_url(@owner, @repository, tag['name']) + json.tagger do + json.partial! 'commit_author', user: render_cache_commit_author(tag['tagger']), name: tag['tagger']['name'] + end + json.time_ago time_from_now(tag['tagger']['date'].to_time) + json.created_at_unix tag['tagger']['date'].to_time.to_i + json.message tag['message'] + json.commit do + json.sha tag['commit']['sha'] + json.message tag['commit']['message'] + json.time_ago time_from_now(tag['commit']['commiter']['date'].to_time) + json.created_at_unix tag['commit']['commiter']['date'].to_time.to_i + json.committer do + json.partial! 'commit_author', user: render_cache_commit_author(tag['commit']['commiter']), name: tag['commit']['commiter']['name'] + end + json.author do + json.partial! 'commit_author', user: render_cache_commit_author(tag['commit']['author']), name: tag['commit']['author']['name'] + end + end +else + json.name tag +end \ No newline at end of file diff --git a/app/views/api/v1/projects/tags/index.json.jbuilder b/app/views/api/v1/projects/tags/index.json.jbuilder new file mode 100644 index 000000000..3c6f2d4a7 --- /dev/null +++ b/app/views/api/v1/projects/tags/index.json.jbuilder @@ -0,0 +1,4 @@ +json.total_count @result_object[:total_data].to_i +json.tags @result_object[:data].each do |tag| + json.partial! "api/v1/projects/tags/simple_gitea_index_detail", tag: tag +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 6fb9f3500..870861579 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -52,6 +52,7 @@ defaults format: :json do patch :update_default_branch end end + resources :tags, only: [:index, :destroy] resources :commits, only: [:index] resources :code_stats, only: [:index] get '/commits/:sha/diff', to: 'commits#diff' From bef13509336521343fc27c4529bcb135289bc257 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 3 Feb 2023 18:20:00 +0800 Subject: [PATCH 24/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aload=5Fproject?= =?UTF-8?q?=E6=96=B0=E5=A2=9Erepository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/concerns/api/project_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/concerns/api/project_helper.rb b/app/controllers/concerns/api/project_helper.rb index 52967e784..44cac08c7 100644 --- a/app/controllers/concerns/api/project_helper.rb +++ b/app/controllers/concerns/api/project_helper.rb @@ -6,7 +6,8 @@ module Api::ProjectHelper repo = params[:repo] @project, @owner = Project.find_with_namespace(namespace, repo) - + @repository = @project&.repository + if @project logger.info "###########:project founded" @project From 726453ea99a1294bdb89d03e53e02387cdee1d86 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 3 Feb 2023 18:23:16 +0800 Subject: [PATCH 25/67] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Atags=20detail?= =?UTF-8?q?=20=E6=97=A0=E6=B3=95=E8=8E=B7=E5=8F=96commit=5Fuser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1/projects/tags/_simple_gitea_index_detail.json.jbuilder | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/api/v1/projects/tags/_simple_gitea_index_detail.json.jbuilder b/app/views/api/v1/projects/tags/_simple_gitea_index_detail.json.jbuilder index 6dada8204..8ceab48e5 100644 --- a/app/views/api/v1/projects/tags/_simple_gitea_index_detail.json.jbuilder +++ b/app/views/api/v1/projects/tags/_simple_gitea_index_detail.json.jbuilder @@ -15,10 +15,10 @@ if tag.present? && tag.is_a?(Hash) json.time_ago time_from_now(tag['commit']['commiter']['date'].to_time) json.created_at_unix tag['commit']['commiter']['date'].to_time.to_i json.committer do - json.partial! 'commit_author', user: render_cache_commit_author(tag['commit']['commiter']), name: tag['commit']['commiter']['name'] + json.partial! 'api/v1/users/commit_user', user: render_cache_commit_author(tag['commit']['commiter']), name: tag['commit']['commiter']['name'] end json.author do - json.partial! 'commit_author', user: render_cache_commit_author(tag['commit']['author']), name: tag['commit']['author']['name'] + json.partial! 'api/v1/users/commit_user', user: render_cache_commit_author(tag['commit']['author']), name: tag['commit']['author']['name'] end end else From 0800f9e6e012b8ee8f455e843868d9d6d18dda8d Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 3 Feb 2023 18:24:07 +0800 Subject: [PATCH 26/67] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1/projects/tags/_simple_gitea_index_detail.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/api/v1/projects/tags/_simple_gitea_index_detail.json.jbuilder b/app/views/api/v1/projects/tags/_simple_gitea_index_detail.json.jbuilder index 8ceab48e5..b8ba28f85 100644 --- a/app/views/api/v1/projects/tags/_simple_gitea_index_detail.json.jbuilder +++ b/app/views/api/v1/projects/tags/_simple_gitea_index_detail.json.jbuilder @@ -4,7 +4,7 @@ if tag.present? && tag.is_a?(Hash) json.zipball_url render_zip_url(@owner, @repository, tag['name']) json.tarball_url render_tar_url(@owner, @repository, tag['name']) json.tagger do - json.partial! 'commit_author', user: render_cache_commit_author(tag['tagger']), name: tag['tagger']['name'] + json.partial! 'api/v1/users/commit_user', user: render_cache_commit_author(tag['tagger']), name: tag['tagger']['name'] end json.time_ago time_from_now(tag['tagger']['date'].to_time) json.created_at_unix tag['tagger']['date'].to_time.to_i From 7c911f5b8610ad18e12c68016a8369442c43609a Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 6 Feb 2023 09:49:36 +0800 Subject: [PATCH 27/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E5=8C=B9=E9=85=8D=E7=89=B9=E6=AE=8A=E7=AC=A6=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/branches_controller.rb | 4 ++-- app/controllers/api/v1/projects/tags_controller.rb | 2 +- app/services/api/v1/projects/tags/delete_service.rb | 2 +- config/routes/api.rb | 8 ++++++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/v1/projects/branches_controller.rb b/app/controllers/api/v1/projects/branches_controller.rb index 5d685a4a9..861bf9692 100644 --- a/app/controllers/api/v1/projects/branches_controller.rb +++ b/app/controllers/api/v1/projects/branches_controller.rb @@ -16,7 +16,7 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController end def destroy - @result_object = Api::V1::Projects::Branches::DeleteService.call(@project, params[:id], current_user&.gitea_token) + @result_object = Api::V1::Projects::Branches::DeleteService.call(@project, params[:name], current_user&.gitea_token) if @result_object return render_ok else @@ -27,7 +27,7 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController before_action :require_manager_above, only: [:update_default_branch] def update_default_branch - @result_object = Api::V1::Projects::Branches::UpdateDefaultBranchService.call(@project, params[:default_branch], current_user&.gitea_token) + @result_object = Api::V1::Projects::Branches::UpdateDefaultBranchService.call(@project, params[:name], current_user&.gitea_token) if @result_object return render_ok else diff --git a/app/controllers/api/v1/projects/tags_controller.rb b/app/controllers/api/v1/projects/tags_controller.rb index 9764225d4..ded55f888 100644 --- a/app/controllers/api/v1/projects/tags_controller.rb +++ b/app/controllers/api/v1/projects/tags_controller.rb @@ -8,7 +8,7 @@ class Api::V1::Projects::TagsController < Api::V1::BaseController before_action :require_operate_above, only: [:destroy] def destroy - @result_object = Api::V1::Projects::Tags::DeleteService.call(@project, params[:id], current_user&.gitea_token) + @result_object = Api::V1::Projects::Tags::DeleteService.call(@project, params[:name], current_user&.gitea_token) if @result_object return render_ok else diff --git a/app/services/api/v1/projects/tags/delete_service.rb b/app/services/api/v1/projects/tags/delete_service.rb index ee383a5bd..44c162259 100644 --- a/app/services/api/v1/projects/tags/delete_service.rb +++ b/app/services/api/v1/projects/tags/delete_service.rb @@ -17,7 +17,7 @@ class Api::V1::Projects::Tags::DeleteService < ApplicationService def call raise Error, errors.full_messages.join(",") unless valid? - check_tag_exist + # check_tag_exist excute_data_to_gitea true diff --git a/config/routes/api.rb b/config/routes/api.rb index 870861579..f86aae83e 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -46,13 +46,17 @@ defaults format: :json do get :hooktasks end end - resources :branches, only:[:index, :create, :destroy] do + resources :branches, param: :name, only:[:index, :create, :destroy] do collection do get :all patch :update_default_branch end end - resources :tags, only: [:index, :destroy] + match 'branches/*name', to: "branches#destroy", via: :all + + resources :tags, param: :name, only: [:index, :destroy] + match 'tags/*name', to: "tags#destroy", via: :all + resources :commits, only: [:index] resources :code_stats, only: [:index] get '/commits/:sha/diff', to: 'commits#diff' From 0eb17aa90f4d3eaa1fd849582aa130162027c2a5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 6 Feb 2023 10:07:15 +0800 Subject: [PATCH 28/67] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=88=86?= =?UTF-8?q?=E6=94=AF=E5=88=97=E8=A1=A8=E6=90=9C=E7=B4=A2=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/branches_controller.rb | 2 +- app/services/api/v1/projects/tags/delete_service.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/projects/branches_controller.rb b/app/controllers/api/v1/projects/branches_controller.rb index 861bf9692..0c89f6012 100644 --- a/app/controllers/api/v1/projects/branches_controller.rb +++ b/app/controllers/api/v1/projects/branches_controller.rb @@ -2,7 +2,7 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController before_action :require_public_and_member_above, only: [:index, :all] def index - @result_object = Api::V1::Projects::Branches::ListService.call(@project, {name: params[:name], page: page, limit: limit}, current_user&.gitea_token) + @result_object = Api::V1::Projects::Branches::ListService.call(@project, {name: params[:keyword], page: page, limit: limit}, current_user&.gitea_token) end def all diff --git a/app/services/api/v1/projects/tags/delete_service.rb b/app/services/api/v1/projects/tags/delete_service.rb index 44c162259..ee383a5bd 100644 --- a/app/services/api/v1/projects/tags/delete_service.rb +++ b/app/services/api/v1/projects/tags/delete_service.rb @@ -17,7 +17,7 @@ class Api::V1::Projects::Tags::DeleteService < ApplicationService def call raise Error, errors.full_messages.join(",") unless valid? - # check_tag_exist + check_tag_exist excute_data_to_gitea true From 6cfb5dfbe21b892f36d2408cc3b61a8c04894348 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 7 Feb 2023 10:33:46 +0800 Subject: [PATCH 29/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E4=BF=9D=E6=8A=A4=E5=88=86=E6=94=AF=E5=92=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=8F=91=E8=A1=8C=E7=89=88=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/tags_controller.rb | 1 + app/services/api/v1/projects/branches/delete_service.rb | 7 ++++++- app/services/api/v1/projects/tags/delete_service.rb | 7 ++++++- app/views/api/v1/projects/tags/index.json.jbuilder | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/projects/tags_controller.rb b/app/controllers/api/v1/projects/tags_controller.rb index ded55f888..06c3b1c8e 100644 --- a/app/controllers/api/v1/projects/tags_controller.rb +++ b/app/controllers/api/v1/projects/tags_controller.rb @@ -2,6 +2,7 @@ class Api::V1::Projects::TagsController < Api::V1::BaseController before_action :require_public_and_member_above, only: [:index] def index + @release_tags = @repository.version_releases.pluck(:tag_name) @result_object = Api::V1::Projects::Tags::ListService.call(@project, {page: page, limit: limit}, current_user&.gitea_token) end diff --git a/app/services/api/v1/projects/branches/delete_service.rb b/app/services/api/v1/projects/branches/delete_service.rb index ab9fee157..79a6ba0db 100644 --- a/app/services/api/v1/projects/branches/delete_service.rb +++ b/app/services/api/v1/projects/branches/delete_service.rb @@ -31,7 +31,12 @@ class Api::V1::Projects::Branches::DeleteService < ApplicationService end def excute_data_to_gitea - @gitea_data = $gitea_client.delete_repos_branches_by_owner_repo_branch(owner, repo, branch_name, {query: request_params}) rescue nil + begin + @gitea_data = $gitea_client.delete_repos_branches_by_owner_repo_branch(owner, repo, branch_name, {query: request_params}) + rescue => e + raise Error, '保护分支无法删除!' if e.to_s.include?("branch protected") + raise Error, '删除分支失败!' + end end def check_branch_exist diff --git a/app/services/api/v1/projects/tags/delete_service.rb b/app/services/api/v1/projects/tags/delete_service.rb index ee383a5bd..bb05f7b0f 100644 --- a/app/services/api/v1/projects/tags/delete_service.rb +++ b/app/services/api/v1/projects/tags/delete_service.rb @@ -31,7 +31,12 @@ class Api::V1::Projects::Tags::DeleteService < ApplicationService end def excute_data_to_gitea - @gitea_data = $gitea_client.delete_repos_tags_by_owner_repo_tag(owner, repo, tag_name, {query: request_params}) rescue nil + begin + @gitea_data = $gitea_client.delete_repos_tags_by_owner_repo_tag(owner, repo, tag_name, {query: request_params}) rescue nil + rescue => e + raise Error, '请先删除发行版!' if e.to_s.include?("409") + raise Error, '删除标签失败!' + end end def check_tag_exist diff --git a/app/views/api/v1/projects/tags/index.json.jbuilder b/app/views/api/v1/projects/tags/index.json.jbuilder index 3c6f2d4a7..207289041 100644 --- a/app/views/api/v1/projects/tags/index.json.jbuilder +++ b/app/views/api/v1/projects/tags/index.json.jbuilder @@ -1,4 +1,5 @@ json.total_count @result_object[:total_data].to_i json.tags @result_object[:data].each do |tag| json.partial! "api/v1/projects/tags/simple_gitea_index_detail", tag: tag + json.has_release @release_tags.blank? ? false : @release_tags.include?(tag['name']) end \ No newline at end of file From 8c8925f3aed09735e2a2f5d99f161007ebd092db Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 7 Feb 2023 10:39:25 +0800 Subject: [PATCH 30/67] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/api/v1/projects/tags/delete_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/api/v1/projects/tags/delete_service.rb b/app/services/api/v1/projects/tags/delete_service.rb index bb05f7b0f..492898b53 100644 --- a/app/services/api/v1/projects/tags/delete_service.rb +++ b/app/services/api/v1/projects/tags/delete_service.rb @@ -32,7 +32,7 @@ class Api::V1::Projects::Tags::DeleteService < ApplicationService def excute_data_to_gitea begin - @gitea_data = $gitea_client.delete_repos_tags_by_owner_repo_tag(owner, repo, tag_name, {query: request_params}) rescue nil + @gitea_data = $gitea_client.delete_repos_tags_by_owner_repo_tag(owner, repo, tag_name, {query: request_params}) rescue => e raise Error, '请先删除发行版!' if e.to_s.include?("409") raise Error, '删除标签失败!' From 39ae14bce72b8afb6ce488dad396890b34534593 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 7 Feb 2023 14:18:57 +0800 Subject: [PATCH 31/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aentry=E6=96=B0?= =?UTF-8?q?=E5=A2=9Esubmodule=20url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 10 +++++++++- app/views/repositories/_simple_entry.json.jbuilder | 1 + app/views/repositories/entries.json.jbuilder | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index d9ac3746f..d05d54611 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -197,5 +197,13 @@ module RepositoriesHelper def tmp_dir "repo" end - + + def repo_git_submodule_url(owner, repo, path) + unless (path.starts_with?('http://') || path.starts_with?('https://')) + path = File.expand_path(path, "#{base_url}/#{owner&.login}/#{repo&.identifier}") + path = path.split("#{Rails.root}/")[1] + end + + return path + end end diff --git a/app/views/repositories/_simple_entry.json.jbuilder b/app/views/repositories/_simple_entry.json.jbuilder index 30ed9d22d..013b33a9d 100644 --- a/app/views/repositories/_simple_entry.json.jbuilder +++ b/app/views/repositories/_simple_entry.json.jbuilder @@ -7,6 +7,7 @@ if @project.forge? json.sha entry['sha'] json.path entry['path'] json.type entry['type'] + json.submodule_git_url repo_git_submodule_url(@owner, @repository, entry['submodule_git_url']) json.size entry['size'] is_readme = is_readme?(entry['type'], entry['name']) if is_readme diff --git a/app/views/repositories/entries.json.jbuilder b/app/views/repositories/entries.json.jbuilder index 6dea93b32..310918597 100644 --- a/app/views/repositories/entries.json.jbuilder +++ b/app/views/repositories/entries.json.jbuilder @@ -51,6 +51,7 @@ if @project.forge? json.path entry['path'] json.sha entry['sha'] json.type entry['type'] + json.submodule_git_url repo_git_submodule_url(@owner, @repository, entry['submodule_git_url']) json.size entry['size'] json.is_readme_file is_readme?(entry['type'], entry['name']) json.content decode64_content(entry, @owner, @repository, @ref, @path) From 353449c53c023737bca20c1919bdae3fc211803b Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 7 Feb 2023 14:23:24 +0800 Subject: [PATCH 32/67] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/_simple_entry.json.jbuilder | 2 +- app/views/repositories/entries.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/repositories/_simple_entry.json.jbuilder b/app/views/repositories/_simple_entry.json.jbuilder index 013b33a9d..0b2a60b57 100644 --- a/app/views/repositories/_simple_entry.json.jbuilder +++ b/app/views/repositories/_simple_entry.json.jbuilder @@ -7,7 +7,7 @@ if @project.forge? json.sha entry['sha'] json.path entry['path'] json.type entry['type'] - json.submodule_git_url repo_git_submodule_url(@owner, @repository, entry['submodule_git_url']) + json.submodule_git_url entry['submodule_git_url'].nil? ? nil : repo_git_submodule_url(@owner, @repository, entry['submodule_git_url']) json.size entry['size'] is_readme = is_readme?(entry['type'], entry['name']) if is_readme diff --git a/app/views/repositories/entries.json.jbuilder b/app/views/repositories/entries.json.jbuilder index 310918597..c86219785 100644 --- a/app/views/repositories/entries.json.jbuilder +++ b/app/views/repositories/entries.json.jbuilder @@ -51,7 +51,7 @@ if @project.forge? json.path entry['path'] json.sha entry['sha'] json.type entry['type'] - json.submodule_git_url repo_git_submodule_url(@owner, @repository, entry['submodule_git_url']) + json.submodule_git_url entry['submodule_git_url'].nil? ? nil : repo_git_submodule_url(@owner, @repository, entry['submodule_git_url']) json.size entry['size'] json.is_readme_file is_readme?(entry['type'], entry['name']) json.content decode64_content(entry, @owner, @repository, @ref, @path) From 128c5c48e647a83639a4192bb6c8dbabffaa0d5b Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 7 Feb 2023 15:56:35 +0800 Subject: [PATCH 33/67] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index d05d54611..a9a17084e 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -200,8 +200,7 @@ module RepositoriesHelper def repo_git_submodule_url(owner, repo, path) unless (path.starts_with?('http://') || path.starts_with?('https://')) - path = File.expand_path(path, "#{base_url}/#{owner&.login}/#{repo&.identifier}") - path = path.split("#{Rails.root}/")[1] + path = File.expand_path(path, "/#{owner&.login}/#{repo&.identifier}") end return path From f0750333f92bcfadf3a5438bafec6cc276a69a20 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 8 Feb 2023 16:57:42 +0800 Subject: [PATCH 34/67] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 45a83fd28..4f0f76fcd 100644 --- a/Gemfile +++ b/Gemfile @@ -139,4 +139,4 @@ gem 'doorkeeper' gem 'doorkeeper-jwt' -gem 'gitea-client', '~> 0.11.5' \ No newline at end of file +gem 'gitea-client', '~> 0.11.6' \ No newline at end of file From 7bce3201137d4f14af728111190a241add1afcf0 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Feb 2023 16:23:06 +0800 Subject: [PATCH 35/67] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=86=B2?= =?UTF-8?q?=E7=AA=81=E4=BB=A3=E7=A0=81=E5=9B=9E=E5=BD=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/queries/projects/list_query.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index 076ecddfd..82d612375 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -11,11 +11,7 @@ class Projects::ListQuery < ApplicationQuery end def call - collection = Project.visible - # 增加私有组织中项目过滤 - collection = collection.joins("left join organization_extensions on organization_extensions.organization_id = projects.user_id") - .where("organization_extensions.visibility is null or organization_extensions.visibility in (0,1)") - .where("projects.user_id > 0") + collection = main_collection collection = filter_projects(collection) sort = params[:sort_by] || "updated_on" @@ -56,7 +52,8 @@ class Projects::ListQuery < ApplicationQuery else items = items.by_name_or_identifier(params[:search]) end - items.or(items.where(user_id: Owner.like(params[:search]).pluck(:id))) + items.or(main_collection.where(user_id: Owner.like(params[:search]).pluck(:id))) + end def by_project_type(items) From c0271707a1268561e033aa49fac487c672a45246 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 10 Feb 2023 21:46:24 +0800 Subject: [PATCH 36/67] fixed merge --- app/queries/projects/list_query.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index 650be2d9c..82d612375 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -53,6 +53,7 @@ class Projects::ListQuery < ApplicationQuery items = items.by_name_or_identifier(params[:search]) end items.or(main_collection.where(user_id: Owner.like(params[:search]).pluck(:id))) + end def by_project_type(items) From 7d17b654f66ee84d40807ffba67569996e892225 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 13 Feb 2023 10:22:36 +0800 Subject: [PATCH 37/67] =?UTF-8?q?=E6=9B=B4=E6=96=B0gems=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 3 ++- app/queries/projects/list_query.rb | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 4f0f76fcd..0645fa72c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,5 @@ -source 'https://gems.ruby-china.com' +#source 'https://gems.ruby-china.com' +source 'https://mirrors.cloud.tencent.com/rubygems/' git_source(:github) { |repo| "https://github.com/#{repo}.git" } gem 'rails', '~> 5.2.0' diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index 82d612375..8a8fa2f36 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -48,7 +48,8 @@ class Projects::ListQuery < ApplicationQuery @ids = Projects::ElasticsearchService.call(params[:search]) items = items.where(platform: 'forge') if @ids.present? - items = items.where(id: @ids).by_name_or_identifier(params[:search]) + # items = items.where(id: @ids).by_name_or_identifier(params[:search]) + items = items.where(id: @ids) else items = items.by_name_or_identifier(params[:search]) end From 1596b0665407ae8945c76a8da8a5bf6f9f46cc9d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 13 Feb 2023 10:52:57 +0800 Subject: [PATCH 38/67] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E5=90=8C=E6=AD=A5es=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/queries/projects/list_query.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index 8a8fa2f36..6b0843540 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -51,10 +51,9 @@ class Projects::ListQuery < ApplicationQuery # items = items.where(id: @ids).by_name_or_identifier(params[:search]) items = items.where(id: @ids) else - items = items.by_name_or_identifier(params[:search]) + items = items.by_name_or_identifier(params[:search]).or(main_collection.where(user_id: Owner.like(params[:search]).pluck(:id))) end - items.or(main_collection.where(user_id: Owner.like(params[:search]).pluck(:id))) - + items end def by_project_type(items) From f0c1e9e31940d2efed2d201e900c52f9e6dc63a1 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 13 Feb 2023 11:27:44 +0800 Subject: [PATCH 39/67] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E5=90=8C=E6=AD=A5es=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/queries/projects/list_query.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index 8a8fa2f36..6b0843540 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -51,10 +51,9 @@ class Projects::ListQuery < ApplicationQuery # items = items.where(id: @ids).by_name_or_identifier(params[:search]) items = items.where(id: @ids) else - items = items.by_name_or_identifier(params[:search]) + items = items.by_name_or_identifier(params[:search]).or(main_collection.where(user_id: Owner.like(params[:search]).pluck(:id))) end - items.or(main_collection.where(user_id: Owner.like(params[:search]).pluck(:id))) - + items end def by_project_type(items) From 774210206ef52a7f5b0d2e209389ada69904a928 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 15 Feb 2023 11:30:33 +0800 Subject: [PATCH 40/67] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BB=A5.=E5=BC=80=E5=A4=B4=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81=E9=A2=84=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/_simple_entry.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/repositories/_simple_entry.json.jbuilder b/app/views/repositories/_simple_entry.json.jbuilder index 0b2a60b57..bbbd09d54 100644 --- a/app/views/repositories/_simple_entry.json.jbuilder +++ b/app/views/repositories/_simple_entry.json.jbuilder @@ -1,6 +1,6 @@ if @project.forge? file_name = entry['name'] - file_type = File.extname(file_name.to_s)[1..-1] + file_type = file_name.starts_with?('.') ? file_name[1..-1] : File.extname(file_name.to_s)[1..-1] direct_download = file_name.to_s.downcase != "Makefile".downcase && download_type(file_type) image_type = image_type?(file_type) json.name file_name From 1cd43de75bf2785e51ede69282ea0de78b35415b Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 15 Feb 2023 18:37:36 +0800 Subject: [PATCH 41/67] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Bot=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 27 +++++++---- app/controllers/installations_controller.rb | 46 +++++++++++++++++++ app/models/bot.rb | 51 +++++++++++++++++++++ app/models/bot_install.rb | 20 ++++++++ app/models/user.rb | 2 +- app/views/installations/index.json.jbuilder | 7 +++ config/initializers/doorkeeper.rb | 2 +- config/routes.rb | 11 +++++ db/migrate/20230214000021_add_bot_info.rb | 9 ++++ test/jwt_test.rb | 42 +++++++++++++++++ 10 files changed, 206 insertions(+), 11 deletions(-) create mode 100644 app/controllers/installations_controller.rb create mode 100644 app/models/bot.rb create mode 100644 app/models/bot_install.rb create mode 100644 app/views/installations/index.json.jbuilder create mode 100644 db/migrate/20230214000021_add_bot_info.rb create mode 100644 test/jwt_test.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7490cb27f..8129df8f1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,6 @@ require 'oauth2' +# require 'openssl' +# require 'jwt' class ApplicationController < ActionController::Base include CodeExample @@ -295,17 +297,24 @@ class ApplicationController < ActionController::Base # Find the current user #Rails.logger.info("current_laboratory is #{current_laboratory} domain is #{request.subdomain}") if request.headers["Authorization"].present? && request.headers["Authorization"].start_with?('Bearer') - tip_exception(401, "请登录后再操作!") unless valid_doorkeeper_token? - if @doorkeeper_token.present? - # client方法对接,需要一直带着用户标识uid - if @doorkeeper_token.resource_owner_id.blank? - tip_exception(-1, "缺少用户标识!") if params[:uid].nil? - User.current = User.find(params[:uid]) - else - User.current = User.find_by(id: @doorkeeper_token.resource_owner_id) + if !valid_doorkeeper_token? + header = request.authorization + pattern = /^Bearer /i + token = header.gsub(pattern, "") + User.current, message = Bot.decode_jwt_token(token) + tip_exception(401, message) if message.present? + else + if @doorkeeper_token.present? + # client方法对接,需要一直带着用户标识uid + if @doorkeeper_token.resource_owner_id.blank? + tip_exception(-1, "缺少用户标识!") if params[:uid].nil? + User.current = User.find(params[:uid]) + else + User.current = User.find_by(id: @doorkeeper_token.resource_owner_id) + end end end - else + else User.current = find_current_user uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous")) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb new file mode 100644 index 000000000..c8928b51d --- /dev/null +++ b/app/controllers/installations_controller.rb @@ -0,0 +1,46 @@ +class InstallationsController < ApplicationController + include RegisterHelper + before_action :require_login + + def index + @install_bots = BotInstall.where(:installer_id => current_user.id) + end + + def register + @bot = Bot.find params[:id] + @bot.client_id = Doorkeeper::OAuth::Helpers::UniqueToken.generate if params[:client_id].blank? + @bot.client_secret = Doorkeeper::OAuth::Helpers::UniqueToken.generate if params[:client_secret].blank? + @bot.private_key = OpenSSL::PKey::RSA::generate(2048).to_s + @bot.owner_id = current_user.id + ActiveRecord::Base.transaction do + # 注册bot对应oauth应用 + Doorkeeper::Application.create!(name: @bot.name, uid: @bot.client_id, secret: @bot.client_secret, redirect_uri: "https://gitlink.org.cn") + # 注册bot对应用户 + result = autologin_register(User.generate_user_login('b'), nil, "b58333123413", 'bot', nickname: @bot.name) + tip_exception(-1, result[:message]) if result[:message].present? + @bot.uid = result[:user][:id] + @bot.save + render_ok + rescue Exception => e + tip_exception(-1, e.message) + end + end + + def access_tokens + @install_bot = BotInstall.find params[:id] + @bot = @install_bot.bot + @application = Doorkeeper::Application.find_by(uid: @bot.client_id, secret: @bot.client_secret) + if @application.present? + # 给bot生成token,因为bot是机器人操作 + @access_token = Doorkeeper::AccessToken.create!({ :application_id => @application.id, + :resource_owner_id => @bot.uid, + :scopes => "public write", + :expires_in => "604800", + :use_refresh_token => true + }) + end + render_ok(token: @access_token.token) + end + +end + diff --git a/app/models/bot.rb b/app/models/bot.rb new file mode 100644 index 000000000..2098ac1e2 --- /dev/null +++ b/app/models/bot.rb @@ -0,0 +1,51 @@ +# == Schema Information +# +# Table name: bot +# +# id :integer not null, primary key +# bot_name :string(255) +# bot_des :text(4294967295) +# webhook :string(255) +# is_public :integer +# logo :string(255) +# state :integer +# client_id :string(255) +# client_secret :string(255) +# web_url :string(255) +# category :string(255) +# install_num :integer default("0") +# update_time :datetime not null +# create_time :datetime not null +# private_key :text(65535) +# uid :integer +# owner_id :integer +# +# Indexes +# +# name (bot_name) UNIQUE +# + +class Bot < ApplicationRecord + self.table_name = "bot" + + has_many :install_bots + + def name + self.bot_name + end + + def self.decode_jwt_token(token) + decoded_token = JWT.decode token, nil, false + return [nil, "Token已过期"] if Time.now.to_i - 60 - decoded_token[0]["exp"].to_i > 0 + bot = Bot.find_by(id: decoded_token[0]["iss"]) + return [nil, "Token不存在"] if bot.blank? + rsa_private = OpenSSL::PKey::RSA.new(bot.private_key) + rsa_public = rsa_private.public_key + JWT.decode token, rsa_public, true, { algorithm: 'RS256' } + [User.find_by(id: bot.owner_id), ""] + rescue JWT::DecodeError + Rails.logger.error "jwt token decode error:#{token}" + [nil, "无效Token"] + end + +end diff --git a/app/models/bot_install.rb b/app/models/bot_install.rb new file mode 100644 index 000000000..d5283c131 --- /dev/null +++ b/app/models/bot_install.rb @@ -0,0 +1,20 @@ +# == Schema Information +# +# Table name: install_bot +# +# id :integer not null, primary key +# bot_id :integer not null +# installer_id :integer not null +# store_id :integer not null +# state :integer not null +# create_time :datetime not null +# update_time :datetime not null +# + +# frozen_string_literal: true + +class BotInstall < ApplicationRecord + self.table_name = "install_bot" + belongs_to :bot + +end diff --git a/app/models/user.rb b/app/models/user.rb index df35f3a2f..b43e289ed 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -114,7 +114,7 @@ class User < Owner # trustie: 来自Trustie平台 # forge: 平台本身注册的用户 # military: 军科的用户 - enumerize :platform, in: [:forge, :educoder, :trustie, :military, :github, :gitee, :qq, :wechat], default: :forge, scope: :shallow + enumerize :platform, in: [:forge, :educoder, :trustie, :military, :github, :gitee, :qq, :wechat, :bot], default: :forge, scope: :shallow belongs_to :laboratory, optional: true has_one :user_extension, dependent: :destroy diff --git a/app/views/installations/index.json.jbuilder b/app/views/installations/index.json.jbuilder new file mode 100644 index 000000000..b2f674f20 --- /dev/null +++ b/app/views/installations/index.json.jbuilder @@ -0,0 +1,7 @@ +json.status 0 +json.message "success" +json.data do + json.array! @install_bots do |install_bot| + json.extract! install_bot.bot, :id, :name + end +end \ No newline at end of file diff --git a/config/initializers/doorkeeper.rb b/config/initializers/doorkeeper.rb index 2a2355c6d..0cc9a02a4 100644 --- a/config/initializers/doorkeeper.rb +++ b/config/initializers/doorkeeper.rb @@ -18,7 +18,7 @@ Doorkeeper.configure do User.authenticate!(params[:username], params[:password]) end - access_token_generator '::Doorkeeper::JWT' + # access_token_generator '::Doorkeeper::JWT' admin_authenticator do user = current_user diff --git a/config/routes.rb b/config/routes.rb index dc538d93f..58c625841 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1047,6 +1047,17 @@ Rails.application.routes.draw do resources :commit_logs, :only => [:create] + scope '/app' do + post 'register', to: 'installations#register' + resources :installations do + get :repositories, on: :collection + member do + post :access_tokens + put :suspended + end + end + end + root 'main#index' diff --git a/db/migrate/20230214000021_add_bot_info.rb b/db/migrate/20230214000021_add_bot_info.rb new file mode 100644 index 000000000..5e8d11b52 --- /dev/null +++ b/db/migrate/20230214000021_add_bot_info.rb @@ -0,0 +1,9 @@ +class AddBotInfo < ActiveRecord::Migration[5.2] + def change + if table_exists? :bot + add_column :bot, :private_key, :text, comment: "私钥" + add_column :bot, :owner_id, :integer, comment: "所有者ID" + add_column :bot, :uid, :integer, comment: "Bot机器人用户ID" + end + end +end diff --git a/test/jwt_test.rb b/test/jwt_test.rb new file mode 100644 index 000000000..8d0faaa3f --- /dev/null +++ b/test/jwt_test.rb @@ -0,0 +1,42 @@ +require 'openssl' +require 'jwt' # https://rubygems.org/gems/jwt + +# Private key contents +private_pem = File.read("/Users/xxq/Documents/gitlink-webhook.2022-06-09.private-key.pem") + +private_key22="-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEApOebWmRV/ooNq5Ks04YnDU7pEezGShGvaiF0cIvn9jvmYHu0\nFialojvJV3VpB6xE6QBPXZ0Pi1lokZ9dMx8F5UWNx9WA7wf7xK3hAJLNml+GeewF\nou8vk/Ry7n6diLxETNVd7YzPvztn5qaMp/DXa+65i11H8a/XXqR7kCVnCevVlufh\nNr/Dp6dW31W8TInnDQasJFMZ8GY7f+tCwLXNc0M8p+TeDp9xmXHOrEB+S/mgbUOF\nXgRr6icbMmlT9bsAxYHrrDkcVxJhs0hq5vD3BaoK06gcZEnN7/HVNzgVSOYNsVNh\n9006cMgDSOwc9F8aulP7cr8k74INq1xswoGs9wIDAQABAoIBAHayc2NkF3YJXv+h\nqx7yUEfHBgKuAKiuBCqLfCnKuqPFx/So9h5/oPeeuzVlwL0SJePlIjuK4vZ128v9\n/vLeILtADmbJ6m2jvHh8hBmKkc3Ndplp50C5k/CWoufCYZhbk3oOlvZ3Rc4rb4VZ\nWqNDu3voMMv8z91KqeZo1LwUAA/l9mU++zLkRA6qOuWGBJFsM8YpshzxL5lzRUb3\n7y+YJDyUZztfzKwr6pqm1n9B2e6e+znCw1vMZXp2TbUrpvrrXSxlgdNuK68SkZX6\nTdZUD8y0viwaioRVf3vR+e/Bf7yZannGdvcmVGs0A7dq9QgHkakqNHiRkQgwviSq\nbjBo7dECgYEAzekeP5j/dAPkv9X4qnmZ4du/+ZgrQrJckDD/JuNIBmQT9m286l4P\nmb2TBcWkswVOZaS5Qy2bN/69rwIbcdvbaROGBCabn3ATK4fSzmUk31M2rRKYZqaU\nMi0W2g2YtSRg+bV6S7aFXa98j5+JlqJeDZQoRuvL68ooq5WzFWmfYnkCgYEAzQTi\n4USqz2z66BfU+v2rchzK8URxnv7EW/CG3XFRsG+1UXCyEIct2L7rzvC7r7+jjS4s\ngmV3Civ1sckGMwikLzxFtUZ1LUBakZp/mmipIzxcHOeBsRdHei8BFvMNqveg1JpO\ncY/Fp+wEkSNLhfkb/IXRw0iwFalBRnyo4BJbLu8CgYBrQ7E6OB169jxHotNzGv2K\npssO3rJKgFev1ZZVT7jJe4Dasrfi7zT5RcQ9EYSGrZD1aiYIVM2zEcUGUfayDXHy\n/vSlXOdc2ylhV9P9KLtYiyTEbBdwAf7ZVJu+465VTqol6t/WaTJ4Z15gAx/NlK+i\nKzgAGf2Uyy78k3NDCE67IQKBgFwM0pUUEKEbLDhi4uRiWsTcep4C/gTGHIGvJ85r\nH6NZNI7BS6GyH/qOFjAO1CYfpB4yWhed2Om/PQw61sa5HYZ7yEyQuvG7UC7JsHsy\nfKZuZmkv5IIPkq8gRZv5OuzFS/fI5GmGhNdVV+OWdkVLyK4Do1/L1guTt9QfCm+4\nrioPAoGBALGr8aUAbz/A611M/bLnk04UYfV+M34/hCf6/rKiBHdQoIHOriSC9Nv7\nyhE5axTdmIWMxfbyb3vHJ5MizZkD/Qj0VDuMkyS2+3TepI6tySQE3YQeWnCMJI9i\nuoCZ31GBui4+W5udbx8NOVsJfXUQn/OAoOn6WuMNPdgB45KXcktj\n-----END RSA PRIVATE KEY-----\n" +private_key33= "-----BEGIN RSA PRIVATE KEY-----\nMIIEogIBAAKCAQEAq/wUH8N+5fzj3hArKY7ChC591R/uKyeNM/BbsR2OGxO5F1CE\nozy6thtPult96Gm9oK3sMpLdYCze2YgozgteFO1Ft0o1GEJ1A4SinOKzeixLpFy0\n5N9t+iz7Xa7jC/1E3uy/s2WvSYCS9NnK2Uj3DQOH8BUWfkvyTtt91a2pplbPCV3T\nw1PykAcDWIFXVJJCMtYd2x+DukSWKHRsYbBCMtVZhEVuKmTE3FBTDVu9sN3b7uLL\n5RzHUg13QZZr9OvMNR3nUZl6yDxw+wD4anDrtpL9C+tFjhMyqsyYpYWwcJm65YiD\ny7Ps24IdcLB4iOxJE91fu+MnicvyBrtEjoBP/wIDAQABAoIBAAcKc9x1CW3q8300\n1j+GS6pTqO0fuIVlwh8dOPPATQAIx6wPrM5t/wrThWkQs8/e/Fdmp2POpWd5jsoD\nDACbcIeUyyTc0d2jYtz5AhtAIK7gv1wEO5efGgaC7ut/7GWiQb6KnLKAeDOfIuUJ\nQYexuAN9YIRQqLIU89+MltM3n9liZTMuPWRFJcitaDytXa10TCe5RUqHGZf49pi7\njCgk0x7jDYqbIzsqOu741P8My/gkAjKPkRnjaj3o6MrwHzIlc4t/6mKbaPnywywk\n6roYMqmytgueA9wxFcj74ekBQAaXsu4xRkbZXxjcBtIvTId5IHHK5Z/r3fgE9K3J\nOuzzJ1kCgYEA3uu/pUjJbKegOsgSdu3cO/NvRV2YsRD4NUgtiMCEakE4VQXRK5pf\nV8xqQeH/rLjZf5aP5xe8n25krh/c+m0ezOMyu5MmhoxaWCPWIezsaKJXOcvsOxIu\n2sJ9GRMXabyuDuSdL7ZGYMpLhRclXYLyPCz7wzN445IluTHuD3lJ2qUCgYEAxYFh\ncVD73yNZn9BN1DSGWpfPtLqOKIdG+xi/ypCSGpJG0QCJRFi7R1qJOxFtJNI8DRiD\nZapPEGLVd/KY5NzBGZBfNQt4DQH9qR4l43c6NNkisWA9rvXvCDqXKmBq7wfpnkYr\n4Ul2hXYmsPJjP8e0BfG54PaSu3BDBMJMtcgDktMCgYBvzyDdnwdgVyc3tHgGbMFk\n1HHAAfT/ArrrxpsIFz+TJ8lAY92JGDGwENhO2TLrCAAXTYY5657w/GbFKzgj5y1m\nqKIekOzm2WjLApZ5h6L/zEUhuRVwf2s+0AP82qWIpFlNIP9yGeNs0qpUQ8q6/13O\nLuXL/3on8nq3S8LSwgv3/QKBgDfM+g7d5ouAnU29uH9/54Wo5pIVMxzYO4Gt2GIO\nvnirYz6hfCbHOwJJ3gPGRKPmkfjROC59E6F5iv48mF3w0M28MGn4N47VRSmGzwWZ\nJeTQhDDBFCxeZ45Xn2Xln9Cw15xUDwmzi7zhSMUtdkUK0x3q0a1xfLtgWE775lhl\njjzpAoGAdUXFW1elfjXpfIYZf7vUV7MPquKL7qAcopd96XBszhOn7g+ibzem+wgt\n1UTSeOBESYANHeJk2MuWPSRXk/FlQETVIcPAEp0kxbwQE+7YEdrMVeDcIe5lPwGD\n+WuS3kg0MPgUrXZXn74gcwWmSIOyHfqXULqOxWE25uU2icdV+2w=\n-----END RSA PRIVATE KEY-----\n" +private_key = OpenSSL::PKey::RSA.new(private_key33) +# puts private_key.to_json + +# Generate the JWT +payload = { + # issued at time, 60 seconds in the past to allow for clock drift + iat: Time.now.to_i - 60, + # JWT expiration time (10 minute maximum) + exp: Time.now.to_i + (10 * 60), + # GitHub App's identifier + iss: "782" +} + +jwt = JWT.encode(payload, private_key, "RS256") +puts jwt +# puts OpenSSL::PKey::RSA.new(private_key33).public_key.to_s +# +rsa_private = OpenSSL::PKey::RSA.new(private_key33) +rsa_public = rsa_private.public_key + +# decoded_token = JWT.decode jwt, nil, false +begin + decoded_token = JWT.decode jwt, rsa_private, true, { algorithm: 'RS256' } +rescue JWT::DecodeError + puts "jwt is not mmmmmm" +end + +# +puts decoded_token[0] +puts decoded_token[0]["iss"] + +# serialized_private_key = OpenSSL::PKey::RSA::generate(2048).to_s + + From 6fe16c7c82476059688c445b940e8bfdd1adc9e2 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 09:19:37 +0800 Subject: [PATCH 42/67] =?UTF-8?q?=E8=B0=83=E6=95=B4Bot=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 2 +- config/routes.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index c8928b51d..0ebc9a3eb 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -6,7 +6,7 @@ class InstallationsController < ApplicationController @install_bots = BotInstall.where(:installer_id => current_user.id) end - def register + def auth_active @bot = Bot.find params[:id] @bot.client_id = Doorkeeper::OAuth::Helpers::UniqueToken.generate if params[:client_id].blank? @bot.client_secret = Doorkeeper::OAuth::Helpers::UniqueToken.generate if params[:client_secret].blank? diff --git a/config/routes.rb b/config/routes.rb index 58c625841..d6e73aebb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1048,7 +1048,7 @@ Rails.application.routes.draw do resources :commit_logs, :only => [:create] scope '/app' do - post 'register', to: 'installations#register' + post 'auth_active', to: 'installations#auth_active' resources :installations do get :repositories, on: :collection member do From c0fcf3445a1e972f98fdcc18ac81851c5797444c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 09:40:08 +0800 Subject: [PATCH 43/67] =?UTF-8?q?=E8=B0=83=E6=95=B4Bot=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 0ebc9a3eb..5d6a26836 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -21,6 +21,7 @@ class InstallationsController < ApplicationController @bot.uid = result[:user][:id] @bot.save render_ok + end rescue Exception => e tip_exception(-1, e.message) end From 1d9df770b516d9804476c441b94d473bc17ac413 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 09:41:39 +0800 Subject: [PATCH 44/67] =?UTF-8?q?=E8=B0=83=E6=95=B4Bot=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 31 +++++++++++---------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 5d6a26836..40efa3c90 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -7,21 +7,22 @@ class InstallationsController < ApplicationController end def auth_active - @bot = Bot.find params[:id] - @bot.client_id = Doorkeeper::OAuth::Helpers::UniqueToken.generate if params[:client_id].blank? - @bot.client_secret = Doorkeeper::OAuth::Helpers::UniqueToken.generate if params[:client_secret].blank? - @bot.private_key = OpenSSL::PKey::RSA::generate(2048).to_s - @bot.owner_id = current_user.id - ActiveRecord::Base.transaction do - # 注册bot对应oauth应用 - Doorkeeper::Application.create!(name: @bot.name, uid: @bot.client_id, secret: @bot.client_secret, redirect_uri: "https://gitlink.org.cn") - # 注册bot对应用户 - result = autologin_register(User.generate_user_login('b'), nil, "b58333123413", 'bot', nickname: @bot.name) - tip_exception(-1, result[:message]) if result[:message].present? - @bot.uid = result[:user][:id] - @bot.save - render_ok - end + begin + @bot = Bot.find params[:id] + @bot.client_id = Doorkeeper::OAuth::Helpers::UniqueToken.generate if params[:client_id].blank? + @bot.client_secret = Doorkeeper::OAuth::Helpers::UniqueToken.generate if params[:client_secret].blank? + @bot.private_key = OpenSSL::PKey::RSA::generate(2048).to_s + @bot.owner_id = current_user.id + ActiveRecord::Base.transaction do + # 注册bot对应oauth应用 + Doorkeeper::Application.create!(name: @bot.name, uid: @bot.client_id, secret: @bot.client_secret, redirect_uri: "https://gitlink.org.cn") + # 注册bot对应用户 + result = autologin_register(User.generate_user_login('b'), nil, "b58333123413", 'bot', nickname: @bot.name) + tip_exception(-1, result[:message]) if result[:message].present? + @bot.uid = result[:user][:id] + @bot.save + render_ok + end rescue Exception => e tip_exception(-1, e.message) end From 3c51d69555d6a32a1484f4007e5c27043c708e62 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 09:57:25 +0800 Subject: [PATCH 45/67] =?UTF-8?q?=E8=B0=83=E6=95=B4Bot=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 29 +++++++++++++++++---- config/routes.rb | 4 ++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 40efa3c90..6e66431be 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -6,6 +6,25 @@ class InstallationsController < ApplicationController @install_bots = BotInstall.where(:installer_id => current_user.id) end + def update_secret + ActiveRecord::Base.transaction do + bot = Bot.find params[:id] + application = Doorkeeper::Application.find_by(uid: bot.client_id, secret: bot.client_secret) + bot.client_secret = Doorkeeper::OAuth::Helpers::UniqueToken.generate + bot.save! + application.secret = bot.client_secret + application.save! + render_ok + end + end + + def update_private_key + bot = Bot.find params[:id] + bot.private_key = OpenSSL::PKey::RSA::generate(2048).to_s + bot.save! + render_ok + end + def auth_active begin @bot = Bot.find params[:id] @@ -35,11 +54,11 @@ class InstallationsController < ApplicationController if @application.present? # 给bot生成token,因为bot是机器人操作 @access_token = Doorkeeper::AccessToken.create!({ :application_id => @application.id, - :resource_owner_id => @bot.uid, - :scopes => "public write", - :expires_in => "604800", - :use_refresh_token => true - }) + :resource_owner_id => @bot.uid, + :scopes => "public write", + :expires_in => "604800", + :use_refresh_token => true + }) end render_ok(token: @access_token.token) end diff --git a/config/routes.rb b/config/routes.rb index d6e73aebb..3d6cc8f55 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1048,7 +1048,9 @@ Rails.application.routes.draw do resources :commit_logs, :only => [:create] scope '/app' do - post 'auth_active', to: 'installations#auth_active' + post ':id/auth_active', to: 'installations#auth_active' + post ':id/update_private_key', to: 'installations#update_private_key' + post ':id/update_secret', to: 'installations#update_secret' resources :installations do get :repositories, on: :collection member do From 3d0fa0d50cfa67f11f40e5d59edf5a8824d09cca Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 11:01:21 +0800 Subject: [PATCH 46/67] =?UTF-8?q?=E8=B0=83=E6=95=B4Bot=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 6e66431be..88c43cf69 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -51,15 +51,14 @@ class InstallationsController < ApplicationController @install_bot = BotInstall.find params[:id] @bot = @install_bot.bot @application = Doorkeeper::Application.find_by(uid: @bot.client_id, secret: @bot.client_secret) - if @application.present? - # 给bot生成token,因为bot是机器人操作 - @access_token = Doorkeeper::AccessToken.create!({ :application_id => @application.id, - :resource_owner_id => @bot.uid, - :scopes => "public write", - :expires_in => "604800", - :use_refresh_token => true - }) - end + tip_exception("该Bot未激活") if @application.blank? + # 给bot生成token,因为bot是机器人操作 + @access_token = Doorkeeper::AccessToken.create!({ :application_id => @application.id, + :resource_owner_id => @bot.uid, + :scopes => "public write", + :expires_in => "604800", + :use_refresh_token => true + }) render_ok(token: @access_token.token) end From 676d2ddce138ea3989c66143b8347cefe352677b Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 13:52:38 +0800 Subject: [PATCH 47/67] =?UTF-8?q?=E8=B0=83=E6=95=B4Bot=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index 88c43cf69..dd7253f2b 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -28,6 +28,7 @@ class InstallationsController < ApplicationController def auth_active begin @bot = Bot.find params[:id] + tip_exception("该Bot已激活") if Doorkeeper::Application.find_by(uid: @bot.client_id, secret: @bot.client_secret).present? @bot.client_id = Doorkeeper::OAuth::Helpers::UniqueToken.generate if params[:client_id].blank? @bot.client_secret = Doorkeeper::OAuth::Helpers::UniqueToken.generate if params[:client_secret].blank? @bot.private_key = OpenSSL::PKey::RSA::generate(2048).to_s From 5c3c47d13b3d42e989cb2e51a86379ae0d2b534d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 14:37:16 +0800 Subject: [PATCH 48/67] =?UTF-8?q?=E8=B0=83=E6=95=B4Bot=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/installations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/installations_controller.rb b/app/controllers/installations_controller.rb index dd7253f2b..20dd25e40 100644 --- a/app/controllers/installations_controller.rb +++ b/app/controllers/installations_controller.rb @@ -37,7 +37,7 @@ class InstallationsController < ApplicationController # 注册bot对应oauth应用 Doorkeeper::Application.create!(name: @bot.name, uid: @bot.client_id, secret: @bot.client_secret, redirect_uri: "https://gitlink.org.cn") # 注册bot对应用户 - result = autologin_register(User.generate_user_login('b'), nil, "b58333123413", 'bot', nickname: @bot.name) + result = autologin_register(User.generate_user_login('b'), nil, "#{SecureRandom.hex(6)}", 'bot', nickname: @bot.name) tip_exception(-1, result[:message]) if result[:message].present? @bot.uid = result[:user][:id] @bot.save From 7d3d95c406477b5b107db447ea6480bc13cc7dc5 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:37:01 +0800 Subject: [PATCH 49/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimo?= =?UTF-8?q?irelab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/issues_controller.rb | 2 + app/jobs/issue_webhook_job.rb | 181 +++++++++++++++++++++++++++ 2 files changed, 183 insertions(+) create mode 100644 app/jobs/issue_webhook_job.rb diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index ddb0facdf..efc7d3ea4 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -154,6 +154,8 @@ class IssuesController < ApplicationController Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}" AtmeService.call(current_user, @atme_receivers, @issue) if @atme_receivers.size > 0 + # 新增时向grimoirelab推送事件 + IssueWebhookJob.set(wait: 5.seconds).perform_later(@issue.id) render json: {status: 0, message: "创建成功", id: @issue.id} else diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_webhook_job.rb new file mode 100644 index 000000000..b85c7c1e0 --- /dev/null +++ b/app/jobs/issue_webhook_job.rb @@ -0,0 +1,181 @@ +class IssueWebhookJob < ApplicationJob + include ApplicationHelper + queue_as :message + + def perform(issue_id, user_id) + issue = Issue.find_by(id: issue_id) + return if issue.blank? + project = issue.project + user = issue.user + domain = "#{Rails.application.config_for(:configuration)['platform_url']}" + gitea_domain = GiteaService.gitea_config[:domain] + ssh_url = "git@#{gitea_domain.gsub("https://","")}:#{project.owner.login}/#{project.identifier}.git" + event_json = { + "action": "opened", + "number": 1, + "issue": { + "id": 888, + "url": "#{domain}/api/v1/#{project.owner.login}/#{project.identifier}/issues/#{issue.id}", + "html_url": "#{domain}/#{project.owner.login}/#{project.identifier}/issues/#{issue.id}", + "number": 1, + "user": { + "id": user.id, + "login": "#{user.login}", + "full_name": "", + "email": "#{user.mail}", + "avatar_url": "#{domain}/#{url_to_avatar(user)}", + "language": "", + "is_admin": false, + "last_login": "#{user.last_login_on}", + "created": "#{user.created_on}", + "restricted": false, + "active": false, + "prohibit_login": false, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "#{user.login}" + }, + "original_author": "", + "original_author_id": 0, + "title": "#{issue.subject}", + "body": "#{issue.description}", + "ref": "", + "labels": [], + "milestone": null, + "assignee": null, + "assignees": null, + "state": "open", + "is_locked": false, + "comments": 0, + "created_at": "#{issue.created_on}", + "updated_at": "#{issue.updated_on}", + "closed_at": null, + "due_date": null, + "pull_request": null, + "repository": { + "id": 11307, + "name": "#{project.identifier}", + "owner": "#{project.owner.login}", + "full_name": "#{project.owner.login}/#{project.identifier}" + } + }, + "repository": { + "id": project.id, + "owner": { + "id": project.owner.id, + "login": "#{project.owner.login}", + "full_name": "", + "email": "#{project.owner.mail}", + "avatar_url": "#{domain}/#{url_to_avatar(project.owner)}", + "language": "", + "is_admin": false, + "last_login": "#{project.owner.last_login_on}", + "created": "#{project.owner.created_on}", + "restricted": false, + "active": false, + "prohibit_login": false, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "#{project.owner.login}" + }, + "name": "#{project.identifier}", + "full_name": "#{project.owner.login}/#{project.identifier}", + "description": "", + "empty": false, + "private": false, + "fork": false, + "template": false, + "parent": null, + "mirror": false, + "size": 843, + "html_url": "#{domain}/#{project.owner.login}/#{project.identifier}", + "ssh_url": "#{ssh_url}", + "clone_url": "#{domain}/#{project.owner.login}/#{project.identifier}.git", + "original_url": "#{project.repository.mirror_url}", + "website": "", + "stars_count": 0, + "forks_count": 0, + "watchers_count": 1, + "open_issues_count": 1, + "open_pr_counter": 0, + "release_counter": 0, + "default_branch": "master", + "archived": false, + "created_at": "#{project.created_on}", + "updated_at": "#{project.updated_on}", + "permissions": { + "admin": true, + "push": true, + "pull": true + }, + "has_issues": true, + "internal_tracker": { + "enable_time_tracker": true, + "allow_only_contributors_to_track_time": true, + "enable_issue_dependencies": true + }, + "has_wiki": true, + "has_pull_requests": true, + "has_projects": false, + "ignore_whitespace_conflicts": false, + "allow_merge_commits": true, + "allow_rebase": true, + "allow_rebase_explicit": true, + "allow_squash_merge": true, + "default_merge_style": "merge", + "avatar_url": "", + "internal": false, + "mirror_interval": "" + }, + "sender": { + "id": user.id, + "login": "#{user.login}", + "full_name": "", + "email": "#{user.mail}", + "avatar_url": "#{domain}/#{url_to_avatar(user)}", + "language": "", + "is_admin": false, + "last_login": "#{user.last_login_on}", + "created": "#{user.created_on}", + "restricted": false, + "active": false, + "prohibit_login": false, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "#{user.login}" + } + } + + url = URI("http://117.50.185.50:80") + http = Net::HTTP.new(url.host, url.port) + request = Net::HTTP::Post.new(url) + request["Content-Type"] = "application/json" + uuid = SecureRandom.uuid + request['X-GitHub-Delivery'] = uuid + request['X-Gitea-Delivery'] = uuid + request['X-Gogs-Delivery'] = uuid + request['X-GitHub-Event'] = 'issues' + request['X-Gitea-Event'] = 'issues' + request['X-Gogs-Event'] = 'issues' + request.body = JSON.dump(event_json) + + response = http.request(request) + Rails.logger.info "issue webhook event======#{response.read_body}" + end + +end \ No newline at end of file From 368be1849cc003dcf04991e34fc386db6978c47c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:41:20 +0800 Subject: [PATCH 50/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimo?= =?UTF-8?q?irelab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/issues_controller.rb | 2 +- app/jobs/{issue_webhook_job.rb => issue_web_hook_job.rb} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename app/jobs/{issue_webhook_job.rb => issue_web_hook_job.rb} (99%) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index efc7d3ea4..76aef3dc6 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -155,7 +155,7 @@ class IssuesController < ApplicationController Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}" AtmeService.call(current_user, @atme_receivers, @issue) if @atme_receivers.size > 0 # 新增时向grimoirelab推送事件 - IssueWebhookJob.set(wait: 5.seconds).perform_later(@issue.id) + IssueWebHookJob.set(wait: 5.seconds).perform_later(@issue.id) render json: {status: 0, message: "创建成功", id: @issue.id} else diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_web_hook_job.rb similarity index 99% rename from app/jobs/issue_webhook_job.rb rename to app/jobs/issue_web_hook_job.rb index b85c7c1e0..97501675f 100644 --- a/app/jobs/issue_webhook_job.rb +++ b/app/jobs/issue_web_hook_job.rb @@ -1,4 +1,4 @@ -class IssueWebhookJob < ApplicationJob +class IssueWebHookJob < ApplicationJob include ApplicationHelper queue_as :message From c872f5068547f21052a068211c1c057fca7d0327 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:42:15 +0800 Subject: [PATCH 51/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimo?= =?UTF-8?q?irelab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/issues_controller.rb | 2 +- app/jobs/{issue_web_hook_job.rb => issue_webhook_job.rb} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename app/jobs/{issue_web_hook_job.rb => issue_webhook_job.rb} (99%) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 76aef3dc6..efc7d3ea4 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -155,7 +155,7 @@ class IssuesController < ApplicationController Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}" AtmeService.call(current_user, @atme_receivers, @issue) if @atme_receivers.size > 0 # 新增时向grimoirelab推送事件 - IssueWebHookJob.set(wait: 5.seconds).perform_later(@issue.id) + IssueWebhookJob.set(wait: 5.seconds).perform_later(@issue.id) render json: {status: 0, message: "创建成功", id: @issue.id} else diff --git a/app/jobs/issue_web_hook_job.rb b/app/jobs/issue_webhook_job.rb similarity index 99% rename from app/jobs/issue_web_hook_job.rb rename to app/jobs/issue_webhook_job.rb index 97501675f..b85c7c1e0 100644 --- a/app/jobs/issue_web_hook_job.rb +++ b/app/jobs/issue_webhook_job.rb @@ -1,4 +1,4 @@ -class IssueWebHookJob < ApplicationJob +class IssueWebhookJob < ApplicationJob include ApplicationHelper queue_as :message From d578c5c8df8fd4fc7d3ee66824bf06647dcb3ea9 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:44:42 +0800 Subject: [PATCH 52/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimo?= =?UTF-8?q?irelab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/issue_webhook_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_webhook_job.rb index b85c7c1e0..375688663 100644 --- a/app/jobs/issue_webhook_job.rb +++ b/app/jobs/issue_webhook_job.rb @@ -2,7 +2,7 @@ class IssueWebhookJob < ApplicationJob include ApplicationHelper queue_as :message - def perform(issue_id, user_id) + def perform(issue_id) issue = Issue.find_by(id: issue_id) return if issue.blank? project = issue.project From f93e66523947ce253b3861a2814f698b1d037e72 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:46:15 +0800 Subject: [PATCH 53/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimo?= =?UTF-8?q?irelab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/issue_webhook_job.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_webhook_job.rb index 375688663..23a4f978a 100644 --- a/app/jobs/issue_webhook_job.rb +++ b/app/jobs/issue_webhook_job.rb @@ -46,17 +46,17 @@ class IssueWebhookJob < ApplicationJob "body": "#{issue.description}", "ref": "", "labels": [], - "milestone": null, - "assignee": null, - "assignees": null, + "milestone": nil, + "assignee": nil, + "assignees": nil, "state": "open", "is_locked": false, "comments": 0, "created_at": "#{issue.created_on}", "updated_at": "#{issue.updated_on}", - "closed_at": null, - "due_date": null, - "pull_request": null, + "closed_at": nil, + "due_date": nil, + "pull_request": nil, "repository": { "id": 11307, "name": "#{project.identifier}", @@ -95,7 +95,7 @@ class IssueWebhookJob < ApplicationJob "private": false, "fork": false, "template": false, - "parent": null, + "parent": nil, "mirror": false, "size": 843, "html_url": "#{domain}/#{project.owner.login}/#{project.identifier}", From 00bb1e82af0ee8b2701f062a6bb6dfa6715e1030 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:51:06 +0800 Subject: [PATCH 54/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimo?= =?UTF-8?q?irelab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6,=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/issue_webhook_job.rb | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_webhook_job.rb index 23a4f978a..34dcdffaa 100644 --- a/app/jobs/issue_webhook_job.rb +++ b/app/jobs/issue_webhook_job.rb @@ -9,7 +9,7 @@ class IssueWebhookJob < ApplicationJob user = issue.user domain = "#{Rails.application.config_for(:configuration)['platform_url']}" gitea_domain = GiteaService.gitea_config[:domain] - ssh_url = "git@#{gitea_domain.gsub("https://","")}:#{project.owner.login}/#{project.identifier}.git" + ssh_url = "git@#{gitea_domain.gsub("https://", "")}:#{project.owner.login}/#{project.identifier}.git" event_json = { "action": "opened", "number": 1, @@ -161,21 +161,26 @@ class IssueWebhookJob < ApplicationJob } } - url = URI("http://117.50.185.50:80") - http = Net::HTTP.new(url.host, url.port) - request = Net::HTTP::Post.new(url) - request["Content-Type"] = "application/json" - uuid = SecureRandom.uuid - request['X-GitHub-Delivery'] = uuid - request['X-Gitea-Delivery'] = uuid - request['X-Gogs-Delivery'] = uuid - request['X-GitHub-Event'] = 'issues' - request['X-Gitea-Event'] = 'issues' - request['X-Gogs-Event'] = 'issues' - request.body = JSON.dump(event_json) + begin + url = URI("http://117.50.185.50:80") + http = Net::HTTP.new(url.host, url.port) + request = Net::HTTP::Post.new(url) + request["Content-Type"] = "application/json" + uuid = SecureRandom.uuid + request['X-GitHub-Delivery'] = uuid + request['X-Gitea-Delivery'] = uuid + request['X-Gogs-Delivery'] = uuid + request['X-GitHub-Event'] = 'issues' + request['X-Gitea-Event'] = 'issues' + request['X-Gogs-Event'] = 'issues' + request.body = JSON.dump(event_json) - response = http.request(request) - Rails.logger.info "issue webhook event======#{response.read_body}" + response = http.request(request) + Rails.logger.info "issue webhook event======#{response.read_body}" + rescue Exception => e + Rails.logger.info "issue webhook event error======#{e.message}" + puts "issue webhook event error======#{e.message}" + end end end \ No newline at end of file From 0725ef74de94b0041aafcbd567ab8b53ecaa8cd9 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:54:43 +0800 Subject: [PATCH 55/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimo?= =?UTF-8?q?irelab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6,=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/issue_webhook_job.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_webhook_job.rb index 34dcdffaa..445a0b02c 100644 --- a/app/jobs/issue_webhook_job.rb +++ b/app/jobs/issue_webhook_job.rb @@ -176,10 +176,10 @@ class IssueWebhookJob < ApplicationJob request.body = JSON.dump(event_json) response = http.request(request) - Rails.logger.info "issue webhook event======#{response.read_body}" + Rails.logger.info "issue #{issue_id} webhook event======#{response.read_body}" rescue Exception => e - Rails.logger.info "issue webhook event error======#{e.message}" - puts "issue webhook event error======#{e.message}" + Rails.logger.info "issue #{issue_id} webhook event error======#{e.message}" + puts "issue: #{issue_id} webhook event error======#{e.message}" end end From 501c1296101d57404fcc179089e773d757e65b2c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:37:01 +0800 Subject: [PATCH 56/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimo?= =?UTF-8?q?irelab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/issues_controller.rb | 2 + app/jobs/issue_webhook_job.rb | 181 +++++++++++++++++++++++++++ 2 files changed, 183 insertions(+) create mode 100644 app/jobs/issue_webhook_job.rb diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index ddb0facdf..efc7d3ea4 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -154,6 +154,8 @@ class IssuesController < ApplicationController Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}" AtmeService.call(current_user, @atme_receivers, @issue) if @atme_receivers.size > 0 + # 新增时向grimoirelab推送事件 + IssueWebhookJob.set(wait: 5.seconds).perform_later(@issue.id) render json: {status: 0, message: "创建成功", id: @issue.id} else diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_webhook_job.rb new file mode 100644 index 000000000..b85c7c1e0 --- /dev/null +++ b/app/jobs/issue_webhook_job.rb @@ -0,0 +1,181 @@ +class IssueWebhookJob < ApplicationJob + include ApplicationHelper + queue_as :message + + def perform(issue_id, user_id) + issue = Issue.find_by(id: issue_id) + return if issue.blank? + project = issue.project + user = issue.user + domain = "#{Rails.application.config_for(:configuration)['platform_url']}" + gitea_domain = GiteaService.gitea_config[:domain] + ssh_url = "git@#{gitea_domain.gsub("https://","")}:#{project.owner.login}/#{project.identifier}.git" + event_json = { + "action": "opened", + "number": 1, + "issue": { + "id": 888, + "url": "#{domain}/api/v1/#{project.owner.login}/#{project.identifier}/issues/#{issue.id}", + "html_url": "#{domain}/#{project.owner.login}/#{project.identifier}/issues/#{issue.id}", + "number": 1, + "user": { + "id": user.id, + "login": "#{user.login}", + "full_name": "", + "email": "#{user.mail}", + "avatar_url": "#{domain}/#{url_to_avatar(user)}", + "language": "", + "is_admin": false, + "last_login": "#{user.last_login_on}", + "created": "#{user.created_on}", + "restricted": false, + "active": false, + "prohibit_login": false, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "#{user.login}" + }, + "original_author": "", + "original_author_id": 0, + "title": "#{issue.subject}", + "body": "#{issue.description}", + "ref": "", + "labels": [], + "milestone": null, + "assignee": null, + "assignees": null, + "state": "open", + "is_locked": false, + "comments": 0, + "created_at": "#{issue.created_on}", + "updated_at": "#{issue.updated_on}", + "closed_at": null, + "due_date": null, + "pull_request": null, + "repository": { + "id": 11307, + "name": "#{project.identifier}", + "owner": "#{project.owner.login}", + "full_name": "#{project.owner.login}/#{project.identifier}" + } + }, + "repository": { + "id": project.id, + "owner": { + "id": project.owner.id, + "login": "#{project.owner.login}", + "full_name": "", + "email": "#{project.owner.mail}", + "avatar_url": "#{domain}/#{url_to_avatar(project.owner)}", + "language": "", + "is_admin": false, + "last_login": "#{project.owner.last_login_on}", + "created": "#{project.owner.created_on}", + "restricted": false, + "active": false, + "prohibit_login": false, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "#{project.owner.login}" + }, + "name": "#{project.identifier}", + "full_name": "#{project.owner.login}/#{project.identifier}", + "description": "", + "empty": false, + "private": false, + "fork": false, + "template": false, + "parent": null, + "mirror": false, + "size": 843, + "html_url": "#{domain}/#{project.owner.login}/#{project.identifier}", + "ssh_url": "#{ssh_url}", + "clone_url": "#{domain}/#{project.owner.login}/#{project.identifier}.git", + "original_url": "#{project.repository.mirror_url}", + "website": "", + "stars_count": 0, + "forks_count": 0, + "watchers_count": 1, + "open_issues_count": 1, + "open_pr_counter": 0, + "release_counter": 0, + "default_branch": "master", + "archived": false, + "created_at": "#{project.created_on}", + "updated_at": "#{project.updated_on}", + "permissions": { + "admin": true, + "push": true, + "pull": true + }, + "has_issues": true, + "internal_tracker": { + "enable_time_tracker": true, + "allow_only_contributors_to_track_time": true, + "enable_issue_dependencies": true + }, + "has_wiki": true, + "has_pull_requests": true, + "has_projects": false, + "ignore_whitespace_conflicts": false, + "allow_merge_commits": true, + "allow_rebase": true, + "allow_rebase_explicit": true, + "allow_squash_merge": true, + "default_merge_style": "merge", + "avatar_url": "", + "internal": false, + "mirror_interval": "" + }, + "sender": { + "id": user.id, + "login": "#{user.login}", + "full_name": "", + "email": "#{user.mail}", + "avatar_url": "#{domain}/#{url_to_avatar(user)}", + "language": "", + "is_admin": false, + "last_login": "#{user.last_login_on}", + "created": "#{user.created_on}", + "restricted": false, + "active": false, + "prohibit_login": false, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "#{user.login}" + } + } + + url = URI("http://117.50.185.50:80") + http = Net::HTTP.new(url.host, url.port) + request = Net::HTTP::Post.new(url) + request["Content-Type"] = "application/json" + uuid = SecureRandom.uuid + request['X-GitHub-Delivery'] = uuid + request['X-Gitea-Delivery'] = uuid + request['X-Gogs-Delivery'] = uuid + request['X-GitHub-Event'] = 'issues' + request['X-Gitea-Event'] = 'issues' + request['X-Gogs-Event'] = 'issues' + request.body = JSON.dump(event_json) + + response = http.request(request) + Rails.logger.info "issue webhook event======#{response.read_body}" + end + +end \ No newline at end of file From e03694021662edf7f30305d0893c9169666ceb35 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:41:20 +0800 Subject: [PATCH 57/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimo?= =?UTF-8?q?irelab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/issues_controller.rb | 2 +- app/jobs/{issue_webhook_job.rb => issue_web_hook_job.rb} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename app/jobs/{issue_webhook_job.rb => issue_web_hook_job.rb} (99%) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index efc7d3ea4..76aef3dc6 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -155,7 +155,7 @@ class IssuesController < ApplicationController Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}" AtmeService.call(current_user, @atme_receivers, @issue) if @atme_receivers.size > 0 # 新增时向grimoirelab推送事件 - IssueWebhookJob.set(wait: 5.seconds).perform_later(@issue.id) + IssueWebHookJob.set(wait: 5.seconds).perform_later(@issue.id) render json: {status: 0, message: "创建成功", id: @issue.id} else diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_web_hook_job.rb similarity index 99% rename from app/jobs/issue_webhook_job.rb rename to app/jobs/issue_web_hook_job.rb index b85c7c1e0..97501675f 100644 --- a/app/jobs/issue_webhook_job.rb +++ b/app/jobs/issue_web_hook_job.rb @@ -1,4 +1,4 @@ -class IssueWebhookJob < ApplicationJob +class IssueWebHookJob < ApplicationJob include ApplicationHelper queue_as :message From 578423942558aa9b1d380aa92c337b8877a2f9c3 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:42:15 +0800 Subject: [PATCH 58/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimo?= =?UTF-8?q?irelab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/issues_controller.rb | 2 +- app/jobs/{issue_web_hook_job.rb => issue_webhook_job.rb} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename app/jobs/{issue_web_hook_job.rb => issue_webhook_job.rb} (99%) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 76aef3dc6..efc7d3ea4 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -155,7 +155,7 @@ class IssuesController < ApplicationController Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}" AtmeService.call(current_user, @atme_receivers, @issue) if @atme_receivers.size > 0 # 新增时向grimoirelab推送事件 - IssueWebHookJob.set(wait: 5.seconds).perform_later(@issue.id) + IssueWebhookJob.set(wait: 5.seconds).perform_later(@issue.id) render json: {status: 0, message: "创建成功", id: @issue.id} else diff --git a/app/jobs/issue_web_hook_job.rb b/app/jobs/issue_webhook_job.rb similarity index 99% rename from app/jobs/issue_web_hook_job.rb rename to app/jobs/issue_webhook_job.rb index 97501675f..b85c7c1e0 100644 --- a/app/jobs/issue_web_hook_job.rb +++ b/app/jobs/issue_webhook_job.rb @@ -1,4 +1,4 @@ -class IssueWebHookJob < ApplicationJob +class IssueWebhookJob < ApplicationJob include ApplicationHelper queue_as :message From 382d8c430cb793d1c46b35dfacbff4698bd7f93c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:44:42 +0800 Subject: [PATCH 59/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimo?= =?UTF-8?q?irelab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/issue_webhook_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_webhook_job.rb index b85c7c1e0..375688663 100644 --- a/app/jobs/issue_webhook_job.rb +++ b/app/jobs/issue_webhook_job.rb @@ -2,7 +2,7 @@ class IssueWebhookJob < ApplicationJob include ApplicationHelper queue_as :message - def perform(issue_id, user_id) + def perform(issue_id) issue = Issue.find_by(id: issue_id) return if issue.blank? project = issue.project From 48fe09345e3b6d774816bb9bea34da18f892a878 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:46:15 +0800 Subject: [PATCH 60/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimo?= =?UTF-8?q?irelab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/issue_webhook_job.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_webhook_job.rb index 375688663..23a4f978a 100644 --- a/app/jobs/issue_webhook_job.rb +++ b/app/jobs/issue_webhook_job.rb @@ -46,17 +46,17 @@ class IssueWebhookJob < ApplicationJob "body": "#{issue.description}", "ref": "", "labels": [], - "milestone": null, - "assignee": null, - "assignees": null, + "milestone": nil, + "assignee": nil, + "assignees": nil, "state": "open", "is_locked": false, "comments": 0, "created_at": "#{issue.created_on}", "updated_at": "#{issue.updated_on}", - "closed_at": null, - "due_date": null, - "pull_request": null, + "closed_at": nil, + "due_date": nil, + "pull_request": nil, "repository": { "id": 11307, "name": "#{project.identifier}", @@ -95,7 +95,7 @@ class IssueWebhookJob < ApplicationJob "private": false, "fork": false, "template": false, - "parent": null, + "parent": nil, "mirror": false, "size": 843, "html_url": "#{domain}/#{project.owner.login}/#{project.identifier}", From e907cae4dc61486e67a29935a9dcde1db43d1474 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:51:06 +0800 Subject: [PATCH 61/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimo?= =?UTF-8?q?irelab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6,=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/issue_webhook_job.rb | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_webhook_job.rb index 23a4f978a..34dcdffaa 100644 --- a/app/jobs/issue_webhook_job.rb +++ b/app/jobs/issue_webhook_job.rb @@ -9,7 +9,7 @@ class IssueWebhookJob < ApplicationJob user = issue.user domain = "#{Rails.application.config_for(:configuration)['platform_url']}" gitea_domain = GiteaService.gitea_config[:domain] - ssh_url = "git@#{gitea_domain.gsub("https://","")}:#{project.owner.login}/#{project.identifier}.git" + ssh_url = "git@#{gitea_domain.gsub("https://", "")}:#{project.owner.login}/#{project.identifier}.git" event_json = { "action": "opened", "number": 1, @@ -161,21 +161,26 @@ class IssueWebhookJob < ApplicationJob } } - url = URI("http://117.50.185.50:80") - http = Net::HTTP.new(url.host, url.port) - request = Net::HTTP::Post.new(url) - request["Content-Type"] = "application/json" - uuid = SecureRandom.uuid - request['X-GitHub-Delivery'] = uuid - request['X-Gitea-Delivery'] = uuid - request['X-Gogs-Delivery'] = uuid - request['X-GitHub-Event'] = 'issues' - request['X-Gitea-Event'] = 'issues' - request['X-Gogs-Event'] = 'issues' - request.body = JSON.dump(event_json) + begin + url = URI("http://117.50.185.50:80") + http = Net::HTTP.new(url.host, url.port) + request = Net::HTTP::Post.new(url) + request["Content-Type"] = "application/json" + uuid = SecureRandom.uuid + request['X-GitHub-Delivery'] = uuid + request['X-Gitea-Delivery'] = uuid + request['X-Gogs-Delivery'] = uuid + request['X-GitHub-Event'] = 'issues' + request['X-Gitea-Event'] = 'issues' + request['X-Gogs-Event'] = 'issues' + request.body = JSON.dump(event_json) - response = http.request(request) - Rails.logger.info "issue webhook event======#{response.read_body}" + response = http.request(request) + Rails.logger.info "issue webhook event======#{response.read_body}" + rescue Exception => e + Rails.logger.info "issue webhook event error======#{e.message}" + puts "issue webhook event error======#{e.message}" + end end end \ No newline at end of file From abef11f71c2c807644317df514f970e9cf746511 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:54:43 +0800 Subject: [PATCH 62/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimo?= =?UTF-8?q?irelab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6,=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/issue_webhook_job.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_webhook_job.rb index 34dcdffaa..445a0b02c 100644 --- a/app/jobs/issue_webhook_job.rb +++ b/app/jobs/issue_webhook_job.rb @@ -176,10 +176,10 @@ class IssueWebhookJob < ApplicationJob request.body = JSON.dump(event_json) response = http.request(request) - Rails.logger.info "issue webhook event======#{response.read_body}" + Rails.logger.info "issue #{issue_id} webhook event======#{response.read_body}" rescue Exception => e - Rails.logger.info "issue webhook event error======#{e.message}" - puts "issue webhook event error======#{e.message}" + Rails.logger.info "issue #{issue_id} webhook event error======#{e.message}" + puts "issue: #{issue_id} webhook event error======#{e.message}" end end From e92b288f4167d9db00b89f097b0697621d921276 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 16:07:51 +0800 Subject: [PATCH 63/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimo?= =?UTF-8?q?irelab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6,=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86,log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/issue_webhook_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_webhook_job.rb index 445a0b02c..abd8a2322 100644 --- a/app/jobs/issue_webhook_job.rb +++ b/app/jobs/issue_webhook_job.rb @@ -160,7 +160,7 @@ class IssueWebhookJob < ApplicationJob "username": "#{user.login}" } } - + puts "event_json:#{event_json.to_json}" begin url = URI("http://117.50.185.50:80") http = Net::HTTP.new(url.host, url.port) From 3427fa676850a74489c90319530b38e2b34743cc Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 16:11:40 +0800 Subject: [PATCH 64/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimo?= =?UTF-8?q?irelab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6,=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/issue_webhook_job.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_webhook_job.rb index abd8a2322..4027a55b2 100644 --- a/app/jobs/issue_webhook_job.rb +++ b/app/jobs/issue_webhook_job.rb @@ -14,7 +14,7 @@ class IssueWebhookJob < ApplicationJob "action": "opened", "number": 1, "issue": { - "id": 888, + "id": issue.id, "url": "#{domain}/api/v1/#{project.owner.login}/#{project.identifier}/issues/#{issue.id}", "html_url": "#{domain}/#{project.owner.login}/#{project.identifier}/issues/#{issue.id}", "number": 1, @@ -160,7 +160,7 @@ class IssueWebhookJob < ApplicationJob "username": "#{user.login}" } } - puts "event_json:#{event_json.to_json}" + # puts "event_json:#{event_json.to_json}" begin url = URI("http://117.50.185.50:80") http = Net::HTTP.new(url.host, url.port) From d731cac2805bf2d3ca1c4d8607e21632c91e3fdb Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 16:07:51 +0800 Subject: [PATCH 65/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimo?= =?UTF-8?q?irelab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6,=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86,log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/issue_webhook_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_webhook_job.rb index 445a0b02c..abd8a2322 100644 --- a/app/jobs/issue_webhook_job.rb +++ b/app/jobs/issue_webhook_job.rb @@ -160,7 +160,7 @@ class IssueWebhookJob < ApplicationJob "username": "#{user.login}" } } - + puts "event_json:#{event_json.to_json}" begin url = URI("http://117.50.185.50:80") http = Net::HTTP.new(url.host, url.port) From e0c074443d13cbf9543eeb6f5861cbef913d66e1 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 16:11:40 +0800 Subject: [PATCH 66/67] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimo?= =?UTF-8?q?irelab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6,=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/issue_webhook_job.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_webhook_job.rb index abd8a2322..4027a55b2 100644 --- a/app/jobs/issue_webhook_job.rb +++ b/app/jobs/issue_webhook_job.rb @@ -14,7 +14,7 @@ class IssueWebhookJob < ApplicationJob "action": "opened", "number": 1, "issue": { - "id": 888, + "id": issue.id, "url": "#{domain}/api/v1/#{project.owner.login}/#{project.identifier}/issues/#{issue.id}", "html_url": "#{domain}/#{project.owner.login}/#{project.identifier}/issues/#{issue.id}", "number": 1, @@ -160,7 +160,7 @@ class IssueWebhookJob < ApplicationJob "username": "#{user.login}" } } - puts "event_json:#{event_json.to_json}" + # puts "event_json:#{event_json.to_json}" begin url = URI("http://117.50.185.50:80") http = Net::HTTP.new(url.host, url.port) From 32a7ad97b46b13e4901a678d184791500cc7adcc Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 20 Feb 2023 18:23:45 +0800 Subject: [PATCH 67/67] Update configuration.yml.example --- config/configuration.yml.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/configuration.yml.example b/config/configuration.yml.example index f056dee1b..77332ef5e 100644 --- a/config/configuration.yml.example +++ b/config/configuration.yml.example @@ -45,8 +45,8 @@ default: &default callback_url: 'callback_url' signature_key: 'test12345678' educoder: - client_id: 'e9ce4d5ba1698d6f7d01d8ee2959776c7a6d743ebe94da2341e288fd2fbf60aa' - client_secret: '6ff84dd75eddd859c5bd0e7a791b58bc5ad1ba4fbb30bc9db37cb0baf9f33012' + client_id: 'test' + client_secret: 'test' base_url: 'https://test-data.educoder.net' redirect_uri: 'https://testforgeplus.trustie.net/api/auth/educoder/callback'