Skip to content

Commit e1c1c3b

Browse files
more refactoring
1 parent ffc0324 commit e1c1c3b

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

blog-post-workflow.js

+2-21
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const {
99
commitReadme,
1010
truncateString,
1111
buildReadme,
12-
exec
12+
exec,
13+
getParameterisedTemplate
1314
} = require('./utils');
1415
const {
1516
ignoreStackExchangeComments,
@@ -48,26 +49,6 @@ const CUSTOM_TAGS = {};
4849
// Keepalive flag
4950
const ENABLE_KEEPALIVE = core.getInput('enable_keepalive') === 'true';
5051

51-
/**
52-
* Returns parsed parameterised templates as array or return null
53-
* @param template
54-
* @param keyName
55-
* @return {null|string[]}
56-
*/
57-
const getParameterisedTemplate = (template, keyName) => {
58-
const key = '$' + keyName + '(';
59-
if (template.indexOf(key) > -1) {
60-
const startIndex = template.indexOf(key) + key.length;
61-
const endIndex = template.indexOf(')', startIndex);
62-
if (endIndex === -1) {
63-
return null;
64-
}
65-
return template.slice(startIndex, endIndex).split(',').map(item => item.trim());
66-
} else {
67-
return null;
68-
}
69-
};
70-
7152
core.setSecret(GITHUB_TOKEN);
7253

7354
core.getInput('custom_tags')

utils.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,31 @@ const updateAndParseCompoundParams = (sourceWithParam, obj) => {
140140
}
141141
};
142142

143+
/**
144+
* Returns parsed parameterised templates as array or return null
145+
* @param template
146+
* @param keyName
147+
* @return {null|string[]}
148+
*/
149+
const getParameterisedTemplate = (template, keyName) => {
150+
const key = '$' + keyName + '(';
151+
if (template.indexOf(key) > -1) {
152+
const startIndex = template.indexOf(key) + key.length;
153+
const endIndex = template.indexOf(')', startIndex);
154+
if (endIndex === -1) {
155+
return null;
156+
}
157+
return template.slice(startIndex, endIndex).split(',').map(item => item.trim());
158+
} else {
159+
return null;
160+
}
161+
};
162+
143163
module.exports = {
144164
updateAndParseCompoundParams,
145165
commitReadme,
146166
truncateString,
147167
buildReadme,
148-
exec
168+
exec,
169+
getParameterisedTemplate
149170
};

0 commit comments

Comments
 (0)