From 89440133e412b042b060db4b69f63508cd021a58 Mon Sep 17 00:00:00 2001 From: bogdan-rosianu Date: Mon, 19 Feb 2024 13:24:09 +0200 Subject: [PATCH] renamings + small refactor --- action/index.cjs | 29 ++++++++++++----------------- src/bot.ts | 33 +++++++++++++-------------------- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/action/index.cjs b/action/index.cjs index febed8b..c80922a 100644 --- a/action/index.cjs +++ b/action/index.cjs @@ -188001,13 +188001,13 @@ const robot = (app) => { const originalOwners = []; const newOwners = []; const networkPath = network === 'mainnet' ? '' : `${network}/`; - const infoJsonUrl = `https://raw.githubusercontent.com/multiversx/mx-assets/master/${networkPath}identities/${identity}/info.json`; + const infoJsonUrl = `https://raw.githubusercontent.com/multiversx/mx-assets/master/${networkPath}identities/${asset}/info.json`; // we try to read the contents of the info.json file const { data: infoFromMaster } = await axios_1.default.get(infoJsonUrl, { validateStatus: status => [200, 404].includes(status) }); if (infoFromMaster && typeof infoFromMaster === 'object' && infoFromMaster['owners']) { originalOwners.push(...infoFromMaster.owners); } - const infoJsonFile = files.find(x => x.filename.endsWith(`/${identity}.json`)); + const infoJsonFile = files.find(x => x.filename.endsWith(`/${asset}/info.json`)); if (infoJsonFile) { const { data: infoFromPullRequest } = await axios_1.default.get(infoJsonFile.raw_url); if (infoFromPullRequest && typeof infoFromPullRequest === 'object' && infoFromPullRequest['owners']) { @@ -188038,15 +188038,10 @@ const robot = (app) => { } return [...new Set(allOwners)]; } - async function getAccountOwner() { - if (!identity) { - return ''; - } - const account = identity; + async function getAccountOwner(account) { const accountOwner = await getAccountOwnerFromApi(account); if (new out_1.Address(accountOwner).isContractAddress()) { - const newOwner = getAccountOwnerFromApi(accountOwner); - return newOwner; + return getAccountOwnerFromApi(accountOwner); } return accountOwner; } @@ -188058,13 +188053,9 @@ const robot = (app) => { } return ''; } - async function getTokenOwner() { + async function getTokenOwner(token) { // 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 - if (!identity) { - return ''; - } - const token = identity; const apiUrl = getApiUrl(); const tokenOwner = await getTokenOwnerFromApi(token, apiUrl); if (new out_1.Address(tokenOwner).isContractAddress()) { @@ -188257,7 +188248,11 @@ const robot = (app) => { await fail('Only one network must be edited at a time'); return; } - const identity = distinctIdentities[0]; + const asset = distinctIdentities[0]; + if (!asset) { + await fail('No asset update detected'); + return; + } const network = distinctNetworks[0]; let owners; switch (checkMode) { @@ -188265,10 +188260,10 @@ const robot = (app) => { owners = await getIdentityOwners(changedFiles); break; case 'account': - owners = [...await getAccountOwner()]; + owners = [...await getAccountOwner(asset)]; break; case 'token': - owners = [...await getTokenOwner()]; + owners = [...await getTokenOwner(asset)]; break; default: owners = []; diff --git a/src/bot.ts b/src/bot.ts index 850a0fb..dc89cac 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -30,7 +30,7 @@ export const robot = (app: Probot) => { const newOwners: string[] = []; const networkPath = network === 'mainnet' ? '' : `${network}/`; - const infoJsonUrl = `https://raw.githubusercontent.com/multiversx/mx-assets/master/${networkPath}identities/${identity}/info.json`; + const infoJsonUrl = `https://raw.githubusercontent.com/multiversx/mx-assets/master/${networkPath}identities/${asset}/info.json`; // we try to read the contents of the info.json file const { data: infoFromMaster } = await axios.get(infoJsonUrl, { validateStatus: status => [200, 404].includes(status) }); @@ -39,7 +39,7 @@ export const robot = (app: Probot) => { originalOwners.push(...infoFromMaster.owners); } - const infoJsonFile = files.find(x => x.filename.endsWith(`/${identity}.json`)); + const infoJsonFile = files.find(x => x.filename.endsWith(`/${asset}/info.json`)); if (infoJsonFile) { const { data: infoFromPullRequest } = await axios.get(infoJsonFile.raw_url); @@ -77,16 +77,10 @@ export const robot = (app: Probot) => { return [...new Set(allOwners)]; } - async function getAccountOwner(): Promise { - if (!identity) { - return ''; - } - const account = identity; - - const accountOwner = await getAccountOwnerFromApi(account); + async function getAccountOwner(account: string): Promise { + const accountOwner = await getAccountOwnerFromApi(account); if (new Address(accountOwner).isContractAddress()) { - const newOwner = getAccountOwnerFromApi(accountOwner); - return newOwner; + return getAccountOwnerFromApi(accountOwner); } return accountOwner; @@ -102,14 +96,9 @@ export const robot = (app: Probot) => { return ''; } - async function getTokenOwner(): Promise { + async function getTokenOwner(token: string): Promise { // 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 - if (!identity) { - return ''; - } - const token = identity; - const apiUrl = getApiUrl(); const tokenOwner = await getTokenOwnerFromApi(token, apiUrl); @@ -358,7 +347,11 @@ export const robot = (app: Probot) => { return; } - const identity = distinctIdentities[0]; + const asset = distinctIdentities[0]; + if(!asset) { + await fail('No asset update detected'); + return; + } const network = distinctNetworks[0]; let owners: string[]; @@ -367,10 +360,10 @@ export const robot = (app: Probot) => { owners = await getIdentityOwners(changedFiles); break; case 'account': - owners = [...await getAccountOwner()]; + owners = [...await getAccountOwner(asset)]; break; case 'token': - owners = [...await getTokenOwner()]; + owners = [...await getTokenOwner(asset)]; break; default: owners = [];