diff --git a/action/index.cjs b/action/index.cjs index 1e486eb..9d5b763 100644 --- a/action/index.cjs +++ b/action/index.cjs @@ -188079,6 +188079,7 @@ const robot = (app) => { // since the token owner can be changed at protocol level at any time, it's enough to check the ownership of the token, // without checking any previous owners const apiUrl = getApiUrl(); + await checkIfTickerAlreadyExists(token); const tokenOwner = await getTokenOwnerFromApi(token, apiUrl); if (new out_1.Address(tokenOwner).isContractAddress()) { return await fetchStringValueFromApi(apiUrl, "accounts", tokenOwner, "ownerAddress"); @@ -188099,7 +188100,7 @@ const robot = (app) => { return response.data; } catch (error) { - console.error(`Cannot query API at ${requestUrl}: ${error}`); + console.error(`Cannot query API at ${requestUrl} : ${error}`); return ''; } } @@ -188154,6 +188155,23 @@ const robot = (app) => { .filter(x => x); return [...new Set(tokens)]; } + async function checkIfTickerAlreadyExists(tokenName) { + const tokensDirPath = (network === "mainnet") ? "/tokens" : `/${network}/tokens`; + const response = await context.octokit.repos.getContent({ + owner: context.repo().owner, + repo: context.repo().repo, + path: tokensDirPath, + }); + const tokenTicker = tokenName.split("-")[0]; + if (!tokenTicker) { + return; + } + const tokensDirectories = (response.data && response.data.length) ? response.data : []; + const subdirectories = tokensDirectories.filter((content) => content?.type === "dir" && content?.name?.startsWith(tokenTicker)); + if (subdirectories.length) { + await fail(`Token with ticker ${tokenTicker} already exists!`); + } + } async function fail(reason) { await createComment(reason); console.error(reason); diff --git a/src/bot.ts b/src/bot.ts index 8abc3b5..d924ed2 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -127,6 +127,8 @@ export const robot = (app: Probot) => { // without checking any previous owners const apiUrl = getApiUrl(); + await checkIfTickerAlreadyExists(token); + const tokenOwner = await getTokenOwnerFromApi(token, apiUrl); if (new Address(tokenOwner).isContractAddress()) { return await fetchStringValueFromApi(apiUrl, "accounts", tokenOwner, "ownerAddress"); @@ -149,7 +151,7 @@ export const robot = (app: Probot) => { const response = await axios.get(requestUrl); return response.data; } catch (error) { - console.error(`Cannot query API at ${requestUrl}: ${error}`); + console.error(`Cannot query API at ${requestUrl} : ${error}`); return ''; } } @@ -224,6 +226,28 @@ export const robot = (app: Probot) => { return [...new Set(tokens)]; } + async function checkIfTickerAlreadyExists(tokenName: string) { + const tokensDirPath = (network === "mainnet") ? "/tokens" : `/${network}/tokens`; + const response = await context.octokit.repos.getContent({ + owner: context.repo().owner, + repo: context.repo().repo, + path: tokensDirPath, + }); + + const tokenTicker = tokenName.split("-")[0]; + if (!tokenTicker) { + return; + } + const tokensDirectories = (response.data && (response.data as any[]).length) ? response.data as any[] : []; + const subdirectories = tokensDirectories.filter( + (content) => content?.type === "dir" && content?.name?.startsWith(tokenTicker), + ); + + if (subdirectories.length) { + await fail(`Token with ticker ${tokenTicker} already exists!`); + } + } + async function fail(reason: string) { await createComment(reason); console.error(reason);