Skip to content

Commit fb47a5a

Browse files
committed
Applied 56 patch
1 parent 0b43586 commit fb47a5a

File tree

9 files changed

+194
-217
lines changed

9 files changed

+194
-217
lines changed

src/bitbucket/bitbucket-cloud/pullRequestsOverview.ts

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { DetailedSiteInfo } from '../../atlclients/authInfo';
2+
import { toISOString } from '../../react/atlascode/util/date-fns';
23
import { HTTPClient } from '../httpClient';
34
import { BitbucketSite, PullRequest, WorkspaceRepo } from '../model';
45
import { CloudPullRequestApi } from './pullRequests';
@@ -11,6 +12,21 @@ export interface OverviewViewState {
1112
};
1213
}
1314

15+
function updatedAfter(minUpdatedTs?: string) {
16+
return (pr: PullRequest) => {
17+
if (!minUpdatedTs) {
18+
return true;
19+
}
20+
21+
const updatedTsIsoString = toISOString(pr.data.updatedTs);
22+
if (!updatedTsIsoString) {
23+
return true;
24+
}
25+
26+
return updatedTsIsoString > minUpdatedTs;
27+
};
28+
}
29+
1430
export class PullRequestsOverviewApi {
1531
constructor(private client: HTTPClient) {}
1632

@@ -44,7 +60,11 @@ export class PullRequestsOverviewApi {
4460
};
4561
}
4662

47-
async getOverviewViewState(ownerSlug: string, site: DetailedSiteInfo): Promise<OverviewViewState> {
63+
async getOverviewViewState(
64+
ownerSlug: string,
65+
site: DetailedSiteInfo,
66+
minUpdatedTs: string,
67+
): Promise<OverviewViewState> {
4868
const fields = [
4969
'+pullRequests.*.author',
5070
'+pullRequests.*.closed_on',
@@ -74,24 +94,30 @@ export class PullRequestsOverviewApi {
7494
`/workspaces/${ownerSlug}/overview-view-state/?fields=${encodeURIComponent(fields)}`,
7595
);
7696

77-
const authored: PullRequest[] = data.pullRequests.authored.map((pr: any) => {
78-
const bbSite = this.extractSiteFromPRData(pr, site);
79-
const workspaceRepo = this.createWorkspaceRepoFromPRData(pr, bbSite);
97+
const authored: PullRequest[] = data.pullRequests.authored
98+
.map((pr: any) => {
99+
const bbSite = this.extractSiteFromPRData(pr, site);
100+
const workspaceRepo = this.createWorkspaceRepoFromPRData(pr, bbSite);
80101

81-
return CloudPullRequestApi.toPullRequestData(pr, bbSite, workspaceRepo);
82-
});
102+
return CloudPullRequestApi.toPullRequestData(pr, bbSite, workspaceRepo);
103+
})
104+
.filter(updatedAfter(minUpdatedTs));
83105

84-
const reviewing: PullRequest[] = data.pullRequests.reviewing.map((pr: any) => {
85-
const bbSite = this.extractSiteFromPRData(pr, site);
86-
const workspaceRepo = this.createWorkspaceRepoFromPRData(pr, bbSite);
87-
return CloudPullRequestApi.toPullRequestData(pr, bbSite, workspaceRepo);
88-
});
106+
const reviewing: PullRequest[] = data.pullRequests.reviewing
107+
.map((pr: any) => {
108+
const bbSite = this.extractSiteFromPRData(pr, site);
109+
const workspaceRepo = this.createWorkspaceRepoFromPRData(pr, bbSite);
110+
return CloudPullRequestApi.toPullRequestData(pr, bbSite, workspaceRepo);
111+
})
112+
.filter(updatedAfter(minUpdatedTs));
89113

90-
const closed: PullRequest[] = data.pullRequests.closed.map((pr: any) => {
91-
const bbSite = this.extractSiteFromPRData(pr, site);
92-
const workspaceRepo = this.createWorkspaceRepoFromPRData(pr, bbSite);
93-
return CloudPullRequestApi.toPullRequestData(pr, bbSite, workspaceRepo);
94-
});
114+
const closed: PullRequest[] = data.pullRequests.closed
115+
.map((pr: any) => {
116+
const bbSite = this.extractSiteFromPRData(pr, site);
117+
const workspaceRepo = this.createWorkspaceRepoFromPRData(pr, bbSite);
118+
return CloudPullRequestApi.toPullRequestData(pr, bbSite, workspaceRepo);
119+
})
120+
.filter(updatedAfter(minUpdatedTs));
95121

96122
const response: OverviewViewState = {
97123
pullRequests: {

src/bitbucket/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ export interface PullRequestApi {
371371
}
372372

373373
export interface PullRequestsOverviewApi {
374-
getOverviewViewState(ownerSlug: string, site: DetailedSiteInfo): Promise<OverviewViewState>;
374+
getOverviewViewState(ownerSlug: string, site: DetailedSiteInfo, minUpdatedTs: string): Promise<OverviewViewState>;
375375
}
376376

377377
export interface RepositoriesApi {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Commands } from '../../constants';
2+
import { executeVSCodeCommand, LifecycleFns, updateConfig } from './devsphereConfigurationManager';
3+
4+
async function reviewSetup(): Promise<void> {
5+
await Promise.all([
6+
executeVSCodeCommand(Commands.BitbucketPullRequestsOverviewFocus),
7+
updateConfig('workbench.editor', 'showTabs', 'single'),
8+
executeVSCodeCommand('workbench.action.closePanel'),
9+
executeVSCodeCommand('workbench.action.closeAuxiliaryBar'),
10+
]);
11+
}
12+
13+
async function reviewTeardown(): Promise<void> {
14+
await Promise.allSettled([
15+
updateConfig('workbench.editor', 'showTabs', 'multiple'),
16+
executeVSCodeCommand('workbench.files.action.focusFilesExplorer'),
17+
]);
18+
}
19+
20+
export const reviewLifecycleFns: LifecycleFns = {
21+
setup: reviewSetup,
22+
shutdown: reviewTeardown,
23+
};
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { commands, Disposable, workspace } from 'vscode';
2+
3+
export async function executeVSCodeCommand(command: string): Promise<void> {
4+
try {
5+
await commands.executeCommand(command);
6+
} catch (error) {
7+
console.error(`Failed to execute VS Code command: ${command}`, error);
8+
}
9+
}
10+
11+
export async function updateConfig(section: string, key: string, value: any): Promise<void> {
12+
const config = workspace.getConfiguration(section);
13+
if (config.get(key) !== value) {
14+
await config.update(key, value, true);
15+
}
16+
}
17+
18+
/**
19+
* Type representing all valid view names in the application.
20+
*
21+
* @important When creating a new view, you must add its name to this union type
22+
* and register its teardown function in the teardownFunctions map.
23+
*/
24+
export enum View {
25+
Review = 'review',
26+
Noop = 'noop',
27+
}
28+
29+
export type LifecycleFns = {
30+
setup: () => Promise<void>;
31+
shutdown: () => Promise<void>;
32+
};
33+
34+
export const getDefaultLifecycleFns = (): LifecycleFns => ({
35+
setup: async () => {},
36+
shutdown: async () => {},
37+
});
38+
39+
export class DevsphereConfigurationManager implements Disposable {
40+
private currentView: View = View.Noop;
41+
42+
constructor(private lifecycleFunctions: Record<View, LifecycleFns>) {}
43+
44+
dispose() {
45+
this.lifecycleFunctions = {
46+
[View.Noop]: getDefaultLifecycleFns(),
47+
[View.Review]: getDefaultLifecycleFns(),
48+
};
49+
}
50+
51+
async setupView(view: View) {
52+
if (view === this.currentView) {
53+
return;
54+
}
55+
56+
const oldView = this.currentView;
57+
this.currentView = view;
58+
59+
try {
60+
await this.lifecycleFunctions[oldView].shutdown();
61+
} catch (error) {
62+
console.error(`Failed to shutdown view: ${oldView}`, error);
63+
}
64+
65+
try {
66+
await this.lifecycleFunctions[view].setup();
67+
} catch (error) {
68+
console.error(`Failed to setup view: ${view}`, error);
69+
}
70+
}
71+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { commands, ExtensionContext } from 'vscode';
2+
3+
import { Commands } from '../../constants';
4+
import { reviewLifecycleFns } from './devsphereConfigReview';
5+
import {
6+
DevsphereConfigurationManager,
7+
getDefaultLifecycleFns,
8+
LifecycleFns,
9+
View,
10+
} from './devsphereConfigurationManager';
11+
12+
// Map view names to their teardown functions - must include all possible ViewName values
13+
const lifecycleFunctions: Record<View, LifecycleFns> = {
14+
[View.Review]: reviewLifecycleFns,
15+
[View.Noop]: getDefaultLifecycleFns(),
16+
};
17+
18+
export function registerDevsphereCommands(context: ExtensionContext): void {
19+
const devsphereConfigManager = new DevsphereConfigurationManager(lifecycleFunctions);
20+
21+
context.subscriptions.push(devsphereConfigManager);
22+
23+
context.subscriptions.push(
24+
commands.registerCommand(Commands.InitialiseDevsphereReviewSettings, () =>
25+
devsphereConfigManager.setupView(View.Review),
26+
),
27+
commands.registerCommand(Commands.ResetDevsphereCustomConfiguration, () =>
28+
devsphereConfigManager.setupView(View.Noop),
29+
),
30+
);
31+
}

0 commit comments

Comments
 (0)