Skip to content

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

Fix Author wrongfully stated as the user referencing a work package

Aaron Contreras924b0118f916
diff --git a/modules/github_integration/config/locales/js-en.yml b/modules/github_integration/config/locales/js-en.yml
index 47236883571..a306ae694fa 100644
--- a/modules/github_integration/config/locales/js-en.yml
+++ b/modules/github_integration/config/locales/js-en.yml
@@ -49,7 +49,7 @@ en:
github_actions: Actions
pull_requests:
message: "Pull request #%{pr_number} %{pr_link} for %{repository_link} has been %{pr_state} by %{github_user_link}."
- referenced_message: "%{github_user_link} referenced this work package in pull request #%{pr_number} %{pr_link} on %{repository_link}."
+ referenced_message: "Pull request #%{pr_number} %{pr_link} for %{repository_link} authored by %{github_user_link} referenced this work package."
states:
opened: 'opened'
closed: 'closed'
diff --git a/modules/github_integration/spec/features/work_package_activity_spec.rb b/modules/github_integration/spec/features/work_package_activity_spec.rb
index 74cf4082e0c..8b62a11b083 100644
--- a/modules/github_integration/spec/features/work_package_activity_spec.rb
+++ b/modules/github_integration/spec/features/work_package_activity_spec.rb
@@ -6,14 +6,14 @@ RSpec.describe 'Work Package Activity Tab',
'Comments by Github',
:js,
:with_cuprite do
- shared_let(:github_system_user) { create(:admin) }
+ shared_let(:github_system_user) { create(:admin, firstname: 'Github', lastname: 'System User') }
shared_let(:admin) { create(:admin) }
shared_let(:project) { create(:project, enabled_module_names: Setting.default_projects_modules + %w[activity]) }
shared_let(:work_package) { create(:work_package, project:) }
- shared_let(:pull_request_author) { create(:github_user) }
- shared_let(:pull_request_merging_user) { create(:github_user) }
+ shared_let(:pull_request_author) { create(:github_user, github_login: 'i_am_the_author') }
+ shared_let(:pull_request_merging_user) { create(:github_user, github_login: 'i_merged') }
shared_let(:pull_request) do
create(:github_pull_request,
github_user: pull_request_author)
@@ -26,6 +26,13 @@ RSpec.describe 'Work Package Activity Tab',
pull_request.reload
end
+ def upsert_pull_request_with_reference
+ OpenProject::GithubIntegration::NotificationHandler::PullRequest.new
+ .process(referenced_payload)
+
+ pull_request.reload
+ end
+
let(:closed_merged_payload) do
{
'action' => 'closed',
@@ -35,6 +42,15 @@ RSpec.describe 'Work Package Activity Tab',
}
end
+ let(:referenced_payload) do
+ {
+ 'action' => 'referenced',
+ 'open_project_user_id' => github_system_user.id,
+ 'pull_request' => pull_request_hash,
+ 'sender' => sender_section_hash
+ }
+ end
+
let(:pull_request_hash) do
{
'id' => pull_request.id,
@@ -43,37 +59,29 @@ RSpec.describe 'Work Package Activity Tab',
'title' => pull_request.title,
'html_url' => pull_request.github_html_url,
'updated_at' => Time.current.iso8601,
- 'state' => 'closed',
+ 'state' => state,
'draft' => false,
'merged' => true,
'merged_by' => merged_by_section_hash,
- 'merged_at' => Time.current.iso8601,
+ 'merged_at' => merged_at,
'comments' => pull_request.comments_count + 1,
'review_comments' => pull_request.review_comments_count,
'additions' => pull_request.additions_count,
'deletions' => pull_request.deletions_count,
'changed_files' => pull_request.changed_files_count,
'labels' => pull_request.labels,
- 'user' => author_section_hash,
- 'base' => base_section_hash
- }
- end
-
- let(:merged_by_section_hash) do
- {
- 'id' => pull_request_merging_user.github_id,
- 'login' => pull_request_merging_user.github_login,
- 'html_url' => pull_request_merging_user.github_html_url,
- 'avatar_url' => pull_request_merging_user.github_avatar_url
- }
- end
-
- let(:author_section_hash) do
- {
- 'id' => pull_request_author.github_id,
- 'login' => pull_request_author.github_login,
- 'html_url' => pull_request_author.github_html_url,
- 'avatar_url' => pull_request_author.github_avatar_url
+ 'user' => {
+ 'id' => pull_request_author.github_id,
+ 'login' => pull_request_author.github_login,
+ 'html_url' => pull_request_author.github_html_url,
+ 'avatar_url' => pull_request_author.github_avatar_url
+ },
+ 'base' => {
+ 'repo' => {
+ 'full_name' => 'author_user/repo',
+ 'html_url' => 'github.com/author_user/repo'
+ }
+ }
}
end
@@ -84,27 +92,26 @@ RSpec.describe 'Work Package Activity Tab',
}
end
- let(:base_section_hash) do
- {
- 'repo' => {
- 'full_name' => 'author_user/repo',
- 'html_url' => 'github.com/author_user/repo'
- }
- }
- end
-
let(:work_package_page) { Pages::SplitWorkPackage.new(work_package, project) }
- before do
- login_as admin
- end
-
context 'when the pull request is merged' do
before do
upsert_pull_request_with_merge
+ login_as admin
end
context "and I visit the work package's activity tab" do
+ let(:merged_by_section_hash) do
+ {
+ 'id' => pull_request_merging_user.github_id,
+ 'login' => pull_request_merging_user.github_login,
+ 'html_url' => pull_request_merging_user.github_html_url,
+ 'avatar_url' => pull_request_merging_user.github_avatar_url
+ }
+ end
+ let(:merged_at) { Time.current.iso8601 }
+ let(:state) { 'closed' }
+
before do
work_package_page.visit_tab! 'activity'
work_package_page.ensure_page_loaded
@@ -124,4 +131,35 @@ RSpec.describe 'Work Package Activity Tab',
end
end
end
+
+ context 'when the Work Package is referenced in a Pull Request' do
+ let(:merged_by_section_hash) { {} }
+ let(:merged_at) { nil }
+ let(:state) { 'open' }
+
+ before do
+ upsert_pull_request_with_reference
+ login_as admin
+ end
+
+ context "and I visit the work package's activity tab" do
+ before do
+ work_package_page.visit_tab! 'activity'
+ work_package_page.ensure_page_loaded
+ end
+
+ it 'renders a comment stating the Work Package was referenced in the Pull Request' do
+ expected_referenced_comment = <<~GITHUB_REFERENCED_COMMENT.squish
+ Referenced#{I18n.t('js.github_integration.pull_requests.referenced_message',
+ pr_number: pull_request.number,
+ pr_link: pull_request.title,
+ repository_link: pull_request.repository,
+ pr_state: 'referenced',
+ github_user_link: pull_request_author.github_login)}
+ GITHUB_REFERENCED_COMMENT
+
+ expect(page).to have_selector('.user-comment > .message', text: expected_referenced_comment)
+ end
+ end
+ end
end