Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
chore: support all job kinds from the streamed cases
Browse files Browse the repository at this point in the history
  • Loading branch information
grzpab committed Dec 16, 2023
1 parent 6e4e992 commit d90e4ec
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "intuita-vscode-extension",
"displayName": "Intuita",
"description": " Discover, run & manage codemods faster & easier.",
"version": "0.38.2",
"version": "0.38.3",
"publisher": "Intuita",
"icon": "img/intuita_square128.png",
"repository": {
Expand Down
86 changes: 69 additions & 17 deletions src/data/readHomeDirectoryCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,66 @@ interface HomeDirectoryEventEmitter extends EventEmitter {
): this;
}

const buildPartialJob = (
surfaceAgnosticJob: SurfaceAgnosticJob,
): Pick<Job, 'kind' | 'oldUri' | 'newContentUri' | 'newUri'> => {
if (surfaceAgnosticJob.kind === JOB_KIND.CREATE_FILE) {
return {
kind: JobKind.createFile,
oldUri: null,
newContentUri: Uri.file(surfaceAgnosticJob.dataUri),
newUri: Uri.file(surfaceAgnosticJob.pathUri),
};
}

if (surfaceAgnosticJob.kind === JOB_KIND.UPDATE_FILE) {
return {
kind: JobKind.rewriteFile,
oldUri: Uri.file(surfaceAgnosticJob.pathUri),
newContentUri: Uri.file(surfaceAgnosticJob.newDataUri),
newUri: null,
};
}

if (surfaceAgnosticJob.kind === JOB_KIND.MOVE_FILE) {
return {
kind: JobKind.moveFile,
oldUri: Uri.file(surfaceAgnosticJob.oldPathUri),
newContentUri: null,
newUri: Uri.file(surfaceAgnosticJob.newPathUri),
};
}

if (surfaceAgnosticJob.kind === JOB_KIND.MOVE_AND_UPDATE_FILE) {
return {
kind: JobKind.moveFile,
oldUri: Uri.file(surfaceAgnosticJob.oldPathUri),
newContentUri: Uri.file(surfaceAgnosticJob.newDataUri),
newUri: Uri.file(surfaceAgnosticJob.newPathUri),
};
}

if (surfaceAgnosticJob.kind === JOB_KIND.DELETE_FILE) {
return {
kind: JobKind.deleteFile,
oldUri: Uri.file(surfaceAgnosticJob.pathUri),
newContentUri: null,
newUri: null,
};
}

if (surfaceAgnosticJob.kind === JOB_KIND.COPY_FILE) {
return {
kind: JobKind.deleteFile,
oldUri: Uri.file(surfaceAgnosticJob.sourcePathUri),
newContentUri: null,
newUri: Uri.file(surfaceAgnosticJob.targetPathUri),
};
}

throw new Error('Unsupported surface agnostic job');
};

const readHomeDirectoryCase = async (
homeDirectoryEventEmitter: HomeDirectoryEventEmitter,
rootUri: Uri,
Expand Down Expand Up @@ -81,24 +141,16 @@ const readHomeDirectoryCase = async (
return;
}

if (surfaceAgnosticJob.kind === JOB_KIND.UPDATE_FILE) {
const job: Job = {
hash: surfaceAgnosticJob.jobHashDigest,
originalNewContent: null,
codemodName: kase.codemodName,
createdAt: kase.createdAt,
caseHashDigest: kase.hash,
// variant
kind: JobKind.rewriteFile,
oldUri: Uri.file(surfaceAgnosticJob.pathUri),
newContentUri: Uri.file(surfaceAgnosticJob.newDataUri),
newUri: null,
};

homeDirectoryEventEmitter.emit('job', kase, [job]);
}
const job: Job = {
hash: surfaceAgnosticJob.jobHashDigest,
originalNewContent: null,
codemodName: kase.codemodName,
createdAt: kase.createdAt,
caseHashDigest: kase.hash,
...buildPartialJob(surfaceAgnosticJob),
};

// TODO implement more job kinds
homeDirectoryEventEmitter.emit('job', kase, [job]);
};

caseReadingService.on('job', jobHandler);
Expand Down

0 comments on commit d90e4ec

Please sign in to comment.