improve VCS api (#7404)

* clearer names

* add gql types

* remove paths helper

* fix tests
This commit is contained in:
Jack Kavanagh 2024-05-14 11:01:19 +02:00 committed by GitHub
parent 03afa4d452
commit 2a6737ee98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 125 additions and 250 deletions

View File

@ -201,7 +201,7 @@ export class GitVCS {
return insomniaFiles;
}
async getBranch() {
async getCurrentBranch() {
const branch = await git.currentBranch({ ...this._baseOpts });
if (typeof branch !== 'string') {
@ -212,7 +212,7 @@ export class GitVCS {
}
async listBranches() {
const branch = await this.getBranch();
const branch = await this.getCurrentBranch();
const branches = await git.listBranches({ ...this._baseOpts });
// For some reason, master isn't in branches on fresh repo (no commits)
@ -337,7 +337,7 @@ export class GitVCS {
* @returns {Promise<boolean>}
*/
async canPush(gitCredentials?: GitCredentials | null): Promise<boolean> {
const branch = await this.getBranch();
const branch = await this.getCurrentBranch();
const remote = await this.getRemote('origin');
if (!remote) {
@ -385,7 +385,7 @@ export class GitVCS {
}
async pull(gitCredentials?: GitCredentials | null) {
console.log('[git] Pull remote=origin', await this.getBranch());
console.log('[git] Pull remote=origin', await this.getCurrentBranch());
return git.pull({
...this._baseOpts,
...gitCallbacks(gitCredentials),
@ -395,7 +395,7 @@ export class GitVCS {
}
async merge(theirBranch: string) {
const ours = await this.getBranch();
const ours = await this.getCurrentBranch();
console.log(`[git] Merge ${ours} <-- ${theirBranch}`);
return git.merge({
...this._baseOpts,
@ -516,7 +516,7 @@ export class GitVCS {
console.log('[git] Undo pending changes');
await git.checkout({
...this._baseOpts,
ref: await this.getBranch(),
ref: await this.getCurrentBranch(),
remote: 'origin',
force: true,
filepaths: fileFilter?.map(convertToPosixSep),

View File

@ -1,17 +0,0 @@
import { describe, expect, it } from '@jest/globals';
import * as paths from '../paths';
describe('paths', () => {
it('successes', async () => {
expect(paths.projectBase('p1')).toBe('/projects/p1/');
expect(paths.head('p1')).toBe('/projects/p1/head.json');
expect(paths.project('p1')).toBe('/projects/p1/meta.json');
expect(paths.blobs('p1')).toBe('/projects/p1/blobs/');
expect(paths.blob('p1', 'b1c1c2')).toBe('/projects/p1/blobs/b1/c1c2');
expect(paths.snapshots('p1')).toBe('/projects/p1/snapshots/');
expect(paths.snapshot('p1', 's1')).toBe('/projects/p1/snapshots/s1.json');
expect(paths.branches('p1')).toBe('/projects/p1/branches/');
expect(paths.branch('p1', 'master')).toBe('/projects/p1/branches/master.json');
});
});

View File

@ -33,7 +33,7 @@ describe('pullBackendProject()', () => {
describe('creating a new project', () => {
beforeEach(() => {
vcs.getRemoteBranches.mockResolvedValue([]);
vcs.getRemoteBranchNames.mockResolvedValue([]);
});
afterEach(() => {
@ -116,7 +116,7 @@ describe('pullBackendProject()', () => {
describe('pulling an existing project', () => {
it('should overwrite the parentId only for a workspace with the project id', async () => {
// Arrange
vcs.getRemoteBranches.mockResolvedValue([DEFAULT_BRANCH_NAME]);
vcs.getRemoteBranchNames.mockResolvedValue([DEFAULT_BRANCH_NAME]);
const existingWrk = await models.workspace.create({ _id: backendProject.rootDocumentId, name: backendProject.name });
const existingReq = await models.request.create({ parentId: existingWrk._id });
@ -151,7 +151,7 @@ describe('pullBackendProject()', () => {
it('should throw the corrected intercepted error', async () => {
// Arrange
vcs.getRemoteBranches.mockRejectedValue(new Error('invalid access to project'));
vcs.getRemoteBranchNames.mockRejectedValue(new Error('invalid access to project'));
// Act
const action = () => pullBackendProject({ vcs, backendProject, remoteProject: { remoteId: '' } });

View File

@ -6,7 +6,6 @@ import { baseModelSchema, workspaceModelSchema } from '../../../models/__schemas
import { projectSchema } from '../../__schemas__/type-schemas';
import MemoryDriver from '../../store/drivers/memory-driver';
import { BackendProject } from '../../types';
import * as paths from '../paths';
import { describeChanges } from '../util';
import { VCS } from '../vcs';
@ -524,12 +523,12 @@ describe('VCS', () => {
});
});
describe('getBranches()', () => {
describe('getBranchNames()', () => {
it('lists branches', async () => {
const v = await vcs('master');
await v.checkout([], 'branch-1');
await v.checkout([], 'branch-2');
const branches = await v.getBranches();
const branches = await v.getBranchNames();
expect(branches).toEqual(['master', 'branch-1', 'branch-2']);
});
});
@ -578,11 +577,11 @@ describe('VCS', () => {
await v.takeSnapshot('Add foo');
// Checkout branch
await v.checkout([], 'new-branch');
expect(await v.getBranches()).toEqual(['master', 'new-branch']);
expect(await v.getBranchNames()).toEqual(['master', 'new-branch']);
// Back to master and delete other branch
await v.checkout([], 'master');
await v.removeBranch('new-branch');
expect(await v.getBranches()).toEqual(['master']);
expect(await v.getBranchNames()).toEqual(['master']);
});
});
@ -606,7 +605,7 @@ describe('VCS', () => {
await v.fork('new-branch');
await v.checkout([], 'new-branch');
const history = await v.getHistory();
expect(await v.getBranch()).toBe('new-branch');
expect(await v.getCurrentBranchName()).toBe('new-branch');
expect(history).toEqual([
{
created: expect.any(Date),
@ -717,7 +716,7 @@ describe('VCS', () => {
it('does something', async () => {
const v = await vcs('master');
// Add a file to master
expect(await v.getBranch()).toBe('master');
expect(await v.getCurrentBranchName()).toBe('master');
const status1 = await v.status(
[
{
@ -750,7 +749,7 @@ describe('VCS', () => {
// Checkout new branch and add file
await v.fork('new-branch');
await v.checkout([], 'new-branch');
expect(await v.getBranch()).toBe('new-branch');
expect(await v.getCurrentBranchName()).toBe('new-branch');
const status2 = await v.status(
[
{
@ -802,7 +801,7 @@ describe('VCS', () => {
]);
// Merge new branch back into master
await v.checkout([], 'master');
expect(await v.getBranch()).toBe('master');
expect(await v.getCurrentBranchName()).toBe('master');
await v.merge([], 'new-branch');
expect(await v.getHistory()).toEqual([
{
@ -959,9 +958,9 @@ describe('VCS', () => {
const driver = new MemoryDriver();
vcs = new VCS(driver);
driver.setItem(paths.projects(), Buffer.from(JSON.stringify([backendProject])));
driver.setItem(paths.projectBase(backendProject.id), Buffer.from(''));
driver.setItem(paths.project(backendProject.id), Buffer.from(JSON.stringify(backendProject)));
driver.setItem('/projects/', Buffer.from(JSON.stringify([backendProject])));
driver.setItem(`/projects/${backendProject.id}/`, Buffer.from(''));
driver.setItem(`/projects/${backendProject.id}/meta.json`, Buffer.from(JSON.stringify(backendProject)));
});
it('should return true if has project', async () => {

View File

@ -1,41 +0,0 @@
export function projects() {
return '/projects/';
}
export function projectBase(projectId: string) {
return `${projects()}${projectId}/`;
}
export function head(projectId: string) {
return `${projectBase(projectId)}head.json`;
}
export function project(projectId: string) {
return `${projectBase(projectId)}meta.json`;
}
export function blobs(projectId: string) {
return `${projectBase(projectId)}blobs/`;
}
export function blob(projectId: string, blobId: string) {
const subPath = `${blobId.slice(0, 2)}/${blobId.slice(2)}`;
return `${blobs(projectId)}${subPath}`;
}
export function snapshots(projectId: string) {
return `${projectBase(projectId)}snapshots/`;
}
export function snapshot(projectId: string, snapshotId: string) {
return `${snapshots(projectId)}${snapshotId}.json`;
}
export function branches(projectId: string) {
return `${projectBase(projectId)}branches/`;
}
export function branch(projectId: string, branchName: string) {
return `${branches(projectId)}${branchName}.json`;
}

View File

@ -19,7 +19,7 @@ export const pullBackendProject = async ({ vcs, backendProject, remoteProject }:
await vcs.checkout([], DEFAULT_BRANCH_NAME);
const remoteBranches = await interceptAccessError({
action: 'pull',
callback: () => vcs.getRemoteBranches(),
callback: () => vcs.getRemoteBranchNames(),
resourceName: backendProject.name,
});

View File

@ -8,7 +8,6 @@ import path from 'path';
import * as crypt from '../../account/crypt';
import * as session from '../../account/session';
import { generateId } from '../../common/misc';
import { strings } from '../../common/strings';
import { BaseModel } from '../../models';
import { insomniaFetch } from '../../ui/insomniaFetch';
import Store from '../store';
@ -25,10 +24,8 @@ import type {
Stage,
StageEntry,
StatusCandidate,
Team,
} from '../types';
import { BackendProjectWithTeams, normalizeBackendProjectTeam } from './normalize-backend-project-team';
import * as paths from './paths';
import { BackendProjectWithTeams } from './normalize-backend-project-team';
import {
compareBranches,
generateCandidateMap,
@ -106,9 +103,19 @@ export class VCS {
async archiveProject() {
const backendProjectId = this._backendProjectId();
await this._queryProjectArchive(backendProjectId);
await this._store.removeItem(paths.project(backendProjectId));
await this._runGraphQL(
`
mutation ($id: ID!) {
projectArchive(id: $id)
}
`,
{
id: backendProjectId,
},
'projectArchive',
);
console.log(`[sync] Archived remote project ${backendProjectId}`);
await this._store.removeItem(`/projects/${backendProjectId}/meta.json`);
this._backendProject = null;
}
@ -131,20 +138,12 @@ export class VCS {
await this.setBackendProject(project);
}
async backendProjectTeams() {
return this._queryBackendProjectTeams();
}
async localBackendProjects() {
return this._allBackendProjects();
}
async remoteBackendProjects({ teamId, teamProjectId }: { teamId: string; teamProjectId: string }) {
return this._queryBackendProjects(teamId, teamProjectId);
}
async remoteBackendProjectsInAnyTeam() {
const { projects } = await this._runGraphQL(
const { projects } = await this._runGraphQL<{ projects: BackendProjectWithTeams[] }>(
`
query ($teamId: ID, $teamProjectId: ID) {
projects(teamId: $teamId, teamProjectId: $teamProjectId) {
@ -159,13 +158,19 @@ export class VCS {
}
`,
{
teamId: '',
teamProjectId: '',
teamId,
teamProjectId,
},
'projects',
);
return (projects as BackendProjectWithTeams[]).map(normalizeBackendProjectTeam);
return projects.map(backend => ({
id: backend.id,
name: backend.name,
rootDocumentId: backend.rootDocumentId,
// A backend project is guaranteed to exist on exactly one team
team: backend.teams[0],
}));
}
async blobFromLastSnapshot(key: string) {
@ -457,8 +462,8 @@ export class VCS {
};
}
async getHistoryCount(branchName?: string) {
const branch = branchName ? await this._getBranch(branchName) : await this._getCurrentBranch();
async getHistoryCount() {
const branch = await this._getCurrentBranch();
return branch?.snapshots.length || 0;
}
@ -481,17 +486,29 @@ export class VCS {
return snapshots;
}
async getBranch() {
async getCurrentBranchName() {
const branch = await this._getCurrentBranch();
return branch.name;
}
async getRemoteBranches(): Promise<string[]> {
const branches = await this._queryBranches();
return branches.map(b => b.name);
async getRemoteBranchNames(): Promise<string[]> {
const { branches } = await this._runGraphQL<{ branches: { name: string }[] | null }>(
`
query ($projectId: ID!) {
branches(project: $projectId) {
name
}
}`,
{
projectId: this._backendProjectId(),
},
'branches',
);
// TODO: Fix server returning null instead of empty list
return (branches || []).map(b => b.name);
}
async getBranches(): Promise<string[]> {
async getBranchNames(): Promise<string[]> {
const branches = await this._getBranches();
return branches.map(b => b.name);
}
@ -808,14 +825,14 @@ export class VCS {
return snapshot;
}
async _runGraphQL(
async _runGraphQL<T>(
query: string,
variables: Record<string, any>,
name: string,
): Promise<Record<string, any>> {
): Promise<T> {
const { sessionId } = await this._assertSession();
const { data, errors } = await insomniaFetch<{ data: {}; errors: [{ message: string }] }>({
const { data, errors } = await insomniaFetch<{ data: T; errors: [{ message: string }] }>({
method: 'POST',
path: '/graphql?' + name,
data: { query, variables },
@ -831,7 +848,7 @@ export class VCS {
}
async _queryBlobsMissing(ids: string[]): Promise<string[]> {
const { blobsMissing } = await this._runGraphQL(
const { blobsMissing } = await this._runGraphQL<{ blobsMissing: { missing: string[] } }>(
`
query ($projectId: ID!, $ids: [ID!]!) {
blobsMissing(project: $projectId, ids: $ids) {
@ -848,26 +865,6 @@ export class VCS {
return blobsMissing.missing;
}
async _queryBranches(): Promise<Branch[]> {
const { branches } = await this._runGraphQL(
`
query ($projectId: ID!) {
branches(project: $projectId) {
created
modified
name
snapshots
}
}`,
{
projectId: this._backendProjectId(),
},
'branches',
);
// TODO: Fix server returning null instead of empty list
return branches || [];
}
async _queryRemoveBranch(branchName: string) {
await this._runGraphQL(
`
@ -883,7 +880,7 @@ export class VCS {
}
async _queryBranch(branchName: string): Promise<Branch | null> {
const { branch } = await this._runGraphQL(
const { branch } = await this._runGraphQL<{ branch: Branch | null }>(
`
query ($projectId: ID!, $branch: String!) {
branch(project: $projectId, name: $branch) {
@ -906,7 +903,7 @@ export class VCS {
let allSnapshots: Snapshot[] = [];
for (const ids of chunkArray(allIds, 20)) {
const { snapshots } = await this._runGraphQL(
const { snapshots } = await this._runGraphQL<{ snapshots: Snapshot[] }>(
`
query ($ids: [ID!]!, $projectId: ID!) {
snapshots(ids: $ids, project: $projectId) {
@ -953,7 +950,7 @@ export class VCS {
}
const branch = await this._getCurrentBranch();
const { snapshotsCreate } = await this._runGraphQL(
const { snapshotsCreate } = await this._runGraphQL<{ snapshotsCreate: Snapshot[] }>(
`
mutation ($projectId: ID!, $snapshots: [SnapshotInput!]!, $branchName: String!) {
snapshotsCreate(project: $projectId, snapshots: $snapshots, branch: $branchName) {
@ -1002,7 +999,7 @@ export class VCS {
const result: Record<string, Buffer> = {};
for (const ids of chunkArray(allIds, 50)) {
const { blobs } = await this._runGraphQL(
const { blobs } = await this._runGraphQL<{ blobs: { id: string; content: string }[] }>(
`
query ($ids: [ID!]!, $projectId: ID!) {
blobs(ids: $ids, project: $projectId) {
@ -1039,7 +1036,7 @@ export class VCS {
id: i.id,
content: i.content,
}));
const { blobsCreate } = await this._runGraphQL(
const { blobsCreate } = await this._runGraphQL<{ blobsCreate: { count: number } }>(
`
mutation ($projectId: ID!, $blobs: [BlobInput!]!) {
blobsCreate(project: $projectId, blobs: $blobs) {
@ -1093,7 +1090,7 @@ export class VCS {
}
async _queryBackendProjectKey() {
const { projectKey } = await this._runGraphQL(
const { projectKey } = await this._runGraphQL<{ projectKey: { encSymmetricKey: string } }>(
`
query ($projectId: ID!) {
projectKey(projectId: $projectId) {
@ -1109,33 +1106,8 @@ export class VCS {
return projectKey.encSymmetricKey as string;
}
async _queryBackendProjects(teamId: string, teamProjectId: string) {
const { projects } = await this._runGraphQL(
`
query ($teamId: ID, $teamProjectId: ID) {
projects(teamId: $teamId, teamProjectId: $teamProjectId) {
id
name
rootDocumentId
teams {
id
name
}
}
}
`,
{
teamId,
teamProjectId,
},
'projects',
);
return (projects as BackendProjectWithTeams[]).map(normalizeBackendProjectTeam);
}
async _queryProject(): Promise<BackendProject | null> {
const { project } = await this._runGraphQL(
const { project } = await this._runGraphQL<{ project: BackendProject | null }>(
`
query ($id: ID!) {
project(id: $id) {
@ -1153,31 +1125,6 @@ export class VCS {
return project;
}
async _queryBackendProjectTeams(): Promise<Team[]> {
const { project } = await this._runGraphQL(
`
query ($id: ID!) {
project(id: $id) {
teams {
id
name
}
}
}
`,
{
id: this._backendProjectId(),
},
'project.teams',
);
if (!project) {
throw new Error(`Please push the ${strings.collection.singular.toLowerCase()} to be able to share it`);
}
return project.teams;
}
async _queryTeamMemberKeys(
teamId: string,
): Promise<{
@ -1191,7 +1138,15 @@ export class VCS {
teamId,
});
const { teamMemberKeys } = await this._runGraphQL(
const { teamMemberKeys } = await this._runGraphQL<{
teamMemberKeys: {
memberKeys: {
accountId: string;
publicKey: string;
autoLinked: boolean;
}[];
};
}>(
`
query ($teamId: ID!) {
teamMemberKeys(teamId: $teamId) {
@ -1241,7 +1196,7 @@ export class VCS {
});
}
const { projectCreate } = await this._runGraphQL(
const { projectCreate } = await this._runGraphQL<{ projectCreate: BackendProject }>(
`
mutation (
$name: String!,
@ -1282,11 +1237,11 @@ export class VCS {
async _getBackendProject(): Promise<BackendProject | null> {
const projectId = this._backendProject ? this._backendProject.id : 'n/a';
return this._store.getItem(paths.project(projectId));
return this._store.getItem(`/projects/${projectId}/meta.json`);
}
async _getBackendProjectById(id: string): Promise<BackendProject | null> {
return this._store.getItem(paths.project(id));
async _getBackendProjectById(projectId: string): Promise<BackendProject | null> {
return this._store.getItem(`/projects/${projectId}/meta.json`);
}
async _getBackendProjectSymmetricKey() {
@ -1308,11 +1263,11 @@ export class VCS {
}
async _storeBackendProject(project: BackendProject) {
return this._store.setItem(paths.project(project.id), project);
return this._store.setItem(`/projects/${project.id}/meta.json`, project);
}
async _getHead(): Promise<Head> {
const head = await this._store.getItem(paths.head(this._backendProjectId()));
const head = await this._store.getItem(`/projects/${this._backendProjectId()}/head.json`);
if (head === null) {
await this._storeHead({ branch: 'master' });
@ -1360,11 +1315,8 @@ export class VCS {
return this._backendProject.id;
}
async _getBranch(name: string, backendProjectId?: string): Promise<Branch | null> {
const pId = backendProjectId || this._backendProjectId();
const p = paths.branch(pId, name);
return this._store.getItem(p);
async _getBranch(name: string): Promise<Branch | null> {
return this._store.getItem(`/projects/${this._backendProjectId()}/branches/${name}.json`);
}
async _getBranches(backendProjectId?: string) {
@ -1372,7 +1324,7 @@ export class VCS {
const pId = backendProjectId || this._backendProjectId();
for (const p of await this._store.keys(paths.branches(pId))) {
for (const p of await this._store.keys(`/projects/${pId}/branches/`)) {
const b = await this._store.getItem(p);
if (b === null) {
@ -1461,8 +1413,7 @@ export class VCS {
async _allBackendProjects() {
const backendProjects: BackendProject[] = [];
const basePath = paths.projects();
const keys = await this._store.keys(basePath, false);
const keys = await this._store.keys('/projects/', false);
for (const key of keys) {
const id = path.basename(key);
@ -1480,7 +1431,7 @@ export class VCS {
}
async _assertSnapshot(id: string) {
const snapshot: Snapshot = await this._store.getItem(paths.snapshot(this._backendProjectId(), id));
const snapshot: Snapshot = await this._store.getItem(`/projects/${this._backendProjectId()}/snapshots/${id}.json`);
if (snapshot && typeof snapshot.created === 'string') {
snapshot.created = new Date(snapshot.created);
@ -1494,7 +1445,7 @@ export class VCS {
}
async _getSnapshot(id: string) {
const snapshot: Snapshot = await this._store.getItem(paths.snapshot(this._backendProjectId(), id));
const snapshot: Snapshot = await this._store.getItem(`/projects/${this._backendProjectId()}/snapshots/${id}.json`);
if (snapshot && typeof snapshot.created === 'string') {
snapshot.created = new Date(snapshot.created);
@ -1511,14 +1462,14 @@ export class VCS {
}
async _storeSnapshot(snapshot: Snapshot) {
return this._store.setItem(paths.snapshot(this._backendProjectId(), snapshot.id), snapshot);
return this._store.setItem(`/projects/${this._backendProjectId()}/snapshots/${snapshot.id}.json`, snapshot);
}
async _storeSnapshots(snapshots: Snapshot[]) {
const promises: Promise<Snapshot>[] = [];
for (const snapshot of snapshots) {
const p = paths.snapshot(this._backendProjectId(), snapshot.id);
const p = `/projects/${this._backendProjectId()}/snapshots/${snapshot.id}.json`;
const promise = this._store.setItem(p, snapshot);
// @ts-expect-error -- TSCONVERSION appears to be a genuine error
promises.push(promise);
@ -1535,25 +1486,24 @@ export class VCS {
}
branch.modified = new Date();
return this._store.setItem(paths.branch(this._backendProjectId(), branch.name.toLowerCase()), branch);
return this._store.setItem(`/projects/${this._backendProjectId()}/branches/${branch.name.toLowerCase()}.json`, branch);
}
async _removeBranch(branch: Branch) {
return this._store.removeItem(paths.branch(this._backendProjectId(), branch.name));
return this._store.removeItem(`/projects/${this._backendProjectId()}/branches/${branch.name}.json`);
}
async _removeProject(project: BackendProject) {
console.log(`[sync] Remove local project ${project.id}`);
return this._store.removeItem(paths.project(project.id));
return this._store.removeItem(`/projects/${project.id}/meta.json`);
}
async _storeHead(head: Head) {
await this._store.setItem(paths.head(this._backendProjectId()), head);
await this._store.setItem(`/projects/${this._backendProjectId()}/head.json`, head);
}
_getBlob(id: string) {
const p = paths.blob(this._backendProjectId(), id);
return this._store.getItem(p) as Promise<BaseModel | null>;
_getBlob(blobId: string) {
return this._store.getItem(`/projects/${this._backendProjectId()}/blobs/${blobId.slice(0, 2)}/${blobId.slice(2)}`) as Promise<BaseModel | null>;
}
async _getBlobs(ids: string[]) {
@ -1566,53 +1516,37 @@ export class VCS {
return Promise.all(promises);
}
async _storeBlob(id: string, content: Record<string, any> | null) {
return this._store.setItem(paths.blob(this._backendProjectId(), id), content);
async _storeBlob(blobId: string, content: Record<string, any> | null) {
return this._store.setItem(`/projects/${this._backendProjectId()}/blobs/${blobId.slice(0, 2)}/${blobId.slice(2)}`, content);
}
async _storeBlobs(map: Record<string, string>) {
async _storeBlobs(blobsToStore: Record<string, string>) {
const promises: Promise<any>[] = [];
for (const id of Object.keys(map)) {
const buff = Buffer.from(map[id], 'utf8');
promises.push(this._storeBlob(id, buff));
for (const blobId of Object.keys(blobsToStore)) {
const buff = Buffer.from(blobsToStore[blobId], 'utf8');
promises.push(this._store.setItem(`/projects/${this._backendProjectId()}/blobs/${blobId.slice(0, 2)}/${blobId.slice(2)}`, buff));
}
await Promise.all(promises);
}
async _storeBlobsBuffer(map: Record<string, Buffer>) {
async _storeBlobsBuffer(decryptedBlobs: Record<string, Buffer>) {
const promises: Promise<any>[] = [];
for (const id of Object.keys(map)) {
const p = paths.blob(this._backendProjectId(), id);
promises.push(this._store.setItemRaw(p, map[id]));
for (const blobId of Object.keys(decryptedBlobs)) {
promises.push(this._store.setItemRaw(`/projects/${this._backendProjectId()}/blobs/${blobId.slice(0, 2)}/${blobId.slice(2)}`, decryptedBlobs[blobId]));
}
await Promise.all(promises);
}
async _getBlobRaw(id: string) {
return this._store.getItemRaw(paths.blob(this._backendProjectId(), id));
async _getBlobRaw(blobId: string) {
return this._store.getItemRaw(`/projects/${this._backendProjectId()}/blobs/${blobId.slice(0, 2)}/${blobId.slice(2)}`);
}
async _hasBlob(id: string) {
return this._store.hasItem(paths.blob(this._backendProjectId(), id));
}
async _queryProjectArchive(projectId: string) {
await this._runGraphQL(
`
mutation ($id: ID!) {
projectArchive(id: $id)
}
`,
{
id: projectId,
},
'projectArchive',
);
console.log(`[sync] Archived remote project ${projectId}`);
async _hasBlob(blobId: string) {
return this._store.hasItem(`/projects/${this._backendProjectId()}/blobs/${blobId.slice(0, 2)}/${blobId.slice(2)}`);
}
}

View File

@ -74,7 +74,7 @@ export const gitRepoLoader: ActionFunction = async ({
if (GitVCS.isInitializedForRepo(gitRepository._id)) {
return {
branch: await GitVCS.getBranch(),
branch: await GitVCS.getCurrentBranch(),
branches: await GitVCS.listBranches(),
gitRepository: gitRepository,
};
@ -132,7 +132,7 @@ export const gitRepoLoader: ActionFunction = async ({
await GitVCS.addRemote(gitUri);
return {
branch: await GitVCS.getBranch(),
branch: await GitVCS.getCurrentBranch(),
branches: await GitVCS.listBranches(),
gitRepository: gitRepository,
};
@ -299,7 +299,7 @@ export const gitChangesLoader: LoaderFunction = async ({
invariant(gitRepository, 'Git Repository not found');
const branch = await GitVCS.getBranch();
const branch = await GitVCS.getCurrentBranch();
try {
const { changes, statusNames } = await getGitChanges(GitVCS, workspace);

View File

@ -262,7 +262,7 @@ export const syncDataAction: ActionFunction = async ({ params }) => {
invariant(project, 'Project not found');
invariant(project.remoteId, 'Project is not remote');
const vcs = VCSInstance();
const remoteBranches = (await vcs.getRemoteBranches()).sort();
const remoteBranches = (await vcs.getRemoteBranchNames()).sort();
const compare = await vcs.compareRemoteBranch();
const remoteBackendProjects = await vcs.remoteBackendProjects({
teamId: project.parentId,
@ -310,11 +310,11 @@ export const syncDataLoader: LoaderFunction = async ({
invariant(project.remoteId, 'Project is not remote');
const vcs = VCSInstance();
const { syncItems } = await getSyncItems({ workspaceId });
const localBranches = (await vcs.getBranches()).sort();
const localBranches = (await vcs.getBranchNames()).sort();
const remoteBranches = (
remoteBranchesCache[workspaceId] || (await vcs.getRemoteBranches())
remoteBranchesCache[workspaceId] || (await vcs.getRemoteBranchNames())
).sort();
const currentBranch = await vcs.getBranch();
const currentBranch = await vcs.getCurrentBranchName();
const history = (await vcs.getHistory()).sort((a, b) =>
b.created > a.created ? 1 : -1
);
@ -525,7 +525,7 @@ export const fetchRemoteBranchAction: ActionFunction = async ({
const branch = formData.get('branch');
invariant(typeof branch === 'string', 'Branch is required');
const vcs = VCSInstance();
const currentBranch = await vcs.getBranch();
const currentBranch = await vcs.getCurrentBranchName();
try {
invariant(project.remoteId, 'Project is not remote');