-
-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move skip and enable cheks of listr tasks to separate file
- Loading branch information
Showing
7 changed files
with
147 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
'use strict' | ||
|
||
const { GIT_ERROR, TASK_ERROR } = require('./messages') | ||
const { | ||
ApplyEmptyCommitError, | ||
TaskError, | ||
RestoreOriginalStateError, | ||
GitError, | ||
RestoreUnstagedChangesError | ||
} = require('./symbols') | ||
|
||
const hasPartiallyStagedFiles = (ctx) => ctx.hasPartiallyStagedFiles | ||
|
||
const applyModificationsSkipped = (ctx) => { | ||
// Always apply back unstaged modifications when skipping backup | ||
if (!ctx.shouldBackup) return false | ||
// Should be skipped in case of git errors | ||
if (ctx.errors.has(GitError)) { | ||
return GIT_ERROR | ||
} | ||
// Should be skipped when tasks fail | ||
if (ctx.errors.has(TaskError)) { | ||
return TASK_ERROR | ||
} | ||
} | ||
|
||
const restoreUnstagedChangesSkipped = (ctx) => { | ||
// Should be skipped in case of git errors | ||
if (ctx.errors.has(GitError)) { | ||
return GIT_ERROR | ||
} | ||
// Should be skipped when tasks fail | ||
if (ctx.errors.has(TaskError)) { | ||
return TASK_ERROR | ||
} | ||
} | ||
|
||
const restoreOriginalStateEnabled = (ctx) => | ||
ctx.shouldBackup && | ||
(ctx.errors.has(TaskError) || | ||
ctx.errors.has(ApplyEmptyCommitError) || | ||
ctx.errors.has(RestoreUnstagedChangesError)) | ||
|
||
const restoreOriginalStateSkipped = (ctx) => { | ||
// Should be skipped in case of unknown git errors | ||
if ( | ||
ctx.errors.has(GitError) && | ||
!ctx.errors.has(ApplyEmptyCommitError) && | ||
!ctx.errors.has(RestoreUnstagedChangesError) | ||
) { | ||
return GIT_ERROR | ||
} | ||
} | ||
|
||
const cleanupSkipped = (ctx) => { | ||
// Should be skipped in case of unknown git errors | ||
if ( | ||
ctx.errors.has(GitError) && | ||
!ctx.errors.has(ApplyEmptyCommitError) && | ||
!ctx.errors.has(RestoreUnstagedChangesError) | ||
) { | ||
return GIT_ERROR | ||
} | ||
// Should be skipped when reverting to original state fails | ||
if (ctx.errors.has(RestoreOriginalStateError)) { | ||
return GIT_ERROR | ||
} | ||
} | ||
|
||
module.exports = { | ||
hasPartiallyStagedFiles, | ||
applyModificationsSkipped, | ||
restoreUnstagedChangesSkipped, | ||
restoreOriginalStateEnabled, | ||
restoreOriginalStateSkipped, | ||
cleanupSkipped | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { | ||
applyModificationsSkipped, | ||
cleanupSkipped, | ||
restoreOriginalStateSkipped, | ||
restoreUnstagedChangesSkipped | ||
} from '../lib/state' | ||
import { GitError, RestoreOriginalStateError } from '../lib/symbols' | ||
|
||
describe('applyModificationsSkipped', () => { | ||
it('should return false when backup is disabled', () => { | ||
const result = applyModificationsSkipped({ shouldBackup: false }) | ||
expect(result).toEqual(false) | ||
}) | ||
|
||
it('should return error message when there is an unkown git error', () => { | ||
const result = applyModificationsSkipped({ shouldBackup: true, errors: new Set([GitError]) }) | ||
expect(typeof result === 'string').toEqual(true) | ||
}) | ||
}) | ||
|
||
describe('restoreUnstagedChangesSkipped', () => { | ||
it('should return error message when there is an unkown git error', () => { | ||
const result = restoreUnstagedChangesSkipped({ errors: new Set([GitError]) }) | ||
expect(typeof result === 'string').toEqual(true) | ||
}) | ||
}) | ||
|
||
describe('restoreOriginalStateSkipped', () => { | ||
it('should return error message when there is an unkown git error', () => { | ||
const result = restoreOriginalStateSkipped({ errors: new Set([GitError]) }) | ||
expect(typeof result === 'string').toEqual(true) | ||
}) | ||
}) | ||
|
||
describe('shouldSkipCleanup', () => { | ||
it('should return error message when reverting to original state fails', () => { | ||
const result = cleanupSkipped({ errors: new Set([RestoreOriginalStateError]) }) | ||
expect(typeof result === 'string').toEqual(true) | ||
}) | ||
}) |