Skip to content

Commit b7e392e

Browse files
committed
wip
1 parent 1f16680 commit b7e392e

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

agent.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports.exec = (program) => {
3636

3737
socket.on('tf.githubCi.pullRequest', (req) => {
3838
if (!agent.authenticated) return
39-
q.push(services.githubCi.push(socket, 'tf.githubCi.pullRequest', req))
39+
q.push(services.githubCi.pullRequest(socket, 'tf.githubCi.pullRequest', req))
4040
})
4141

4242
socket.on('tf.githubCi.push', (req) => {
@@ -49,6 +49,11 @@ module.exports.exec = (program) => {
4949
q.push(services.githubCi.test_cmd(socket, 'tf.githubCi.test_cmd', req))
5050
})
5151

52+
socket.on('tf.githubCi.run_cmd', (req) => {
53+
if (!agent.authenticated) return
54+
q.push(services.githubCi.run_cmd(socket, 'tf.githubCi.run_cmd', req))
55+
})
56+
5257
// Execute command
5358
socket.on('tf.agent.execute', function (req) {
5459
if (!agent.authenticated) return

services/githubCi.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,37 @@ const genTmpFolder = (subfix) => {
1616
return tmpPath
1717
}
1818

19-
const push = (socket, topic, req) => {
20-
console.log({req})
19+
const push = async (socket, topic, req) => {
2120
const triggerService = req.triggerService
2221
const webhook = req.webhook
2322
const repo = webhook.repository.full_name
2423
const tmpPath = genTmpFolder(req.execution)
2524

25+
const sha = webhook.pullRequest ? webhook.pullRequest.head.sha : webhook.head_commit.id
26+
2627
report.progress(socket, req, `Clonning ${repo}`, null)
28+
report.progress(socket, req, `SHA ${sha}`, null)
2729
report.progress(socket, req, `Temporal path ${tmpPath}`, null)
2830

2931
// Clone repository
30-
git()
31-
.clone(`https://tideflow:${triggerService.config.secret}@github.com/${repo}`, tmpPath)
32-
.then(result => {
33-
delete req.webhook
34-
report.result( socket, req,
35-
{
36-
stderr: null,
37-
stdout: 'Clone finished'
38-
}
39-
)
40-
})
41-
.catch(err => {
42-
report.exception( socket, req, err.toString() )
43-
});
32+
try {
33+
await git().clone(`https://tideflow:${triggerService.config.secret}@github.com/${repo}`, tmpPath)
34+
await git(tmpPath).checkout(sha)
35+
delete req.webhook
36+
report.result( socket, req,
37+
{
38+
stderr: null,
39+
stdout: 'Clone finished'
40+
}
41+
)
42+
}
43+
catch (ex) {
44+
report.exception( socket, req, ex.toString() )
45+
}
4446
}
4547

4648
module.exports.push = push
49+
module.exports.pullRequest = push
4750

4851
const test_cmd = async (socket, topic, req) => {
4952
const commands = req.cmd.split('\n')
@@ -100,10 +103,9 @@ const test_cmd = async (socket, topic, req) => {
100103

101104
try {
102105
await Promise.all(processCommands)
103-
console.log('all promises done')
104106
report.result(socket, req,
105107
{
106-
stdout: 'Clone finished'
108+
stdout: 'Execution finished'
107109
}
108110
)
109111
}
@@ -113,4 +115,5 @@ const test_cmd = async (socket, topic, req) => {
113115
}
114116

115117
module.exports.test_cmd = test_cmd
118+
module.exports.run_cmd = test_cmd
116119

0 commit comments

Comments
 (0)