Skip to content

Commit e870016

Browse files
authored
Update index.js
tiny fix for situations where no prior logs stored
1 parent 0776e33 commit e870016

File tree

1 file changed

+33
-39
lines changed

1 file changed

+33
-39
lines changed

svn-bot/index.js

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,44 @@ unirest.get(program.destination)
4646
if (res_last.status === 200)
4747
{
4848
const {result} = res_last.body;
49-
if (result)
49+
50+
const {revision} = result.log;
51+
svn.commands.log(program.address, {
52+
trustServerCert: true,
53+
revision: result ? `HEAD:${revision}` : `HEAD:1`,
54+
username: program.username,
55+
password: program.password
56+
}, (err, data) =>
5057
{
51-
const {revision} = result.log;
52-
svn.commands.log(program.address, {
53-
trustServerCert: true,
54-
revision: `HEAD:${revision}`,
55-
username: program.username,
56-
password: program.password
57-
}, (err, data) =>
58+
if (!err)
5859
{
59-
if (!err)
60+
if (!Array.isArray(data.logentry))
61+
{
62+
const doc = {
63+
repo: program.address,
64+
log: {
65+
revision: Number(data.logentry.$.revision),
66+
author: data.logentry.author,
67+
date: new Date(data.logentry.date).getTime(),
68+
message: data.logentry.msg
69+
}
70+
};
71+
72+
if (doc.log.revision > revision)
73+
{
74+
uploadToApi(doc);
75+
}
76+
}
77+
else
6078
{
61-
if (!Array.isArray(data.logentry))
79+
for (const entry of data.logentry)
6280
{
6381
const doc = {
6482
repo: program.address,
6583
log: {
66-
revision: Number(data.logentry.$.revision),
67-
author: data.logentry.author,
68-
date: new Date(data.logentry.date).getTime(),
69-
message: data.logentry.msg
84+
revision: Number(entry.$.revision), author: entry.author,
85+
date: new Date(entry.date).getTime(),
86+
message: entry.msg
7087
}
7188
};
7289

@@ -75,32 +92,9 @@ unirest.get(program.destination)
7592
uploadToApi(doc);
7693
}
7794
}
78-
else
79-
{
80-
for (const entry of data.logentry)
81-
{
82-
const doc = {
83-
repo: program.address,
84-
log: {
85-
revision: Number(entry.$.revision), author: entry.author,
86-
date: new Date(entry.date).getTime(),
87-
message: entry.msg
88-
}
89-
};
90-
91-
if (doc.log.revision > revision)
92-
{
93-
uploadToApi(doc);
94-
}
95-
}
96-
}
9795
}
98-
});
99-
}
100-
else
101-
{
102-
process.exit(1);
103-
}
96+
}
97+
});
10498
}
10599
else
106100
{

0 commit comments

Comments
 (0)