Skip to content

Commit 5cbbf3c

Browse files
committed
sync-upstream-branches: adopt a more functional style
This still does the exact same thing, but avoids storing intermediate states of the `data` array's transformation. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 5eb6540 commit 5cbbf3c

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

.github/workflows/sync-upstream-branches.yml

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,22 @@ jobs:
4444
for (;;) {
4545
try {
4646
const [owner, repo] = repository.split('/')
47-
let { data } = await github.rest.git.listMatchingRefs({
48-
owner,
49-
repo,
50-
ref: 'heads/'
51-
})
52-
53-
data = data.filter(e => {
54-
if (!e.ref.startsWith('refs/heads/')) return false
55-
e.name = e.ref.slice(11)
56-
return true
57-
})
58-
59-
if (stripRefsPrefix) {
60-
data = data.filter(e => {
61-
if (!e.name.startsWith(stripRefsPrefix)) return false
62-
e.name = e.name.slice(stripRefsPrefix.length)
47+
return (
48+
await github.rest.git.listMatchingRefs({
49+
owner,
50+
repo,
51+
ref: 'heads/'
52+
})
53+
).data
54+
.filter((e) => {
55+
if (!e.ref.startsWith('refs/heads/')) return false
56+
e.name = e.ref.slice(11)
57+
if (stripRefsPrefix) {
58+
if (!e.name.startsWith(stripRefsPrefix)) return false
59+
e.name = e.name.slice(stripRefsPrefix.length)
60+
}
6361
return true
6462
})
65-
}
66-
67-
return data
6863
.sort((a, b) => a.ref.localeCompare(b.ref))
6964
} catch (e) {
7065
if (e?.status !== 502) throw e

0 commit comments

Comments
 (0)