Commit c6bba8e3 authored by Lennard Sprong's avatar Lennard Sprong
Browse files

feat: Add setting for hiding closed Merge Requests

parent 669811aa
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1110,6 +1110,11 @@
            "default": true,
            "description": "Apply branch protection rules from GitLab"
          },
          "gitlab.showClosedMergeRequests": {
            "type": "boolean",
            "default": true,
            "description": "Show merged or closed Merge Requests for current branch"
          },
          "gitlab.pipelineGitRemoteName": {
            "type": "string",
            "default": null,
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ export const DUO_CODE_SUGGESTIONS_USER_LANGUAGES = 'gitlab.duoCodeSuggestions.ad

export const DUO_ENABLE_WITHOUT_GITLAB_PROJECT = 'gitlab.duo.enabledWithoutGitlabProject';
export const GITLAB_BRANCH_PROTECTION = 'gitlab.branchProtection';
export const GITLAB_SHOW_CLOSED_MRS = 'gitlab.showClosedMergeRequests';
export const DUO_CHAT_CONFIG_NAMESPACE = 'gitlab.duoChat';
export const DUO_AGENT_PLATFORM_CONFIG_NAMESPACE = 'gitlab.duoAgentPlatform';

+10 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ import {
  getLocalFeatureFlagService,
} from '../common/feature_flags/local_feature_flag_service';
import { UserFriendlyError } from '../common/errors/user_friendly_error';
import { GITLAB_SHOW_CLOSED_MRS } from '../common/utils/extension_configuration';
import { getExtensionStateSingleton } from './extension_state';
import { getActiveProject } from './commands/run_with_valid_project';
import { ProjectInRepository } from './gitlab/new_project';
@@ -77,6 +78,8 @@ export class CurrentBranchRefresher {

  onStateChanged = this.#stateChangedEmitter.event;

  #configListener?: vscode.Disposable;

  #lastRefresh = dayjs().subtract(1, 'minute');

  #previousBranchName = '';
@@ -109,6 +112,12 @@ export class CurrentBranchRefresher {
        await this.clearAndSetIntervalAndRefresh();
      }
    }, 1000);

    this.#configListener = vscode.workspace.onDidChangeConfiguration(async ev => {
      if (ev.affectsConfiguration(GITLAB_SHOW_CLOSED_MRS)) {
        await this.clearAndSetIntervalAndRefresh();
      }
    });
  }

  async clearAndSetIntervalAndRefresh(): Promise<void> {
@@ -223,6 +232,7 @@ export class CurrentBranchRefresher {
  dispose() {
    this.stopTimers();
    this.#stateChangedEmitter.dispose();
    this.#configListener?.dispose();
  }
}

+20 −0
Original line number Diff line number Diff line
import * as vscode from 'vscode';
import { createFakeWorkspaceConfiguration } from '../../common/test_utils/vscode_fakes';
import { mr } from '../test_utils/entities';
import { getMostRelevantMergeRequest } from './get_most_relevant_merge_request';

describe('getMostRelevantMergeRequest', () => {
  beforeEach(() => {
    jest
      .mocked(vscode.workspace.getConfiguration)
      .mockReturnValue(createFakeWorkspaceConfiguration({ showClosedMergeRequests: true }));
  });

  it('returns undefined when the list is empty', () => {
    expect(getMostRelevantMergeRequest(undefined)).toBeUndefined();
    expect(getMostRelevantMergeRequest([])).toBeUndefined();
@@ -28,4 +36,16 @@ describe('getMostRelevantMergeRequest', () => {
    ];
    expect(getMostRelevantMergeRequest(mrs)).toBe(mrs[2]);
  });

  it('does not return a merged MR when disabled', () => {
    jest
      .mocked(vscode.workspace.getConfiguration)
      .mockReturnValue(createFakeWorkspaceConfiguration({ showClosedMergeRequests: false }));

    const mrs: RestMr[] = [
      { ...mr, state: 'closed' },
      { ...mr, state: 'merged' },
    ];
    expect(getMostRelevantMergeRequest(mrs)).toBeUndefined();
  });
});
+7 −1
Original line number Diff line number Diff line
import * as vscode from 'vscode';

export function getMostRelevantMergeRequest(items?: RestMr[]): RestMr | undefined {
  if (!items || items.length === 0) {
    return undefined;
  }

  const sorted = [...items].sort((a, b) => {
  const includeClosed = vscode.workspace.getConfiguration('gitlab').showClosedMergeRequests;

  const filtered = includeClosed ? items : items.filter(i => i.state === 'opened');

  const sorted = [...filtered].sort((a, b) => {
    // `state` is being compared as a string, but the alphabetical order
    // also matches the priority.
    //