zx-bulk-release 2.2.5 → 2.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/package.json +1 -1
- package/src/main/js/git.js +13 -32
- package/src/main/js/util.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
## [2.2.6](https://github.com/semrel-extra/zx-bulk-release/compare/v2.2.5...v2.2.6) (2023-03-24)
|
|
2
|
+
|
|
3
|
+
### Fixes & improvements
|
|
4
|
+
* refactor: apply memoize to git utils ([ff8ff78](https://github.com/semrel-extra/zx-bulk-release/commit/ff8ff7840eb65171b7d69d45cafed944627bfd20))
|
|
5
|
+
|
|
1
6
|
## [2.2.5](https://github.com/semrel-extra/zx-bulk-release/compare/v2.2.4...v2.2.5) (2023-03-24)
|
|
2
7
|
|
|
3
8
|
### Fixes & improvements
|
package/package.json
CHANGED
package/src/main/js/git.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import {$, ctx, fs, path, tempy, copy} from 'zx-extra'
|
|
2
2
|
import {log} from './log.js'
|
|
3
|
-
import {keyByValue} from './util.js'
|
|
4
|
-
|
|
5
|
-
const branches = {}
|
|
6
|
-
export const fetchRepo = async ({cwd: _cwd, branch, origin: _origin, basicAuth}) => ctx(async ($) => {
|
|
7
|
-
const root = await getRoot(_cwd)
|
|
8
|
-
const id = `${root}:${branch}`
|
|
9
|
-
|
|
10
|
-
if (branches[id]) return branches[id]
|
|
3
|
+
import {keyByValue, memoizeBy} from './util.js'
|
|
11
4
|
|
|
5
|
+
export const fetchRepo = memoizeBy(async ({cwd: _cwd, branch, origin: _origin, basicAuth}) => ctx(async ($) => {
|
|
12
6
|
const origin = _origin || (await getRepo(_cwd, {basicAuth})).repoAuthedUrl
|
|
13
7
|
const cwd = tempy.temporaryDirectory()
|
|
14
8
|
$.cwd = cwd
|
|
@@ -19,10 +13,9 @@ export const fetchRepo = async ({cwd: _cwd, branch, origin: _origin, basicAuth})
|
|
|
19
13
|
await $`git init .`
|
|
20
14
|
await $`git remote add origin ${origin}`
|
|
21
15
|
}
|
|
22
|
-
branches[id] = cwd
|
|
23
16
|
|
|
24
|
-
return
|
|
25
|
-
})
|
|
17
|
+
return cwd
|
|
18
|
+
}), async ({cwd, branch}) => `${await getRoot(cwd)}:${branch}`)
|
|
26
19
|
|
|
27
20
|
export const pushCommit = async ({cwd, from, to, branch, origin, msg, ignoreFiles, files = [], basicAuth, gitCommitterEmail, gitCommitterName}) => ctx(async ($) => {
|
|
28
21
|
let retries = 3
|
|
@@ -54,7 +47,6 @@ export const pushCommit = async ({cwd, from, to, branch, origin, msg, ignoreFile
|
|
|
54
47
|
} catch (e) {
|
|
55
48
|
retries -= 1
|
|
56
49
|
log({level: 'error'})('git push failed', 'branch', branch, 'retries left', retries, e)
|
|
57
|
-
branches[keyByValue(branches, _cwd)] = null
|
|
58
50
|
|
|
59
51
|
if (retries === 0) {
|
|
60
52
|
throw e
|
|
@@ -63,11 +55,11 @@ export const pushCommit = async ({cwd, from, to, branch, origin, msg, ignoreFile
|
|
|
63
55
|
}
|
|
64
56
|
})
|
|
65
57
|
|
|
66
|
-
const
|
|
67
|
-
export const getRepo = async (_cwd, {basicAuth} = {}) => {
|
|
68
|
-
const cwd = await getRoot(_cwd)
|
|
69
|
-
if (repos[cwd]) return repos[cwd]
|
|
58
|
+
export const getRoot = async (cwd) => (await $.o({cwd})`git rev-parse --show-toplevel`).toString().trim()
|
|
70
59
|
|
|
60
|
+
export const getSha = async (cwd) => (await $.o({cwd})`git rev-parse HEAD`).toString().trim()
|
|
61
|
+
|
|
62
|
+
export const getRepo = memoizeBy(async (cwd, {basicAuth} = {}) => {
|
|
71
63
|
const originUrl = await getOrigin(cwd)
|
|
72
64
|
const [, , repoHost, repoName] = originUrl.replace(':', '/').replace(/\.git/, '').match(/.+(@|\/\/)([^/]+)\/(.+)$/) || []
|
|
73
65
|
const repoPublicUrl = `https://${repoHost}/${repoName}`
|
|
@@ -75,29 +67,18 @@ export const getRepo = async (_cwd, {basicAuth} = {}) => {
|
|
|
75
67
|
? `https://${basicAuth}@${repoHost}/${repoName}.git`
|
|
76
68
|
: originUrl
|
|
77
69
|
|
|
78
|
-
|
|
70
|
+
return {
|
|
79
71
|
repoName,
|
|
80
72
|
repoHost,
|
|
81
73
|
repoPublicUrl,
|
|
82
74
|
repoAuthedUrl,
|
|
83
75
|
originUrl,
|
|
84
76
|
}
|
|
77
|
+
}, getRoot)
|
|
85
78
|
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const origins = {}
|
|
90
|
-
export const getOrigin = async (cwd) => {
|
|
91
|
-
if (!origins[cwd]) {
|
|
92
|
-
origins[cwd] = $.o({cwd})`git config --get remote.origin.url`.then(r => r.toString().trim())
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return origins[cwd]
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export const getRoot = async (cwd) => (await $.o({cwd})`git rev-parse --show-toplevel`).toString().trim()
|
|
99
|
-
|
|
100
|
-
export const getSha = async (cwd) => (await $.o({cwd})`git rev-parse HEAD`).toString().trim()
|
|
79
|
+
export const getOrigin = memoizeBy(async (cwd) =>
|
|
80
|
+
$.o({cwd})`git config --get remote.origin.url`.then(r => r.toString().trim())
|
|
81
|
+
)
|
|
101
82
|
|
|
102
83
|
export const getCommits = async (cwd, from, to = 'HEAD') => ctx(async ($) => {
|
|
103
84
|
const ref = from ? `${from}..${to}` : to
|
package/src/main/js/util.js
CHANGED
|
@@ -45,8 +45,8 @@ export const getPromise = () => {
|
|
|
45
45
|
|
|
46
46
|
export const keyByValue = (obj, value) => Object.keys(obj).find((key) => obj[key] === value)
|
|
47
47
|
|
|
48
|
-
export const memoizeBy = (fn,
|
|
49
|
-
const key = getKey(...args)
|
|
48
|
+
export const memoizeBy = (fn, getKey = v => v, memo = new Map()) => async (...args) => {
|
|
49
|
+
const key = await getKey(...args)
|
|
50
50
|
if (memo.has(key)) {
|
|
51
51
|
return memo.get(key)
|
|
52
52
|
}
|