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

Add counter to github tab (#11938)

Oliver Günther20e9280d1963
diff --git a/modules/github_integration/frontend/module/main.ts b/modules/github_integration/frontend/module/main.ts
index 6bcbaee116f..54fc79f7330 100644
--- a/modules/github_integration/frontend/module/main.ts
+++ b/modules/github_integration/frontend/module/main.ts
@@ -35,6 +35,21 @@ import { GitActionsMenuDirective } from './git-actions-menu/git-actions-menu.dir
import { GitActionsMenuComponent } from './git-actions-menu/git-actions-menu.component';
import { WorkPackagesGithubPrsService } from './tab-prs/wp-github-prs.service';
import { PullRequestComponent } from './pull-request/pull-request.component';
+import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
+import { Observable } from 'rxjs';
+import { map } from 'rxjs/operators';
+
+export function workPackageGithubPrsCount(
+ workPackage:WorkPackageResource,
+ injector:Injector,
+):Observable<number> {
+ const githubPrsService = injector.get(WorkPackagesGithubPrsService);
+ return githubPrsService
+ .requireAndStream(workPackage)
+ .pipe(
+ map((prs) => prs.length),
+ );
+}
export function initializeGithubIntegrationPlugin(injector:Injector) {
const wpTabService = injector.get(WorkPackageTabsService);
@@ -43,6 +58,7 @@ export function initializeGithubIntegrationPlugin(injector:Injector) {
name: I18n.t('js.github_integration.work_packages.tab_name'),
id: 'github',
displayable: (workPackage) => !!workPackage.github,
+ count: workPackageGithubPrsCount,
});
}
diff --git a/modules/github_integration/spec/features/work_package_github_tab_spec.rb b/modules/github_integration/spec/features/work_package_github_tab_spec.rb
index 46285b4ea24..a5f25cc6a67 100644
--- a/modules/github_integration/spec/features/work_package_github_tab_spec.rb
+++ b/modules/github_integration/spec/features/work_package_github_tab_spec.rb
@@ -47,6 +47,9 @@ describe 'Open the GitHub tab', js: true do
let(:pull_request) { create :github_pull_request, :open, work_packages: [work_package], title: 'A Test PR title' }
let(:check_run) { create :github_check_run, github_pull_request: pull_request, name: 'a check run name' }
+ let(:tabs) { Components::WorkPackages::Tabs.new(work_package) }
+ let(:github_tab_element) { find('.op-tab-row--link_selected', text: 'GITHUB') }
+
shared_examples_for "a github tab" do
before do
check_run
@@ -70,6 +73,8 @@ describe 'Open the GitHub tab', js: true do
work_package_page.visit!
work_package_page.switch_to_tab(tab: 'github')
+ tabs.expect_counter(github_tab_element, 1)
+
github_tab.git_actions_menu_button.click
github_tab.git_actions_copy_branch_name_button.click
expect(page).to have_text('Copied!')
@@ -86,6 +91,7 @@ describe 'Open the GitHub tab', js: true do
it 'shows the github tab with an empty-pull-requests message' do
work_package_page.visit!
work_package_page.switch_to_tab(tab: 'github')
+ tabs.expect_no_counter(github_tab_element)
expect(page).to have_content('There are no pull requests')
expect(page).to have_content("Link an existing PR by using the code OP##{work_package.id}")
end