OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
pull introspection impl into github integration, add specs
Markus Kahl547bd8c65c14
diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rbindex af40b15e9e4..8fef00702ad 100644--- a/config/constants/settings/definition.rb+++ b/config/constants/settings/definition.rb@@ -567,10 +567,6 @@ module Settingsdescription: "Require password confirmations for certain administrative actions",default: true},- introspection_enabled: {- description: "If enabled, expose detailed information the running OpenProject environment to users with the necessary permissions.",- default: true- },invitation_expiration_days: {default: 7},diff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rbindex 0f2b2dfcdfb..c92ee82c1f1 100644--- a/config/initializers/permissions.rb+++ b/config/initializers/permissions.rb@@ -61,14 +61,6 @@ Rails.application.reloader.to_prepare dorequire: :loggedin,contract_actions: { users: %i[read create] }- map.permission :introspection,- {- admin: %i[info]- },- permissible_on: :global,- require: :loggedin,- enabled: -> { Setting.introspection_enabled? }-map.permission :manage_user,{users: %i[index show edit update change_status change_status_info],diff --git a/lib/api/v3/root_representer.rb b/lib/api/v3/root_representer.rbindex 4c8179ed3d5..41f25b10006 100644--- a/lib/api/v3/root_representer.rb+++ b/lib/api/v3/root_representer.rb@@ -111,11 +111,6 @@ module APIgetter: ->(*) { OpenProject::VERSION.to_semver },if: ->(*) { current_user.admin? || current_user.allowed_globally?(:introspection) }- property :core_sha,- exec_context: :decorator,- getter: ->(*) { OpenProject::VERSION.core_sha },- if: ->(*) { current_user.admin? || current_user.allowed_globally?(:introspection) }-def _type"Root"enddiff --git a/modules/github_integration/lib/open_project/github_integration/engine.rb b/modules/github_integration/lib/open_project/github_integration/engine.rbindex 81ecb138c88..5d8b3516905 100644--- a/modules/github_integration/lib/open_project/github_integration/engine.rb+++ b/modules/github_integration/lib/open_project/github_integration/engine.rb@@ -47,7 +47,7 @@ module OpenProject::GithubIntegration::Redmine::MenuManager.map(:admin_menu) do |menu|menu.push :admin_github_integration,{ controller: "/deploy_targets", action: "index" },- if: Proc.new { Setting.feature_deploy_targets_active? && User.current.admin? },+ if: Proc.new { OpenProject::FeatureDecisions.deploy_targets_active? && User.current.admin? },caption: :label_github_integration,icon: "github_logo"end@@ -56,12 +56,20 @@ module OpenProject::GithubIntegrationpermission(:show_github_content,{},permissible_on: %i[work_package project])++ permission :introspection,+ {+ admin: %i[info]+ },+ permissible_on: :global,+ require: :loggedin,+ enabled: -> { OpenProject::FeatureDecisions.deploy_targets_active? } # can only be enable at start-timeendmenu :admin_menu,:deploy_targets,{ controller: "/deploy_targets", action: "index" },- if: ->(*) { Setting.feature_deploy_targets_active? && User.current.admin? },+ if: ->(*) { OpenProject::FeatureDecisions.deploy_targets_active? && User.current.admin? },parent: :admin_github_integration,caption: :label_deploy_target_plural,icon: "hosting"@@ -84,6 +92,13 @@ module OpenProject::GithubIntegrationendend+ extend_api_response(:v3, :root) do+ property :core_sha,+ exec_context: :decorator,+ getter: ->(*) { OpenProject::VERSION.core_sha },+ if: ->(*) { current_user.admin? || current_user.allowed_globally?(:introspection) }+ end+extend_api_response(:v3, :work_packages, :work_package,&::OpenProject::GithubIntegration::Patches::API::WorkPackageRepresenter.extension)@@ -118,7 +133,7 @@ module OpenProject::GithubIntegration# Enabling the feature flag at runtime won't enable# the cron job. So if you want this feature, enable it# at start-time.- if Setting.feature_deploy_targets_active?+ if OpenProject::FeatureDecisions.deploy_targets_active?jobs["Cron::CheckDeployStatusJob"] = {cron: "15,45 * * * *", # runs every half hourclass: ::Cron::CheckDeployStatusJob.namediff --git a/modules/github_integration/spec/factories/deploy_target_factory.rb b/modules/github_integration/spec/factories/deploy_target_factory.rbindex ac3cd2ecdea..a40895a43ad 100644--- a/modules/github_integration/spec/factories/deploy_target_factory.rb+++ b/modules/github_integration/spec/factories/deploy_target_factory.rb@@ -31,5 +31,7 @@ FactoryBot.define dotype { "OpenProject" }sequence(:host) { |n| "https://qa-#{n}.openproject-edge.com" }++ api_key { '4p1k3y' }endenddiff --git a/modules/github_integration/spec/requests/extended_root_resource_spec.rb b/modules/github_integration/spec/requests/extended_root_resource_spec.rbnew file mode 100644index 00000000000..d380dfde3b9--- /dev/null+++ b/modules/github_integration/spec/requests/extended_root_resource_spec.rb@@ -0,0 +1,90 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require "spec_helper"+require "rack/test"++RSpec.describe "API v3 Root resource with the github integration extension", with_flag: { deploy_targets: true } do+ include Rack::Test::Methods+ include API::V3::Utilities::PathHelper++ let(:current_user) do+ create(:user, member_with_roles: { project => role })+ end+ let(:role) { create(:project_role, permissions: []) }+ let(:project) { create(:project, public: false) }++ before do+ # reset permissions cache, otherwise the introspection permissions enabled with the+ # deploy_targets feature flag won't be registered+ OpenProject::AccessControl.instance_variable_set(:@permissions, nil)+ end++ describe "#get" do+ let(:response) { last_response }+ let(:get_path) { api_v3_paths.root }++ subject { response.body }++ context "without introspection permission" do+ before do+ allow(User).to receive(:current).and_return(current_user)++ get get_path+ end++ it "responds with 200" do+ expect(response.status).to eq(200)+ end++ it "does not include the core SHA in the res" do+ expect(subject).not_to have_json_path("coreSha")+ end+ end++ context "with introspection permission" do+ let(:current_user) { create(:user, global_permissions: [:introspection]) }+ let(:core_sha) { "b86f391bf02c345e934ca8a945d83fc82d2063ef" }++ before do+ allow(OpenProject::VERSION).to receive(:core_sha).and_return core_sha+ allow(User).to receive(:current).and_return(current_user)++ get get_path+ end++ it "responds with 200" do+ expect(response.status).to eq(200)+ end++ it "does includes the core SHA in the response" do+ expect(subject).to be_json_eql(core_sha.to_json ).at_path("coreSha")+ end+ end+ end+enddiff --git a/modules/github_integration/spec/workers/cron/check_deploy_status_job_spec.rb b/modules/github_integration/spec/workers/cron/check_deploy_status_job_spec.rbindex 6e4d2c69c6e..5de8a3f4be7 100644--- a/modules/github_integration/spec/workers/cron/check_deploy_status_job_spec.rb+++ b/modules/github_integration/spec/workers/cron/check_deploy_status_job_spec.rb@@ -28,18 +28,88 @@require "spec_helper"-RSpec.describe Cron::CheckDeployStatusJob, type: :job, with_flags { deploy_targets: true } do- let!(:deploy_target) { create(:deploy_target) }+RSpec.describe Cron::CheckDeployStatusJob, type: :job, with_flag: { deploy_targets: true } do+ let(:api_key) { "foobar42" }++ let(:merge_commit_sha) { "576e25f7befffa5fc02a4311704e9894a5c9bdd4" }+ let(:core_sha) { "663f3a128aef9c0b031cbd59bb6f740ee50130a7" }- let(:deploy_status_check) { create(:deploy_status_check, deploy_target:, pull_request:) }- let(:pull_request) { create(:github_pull_request, work_packages: [work_package]) }let(:work_package) { create(:work_package) }+ let(:deploy_target) { create(:deploy_target, api_key:) }+ let(:pull_request) { create(:github_pull_request, work_packages: [work_package], state: :closed, merge_commit_sha:) }+let(:job) { described_class.new }- context "with no prior checks" do+ context "with no prior checks and the same deployed sha" do+ before do+ deploy_target+ pull_request++ allow(job).to receive(:openproject_core_sha).with(deploy_target.host, api_key).and_return(core_sha)+ allow(job).to receive(:commit_contains?).with(core_sha, merge_commit_sha).and_return true++ job.perform+ end++ it "marks the pull request 'deployed'" do+ expect(pull_request.reload.state).to eq "deployed"+ end+ end++ context "with prior checks" dobefore do- job.run+ allow(job).to receive(:openproject_core_sha).with(deploy_target.host, api_key).and_return(core_sha)+ allow(job).to receive :commit_contains?+ end++ context "with the same core sha" do+ let!(:deploy_status_check) { create(:deploy_status_check, deploy_target:, github_pull_request: pull_request, core_sha:) }++ before do+ job.perform+ end++ it "leaves the pull request closed while not checking with github again" do+ expect(pull_request.reload.state).to eq "closed"+ expect(job).not_to have_received :commit_contains?+ end+ end++ context "with a different core sha in the previous check" do+ let!(:deploy_status_check) do+ create(:deploy_status_check, deploy_target:, github_pull_request: pull_request, core_sha: "foo")+ end++ before do+ allow(job).to receive(:commit_contains?).with(core_sha, merge_commit_sha).and_return contains_commit++ job.perform+ end++ context "with the same core sha deployed" do+ let(:contains_commit) { true }++ it "marks the pull request deployed" do+ expect(pull_request.reload.state).to eq "deployed"+ end++ it "has checked with github again" do+ expect(job).to have_received(:commit_contains?).with(core_sha, merge_commit_sha)+ end+ end++ context "with a different core sha deployed" do+ let(:contains_commit) { false }++ it "leaves the pull request closed" do+ expect(pull_request.reload.state).to eq "closed"+ end++ it "has checked with github again" do+ expect(job).to have_received(:commit_contains?).with(core_sha, merge_commit_sha)+ end+ endendendend