Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
srvpro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
srvpro
Commits
36c9d9aa
Commit
36c9d9aa
authored
Mar 12, 2018
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hook test
parent
0ad43f9b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
195 additions
and
0 deletions
+195
-0
data/default_config.json
data/default_config.json
+37
-0
ygopro-webhook.js
ygopro-webhook.js
+158
-0
No files found.
data/default_config.json
View file @
36c9d9aa
...
@@ -150,6 +150,43 @@
...
@@ -150,6 +150,43 @@
}
}
]
]
},
},
"webhook"
:
{
"enabled"
:
false
,
"port"
:
7966
,
"password"
:
"123456"
,
"hooks"
:
{
"script"
:
{
"path"
:
"./ygopro/script/"
,
"remote"
:
"origin"
,
"branch"
:
"master"
,
"callback"
:
false
},
"ocgcore"
:
{
"path"
:
"./ygopro/ocgcore/"
,
"remote"
:
"origin"
,
"branch"
:
"master"
,
"callback"
:
{
"command"
:
"make"
,
"args"
:
[
"config=release"
],
"path"
:
"./ygopro/build/"
}
},
"ygopro"
:
{
"path"
:
"./ygopro/"
,
"remote"
:
"origin"
,
"branch"
:
"server"
,
"callback"
:
{
"command"
:
"make"
,
"args"
:
[
"config=release"
],
"path"
:
"./ygopro/build/"
}
}
}
},
"update_util"
:
{
"update_util"
:
{
"enabled"
:
false
,
"enabled"
:
false
,
"port"
:
7955
,
"port"
:
7955
,
...
...
ygopro-webhook.js
0 → 100644
View file @
36c9d9aa
/*
ygopro-webhook.js
ygopro webhook auto update
Author: Nanahira
License: MIT
*/
var
http
=
require
(
'
http
'
);
var
fs
=
require
(
'
fs
'
);
var
execSync
=
require
(
'
child_process
'
).
execSync
;
var
spawn
=
require
(
'
child_process
'
).
spawn
;
var
spawnSync
=
require
(
'
child_process
'
).
spawnSync
;
var
url
=
require
(
'
url
'
);
var
moment
=
require
(
'
moment
'
);
moment
.
locale
(
'
zh-cn
'
);
var
loadJSON
=
require
(
'
load-json-file
'
).
sync
;
var
querystring
=
require
(
'
querystring
'
);
var
constants
=
loadJSON
(
'
./data/constants.json
'
);
var
settings
=
loadJSON
(
'
./config/config.json
'
);
config
=
settings
.
modules
.
webhook
;
var
status
=
{};
var
sendResponse
=
function
(
text
)
{
console
.
log
(
moment
().
format
(
'
YYYY-MM-DD HH:mm:ss
'
)
+
"
-->
"
+
text
);
}
var
pull_data
=
function
(
path
,
remote
,
branch
,
callback
)
{
sendResponse
(
"
Started pulling on branch
"
+
branch
+
"
at
"
+
path
+
"
from
"
+
remote
+
"
.
"
);
var
proc
=
spawn
(
"
git
"
,
[
"
pull
"
,
remote
,
branch
],
{
cwd
:
path
,
env
:
process
.
env
});
proc
.
stdout
.
setEncoding
(
'
utf8
'
);
proc
.
stdout
.
on
(
'
data
'
,
function
(
data
)
{
sendResponse
(
"
git pull stdout:
"
+
data
);
});
proc
.
stderr
.
setEncoding
(
'
utf8
'
);
proc
.
stderr
.
on
(
'
data
'
,
function
(
data
)
{
sendResponse
(
"
git pull stderr:
"
+
data
);
});
proc
.
on
(
'
close
'
,
function
(
code
)
{
sendResponse
(
"
Finished pulling on branch
"
+
branch
+
"
at
"
+
path
+
"
from
"
+
remote
+
"
.
"
);
if
(
callback
)
{
callback
();
}
});
return
proc
;
}
var
run_custom_callback
=
function
(
command
,
args
,
path
,
callback
)
{
sendResponse
(
"
Started running custom callback.
"
);
var
proc
=
spawn
(
command
,
args
,
{
cwd
:
path
,
env
:
process
.
env
});
proc
.
stdout
.
setEncoding
(
'
utf8
'
);
proc
.
stdout
.
on
(
'
data
'
,
function
(
data
)
{
sendResponse
(
"
custom callback stdout:
"
+
data
);
});
proc
.
stderr
.
setEncoding
(
'
utf8
'
);
proc
.
stderr
.
on
(
'
data
'
,
function
(
data
)
{
sendResponse
(
"
custom callback stderr:
"
+
data
);
});
proc
.
on
(
'
close
'
,
function
(
code
)
{
sendResponse
(
"
Finished running custom callback.
"
);
if
(
callback
)
{
callback
();
}
});
return
;
}
var
pull_callback
=
function
(
name
,
info
)
{
if
(
info
.
callback
)
{
run_custom_callback
(
info
.
callback
.
command
,
info
.
callback
.
args
,
info
.
callback
.
path
,
function
()
{
process_callback
(
name
,
info
);
});
}
else
{
process_callback
(
name
,
info
);
}
return
;
}
var
process_callback
=
(
name
,
info
)
{
if
(
status
[
name
]
===
2
)
{
status
[
name
]
=
1
;
sendResponse
(
"
The Process
"
+
name
+
"
was triggered during running. It will be ran again.
"
);
pull_data
(
info
.
path
,
info
.
remote
,
info
.
branch
,
function
()
{
pull_callback
(
info
);
});
}
else
{
status
[
name
]
=
false
;
sendResponse
(
"
Finished process
"
+
name
+
"
.
"
);
}
return
;
}
var
add_process
=
function
(
name
,
info
)
{
if
(
status
[
name
])
{
status
[
name
]
=
2
;
return
"
Another process in repo
"
+
name
+
"
is running. The process will start after this.
"
;
}
status
[
name
]
=
1
;
pull_data
(
info
.
path
,
info
.
remote
,
info
.
branch
,
function
()
{
pull_callback
(
info
);
});
return
"
Started a process in repo
"
+
name
+
"
.
"
;
}
//returns
var
return_error
=
function
(
res
,
msg
)
{
res
.
writeHead
(
403
);
res
.
end
(
msg
);
sendResponse
(
"
Remote error:
"
+
msg
);
return
;
}
var
return_success
=
function
(
res
,
msg
)
{
res
.
writeHead
(
200
);
res
.
end
(
msg
);
sendResponse
(
"
Remote message:
"
+
msg
);
return
;
}
//will create an http server to receive apis
http
.
createServer
(
function
(
req
,
res
)
{
var
u
=
url
.
parse
(
req
.
url
,
true
);
var
data
=
u
.
pathname
.
split
(
"
/
"
);
if
(
data
[
0
]
!==
""
||
data
[
1
]
!==
"
api
"
)
{
return
return_error
(
res
,
"
Invalid format.
"
);
}
if
(
data
[
2
]
!==
config
.
password
)
{
return
return_error
(
res
,
"
Auth Failed.
"
);
}
var
hook
=
data
[
3
];
if
(
!
hook
)
{
return
return_error
(
res
,
"
Invalid format.
"
);
}
var
hook_info
=
hooks
[
hook
];
if
(
!
hook_info
)
{
return
return_error
(
res
,
"
Hooked repo not found.
"
);
}
var
info
=
""
;
req
.
addListener
(
'
data
'
,
function
(
chunk
)
{
info
+=
chunk
;
})
req
.
addListener
(
'
end
'
,
function
()
{
info
=
querystring
.
parse
(
info
);
var
branch
=
info
.
ref
.
split
(
"
/
"
)[
2
];
if
(
!
branch
)
{
return
return_error
(
res
,
"
Invalid branch.
"
);
}
else
if
(
branch
!==
hook_info
.
branch
)
{
return
return_success
(
res
,
"
Branch
"
+
branch
+
"
in repo
"
+
hook
+
"
is not the current branch. Skipped.
"
);
}
else
{
var
return_msg
=
add_process
(
hook
,
hook_info
);
return
return_success
(
res
,
return_msg
);
}
})
return
;
}).
listen
(
config
.
port
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment