-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkspace-local-helpers.js
More file actions
77 lines (70 loc) · 2.68 KB
/
Copy pathworkspace-local-helpers.js
File metadata and controls
77 lines (70 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const createWorkspaceContextSnapshotGetter =
({
getCurrentSelectedRepository,
githubPrBaseBranch,
githubPrHeadBranch,
githubPrTitle,
getActivePrContext,
getPrContextState,
getPrNumber,
getWorkspaceScopeMarker,
getActiveWorkspacePersistedPrTitle,
}) =>
() => {
const toSafeText = value => (typeof value === 'string' ? value.trim() : '')
const activePrContext =
typeof getActivePrContext === 'function' ? getActivePrContext() : null
const prContextState =
typeof getPrContextState === 'function' ? getPrContextState() : 'inactive'
const isActivePrContext = toSafeText(prContextState).toLowerCase() === 'active'
const activePrNumber =
typeof activePrContext?.pullRequestNumber === 'number' &&
Number.isFinite(activePrContext.pullRequestNumber)
? activePrContext.pullRequestNumber
: null
const nextPrNumber = typeof getPrNumber === 'function' ? getPrNumber() : null
const persistedPrNumber =
Number.isFinite(nextPrNumber) && Number(nextPrNumber) > 0
? Number(nextPrNumber)
: null
const prNumber = activePrNumber ?? persistedPrNumber
const contextBaseBranch = toSafeText(activePrContext?.baseBranch)
const contextHeadBranch = toSafeText(activePrContext?.headBranch)
const contextPrTitle = toSafeText(activePrContext?.prTitle)
const formBaseBranch = toSafeText(githubPrBaseBranch?.value)
const formHeadBranch = toSafeText(githubPrHeadBranch?.value)
const formPrTitle = toSafeText(githubPrTitle?.value)
const normalizedWorkspaceScope = toSafeText(getWorkspaceScopeMarker?.()).toLowerCase()
const isLocalScope = normalizedWorkspaceScope !== 'repository'
const persistedPrTitle = toSafeText(getActiveWorkspacePersistedPrTitle?.())
const nextPrTitle =
isActivePrContext && contextPrTitle
? contextPrTitle
: isLocalScope && !formPrTitle && persistedPrTitle
? persistedPrTitle
: formPrTitle
return {
repositoryFullName: getCurrentSelectedRepository(),
baseBranch:
isActivePrContext && contextBaseBranch ? contextBaseBranch : formBaseBranch,
headBranch:
isActivePrContext && contextHeadBranch ? contextHeadBranch : formHeadBranch,
prTitle: nextPrTitle,
prNumber,
prContextState,
}
}
const toStyleModeForTabLanguage = ({ language, toNonEmptyWorkspaceText }) => {
const normalized = toNonEmptyWorkspaceText(language)
if (normalized === 'less') {
return 'less'
}
if (normalized === 'sass') {
return 'sass'
}
if (normalized === 'module') {
return 'module'
}
return 'css'
}
export { createWorkspaceContextSnapshotGetter, toStyleModeForTabLanguage }