feat/wp-schedule-and-board/main #31
@@ -16,6 +16,7 @@ import {
|
||||
main,
|
||||
pages,
|
||||
parseFlags,
|
||||
parseIndex,
|
||||
parseRepo,
|
||||
preflight,
|
||||
resolveLogin,
|
||||
@@ -70,12 +71,6 @@ main(async () => {
|
||||
};
|
||||
});
|
||||
|
||||
function parseIndex(value) {
|
||||
if (!/^[1-9]\d*$/.test(value)) {
|
||||
throw new ScriptError('BAD_INDEX', `--index 需為正整數,收到的是 ${value}`);
|
||||
}
|
||||
return Number(value);
|
||||
}
|
||||
|
||||
async function fetchIssue(login, repo, index, path) {
|
||||
const response = await giteaRequest(login, 'GET', path);
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
giteaRequest,
|
||||
main,
|
||||
parseFlags,
|
||||
parseIndex,
|
||||
parseRepo,
|
||||
preflight,
|
||||
resolveLogin,
|
||||
@@ -82,12 +83,6 @@ main(async () => {
|
||||
return { repo, index, added, skipped };
|
||||
});
|
||||
|
||||
function parseIndex(value, what) {
|
||||
if (!/^[1-9]\d*$/.test(String(value))) {
|
||||
throw new ScriptError('BAD_INDEX', `${what} 需為正整數,收到的是 ${value}`);
|
||||
}
|
||||
return Number(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析逗號分隔的議題編號。
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
giteaRequest,
|
||||
main,
|
||||
parseFlags,
|
||||
parseIndex,
|
||||
parseRepo,
|
||||
preflight,
|
||||
resolveLogin,
|
||||
@@ -76,12 +77,6 @@ main(async () => {
|
||||
};
|
||||
});
|
||||
|
||||
function parseIndex(value) {
|
||||
if (!/^[1-9]\d*$/.test(value)) {
|
||||
throw new ScriptError('BAD_INDEX', `--index 需為正整數,收到的是 ${value}`);
|
||||
}
|
||||
return Number(value);
|
||||
}
|
||||
|
||||
function parseDueDate(value) {
|
||||
if (value === undefined) return null;
|
||||
|
||||
@@ -88,6 +88,19 @@ export function parseFlags(argv, spec = {}) {
|
||||
return flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* 驗證議題編號。四支腳本都要做這件事,錯誤碼也該一致。
|
||||
* @param {string|number} value
|
||||
* @param {string} what 出現在錯誤訊息裡的欄位名,例如 '--index'
|
||||
* @returns {number}
|
||||
*/
|
||||
export function parseIndex(value, what = '--index') {
|
||||
if (!/^[1-9]\d*$/.test(String(value))) {
|
||||
throw new ScriptError('BAD_INDEX', `${what} 需為正整數,收到的是 ${value}`);
|
||||
}
|
||||
return Number(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 驗證並正規化 owner/name 形式的 repo。
|
||||
* @param {string} value
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
giteaRequest,
|
||||
main,
|
||||
parseFlags,
|
||||
parseIndex,
|
||||
parseRepo,
|
||||
preflight,
|
||||
resolveLogin,
|
||||
@@ -61,12 +62,6 @@ main(async () => {
|
||||
return { repo, index, project, alreadyThere: false };
|
||||
});
|
||||
|
||||
function parseIndex(value) {
|
||||
if (!/^[1-9]\d*$/.test(value)) {
|
||||
throw new ScriptError('BAD_INDEX', `--index 需為正整數,收到的是 ${value}`);
|
||||
}
|
||||
return Number(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把 `--project` 解析成 {id, title}。
|
||||
|
||||
Reference in New Issue
Block a user