Skip to content

Commit

Permalink
renamings + small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-rosianu committed Feb 19, 2024
1 parent d326a33 commit 8944013
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 37 deletions.
29 changes: 12 additions & 17 deletions action/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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()) {
Expand Down Expand Up @@ -188257,18 +188248,22 @@ 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) {
case 'identity':
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 = [];
Expand Down
33 changes: 13 additions & 20 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) });
Expand All @@ -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);

Expand Down Expand Up @@ -77,16 +77,10 @@ export const robot = (app: Probot) => {
return [...new Set(allOwners)];
}

async function getAccountOwner(): Promise<string> {
if (!identity) {
return '';
}
const account = identity;

const accountOwner = await getAccountOwnerFromApi(account);
async function getAccountOwner(account: string): Promise<string> {
const accountOwner = await getAccountOwnerFromApi(account);
if (new Address(accountOwner).isContractAddress()) {
const newOwner = getAccountOwnerFromApi(accountOwner);
return newOwner;
return getAccountOwnerFromApi(accountOwner);
}

return accountOwner;
Expand All @@ -102,14 +96,9 @@ export const robot = (app: Probot) => {
return '';
}

async function getTokenOwner(): Promise<string> {
async function getTokenOwner(token: string): Promise<string> {
// 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);
Expand Down Expand Up @@ -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[];
Expand All @@ -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 = [];
Expand Down

0 comments on commit 8944013

Please sign in to comment.