FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
frontend/git-hooks/pre-push at master · devhttps/frontend · GitHub
devhttps
/
frontend
Public
forked from
guardian/frontend
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
frontend
/
git-hooks
/
pre-push
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
96 lines (88 loc) · 2.66 KB
Breadcrumbs
frontend
/
git-hooks
/
pre-push
Copy path
File metadata and controls
executable file
·
96 lines (88 loc) · 2.66 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env node
/* eslint-disable no-console */
const
fs
=
require
(
'fs'
)
;
const
{
promisify
}
=
require
(
'util'
)
;
const
path
=
require
(
'path'
)
;
const
execa
=
require
(
'execa'
)
;
const
chalk
=
require
(
'chalk'
)
;
const
getChangedFiles
=
require
(
'../tools/__tasks__/lib/get-changed-files'
)
;
const
writeFile
=
promisify
(
fs
.
writeFile
)
;
const
confirmIfMasterMessage
=
`
${
chalk
.
red
(
`
${
chalk
.
inverse
(
'You are about to push master!'
)
}
\nIs that what you intended?`
)
}
[y/N]`
;
const
confirmIfMaster
=
execa
.
shell
(
`
protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\\(.*\\),\\1,')
if [ $protected_branch = $current_branch ]
then
read -p "
${
confirmIfMasterMessage
}
" -n 1 -r < /dev/tty
echo
if echo $REPLY | grep -E '^[Yy]$' > /dev/null
then
exit 0 # push will execute
fi
exit 1 # push will not execute
else
exit 0 # push will execute
fi
`
,
{
stdio
:
'inherit'
,
}
)
.
catch
(
(
)
=>
Promise
.
reject
(
new
Error
(
'Ok, stopping 😉'
)
)
)
;
const
validate
=
(
)
=>
execa
(
'./tools/task-runner/runner'
,
[
'validate-head/index'
,
'validate/check-for-disallowed-strings'
]
,
{
stdio
:
'inherit'
,
}
)
;
const
checkYarnLock
=
changed
=>
{
if
(
changed
.
some
(
file
=>
file
===
'package.json'
)
&&
!
changed
.
some
(
file
=>
file
===
'yarn.lock'
)
)
{
return
Promise
.
reject
(
new
Error
(
`
${
chalk
.
red
(
`
${
chalk
.
underline
(
'package.json'
)
}
has changed but
${
chalk
.
underline
(
'yarn.lock'
)
}
is not included in this commit.`
)
}
\n
${
chalk
.
dim
(
`If this is intentional, commit this change with --no-verify.`
)
}
`
)
)
;
}
return
changed
;
}
;
// make sure docs TOC stays up to date
const
updateTOC
=
changed
=>
{
if
(
changed
.
some
(
file
=>
file
.
includes
(
'docs/'
)
)
)
{
const
docs
=
path
.
resolve
(
'docs'
)
;
const
readme
=
path
.
resolve
(
docs
,
'README.md'
)
;
return
execa
.
stdout
(
path
.
resolve
(
docs
,
'generate-toc.sh'
)
)
.
then
(
toc
=>
writeFile
(
readme
,
toc
,
'utf8'
)
)
.
then
(
(
)
=>
execa
.
sync
(
'git'
,
[
'add'
,
readme
]
)
)
.
then
(
(
)
=>
changed
)
;
}
return
changed
;
}
;
confirmIfMaster
.
then
(
validate
)
.
then
(
getChangedFiles
)
.
then
(
checkYarnLock
)
.
then
(
updateTOC
)
.
catch
(
e
=>
{
console
.
log
(
`\n
${
e
}
\n`
)
;
process
.
exit
(
1
)
;
}
)
;
Back
|
FazBrowse Home
|
New Git URL