Skip to content

Commit

Permalink
updated dist
Browse files Browse the repository at this point in the history
  • Loading branch information
Bullrich committed Feb 28, 2024
1 parent 51be37c commit 2655eaa
Showing 1 changed file with 65 additions and 10 deletions.
75 changes: 65 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67493,6 +67493,7 @@ const summary_1 = __nccwpck_require__(81327);
const api_1 = __nccwpck_require__(47196);
const constants_1 = __nccwpck_require__(69042);
const parse_RFC_1 = __nccwpck_require__(58542);
const subsquare_1 = __nccwpck_require__(88590);
const logger = {
info: core_1.info,
debug: core_1.debug,
Expand All @@ -67506,7 +67507,7 @@ const getBlockDate = async (blockNr, api) => {
return new Date(timestamp.toPrimitive());
};
const getAllPRs = async (octokit, repo) => {
const prs = await octokit.paginate(octokit.rest.pulls.list, repo);
const prs = await octokit.paginate(octokit.rest.pulls.list, { ...repo, state: "all" });
logger.info(`Found ${prs.length} open PRs`);
const prRemarks = [];
for (const pr of prs) {
Expand Down Expand Up @@ -67534,7 +67535,9 @@ const getAllRFCRemarks = async (startDate) => {
throw new Error(`Query result is not a number: ${typeof query}`);
}
logger.info(`Available referendas: ${query}`);
const hashes = [];
const ongoing = [];
const completed = [];
const subsquareApi = new subsquare_1.SubsquareApi();
for (const index of Array.from(Array(query).keys())) {
logger.info(`Fetching elements ${index + 1}/${query}`);
const refQuery = (await api.query.fellowshipReferenda.referendumInfoFor(index)).toJSON();
Expand All @@ -67551,7 +67554,7 @@ const getAllRFCRemarks = async (startDate) => {
const { proposal } = refQuery.ongoing;
const hash = proposal?.lookup?.hash ?? proposal?.inline;
if (hash) {
hashes.push({ hash, url: `https://collectives.polkassembly.io/referenda/${index}` });
ongoing.push({ hash, url: `https://collectives.polkassembly.io/referenda/${index}` });
}
else {
logger.warn(`Found no lookup hash nor inline hash for https://collectives.polkassembly.io/referenda/${index}`);
Expand All @@ -67560,10 +67563,22 @@ const getAllRFCRemarks = async (startDate) => {
}
else {
logger.debug(`Reference query is not ongoing: ${JSON.stringify(refQuery)}`);
if (refQuery.approved) {
logger.debug(`Fetching info from referenda ${index} from Subsquare`);
const rfc = await subsquareApi.fetchReferenda(index);
const confirmedBlock = rfc.onchainData.timeline.find(({ name }) => name === "Confirmed");
if (confirmedBlock) {
completed.push({
hash: rfc.onchainData.proposalHash,
executedHash: confirmedBlock.indexer.blockHash,
index,
});
}
}
}
}
logger.info(`Found ${hashes.length} ongoing requests`);
return hashes;
logger.info(`Found ${ongoing.length} ongoing and ${completed.length} completed requests`);
return { completed, ongoing };
}
catch (err) {
logger.error("Error during exectuion");
Expand All @@ -67575,13 +67590,13 @@ const getAllRFCRemarks = async (startDate) => {
};
exports.getAllRFCRemarks = getAllRFCRemarks;
const cron = async (startDate, owner, repo, octokit) => {
const remarks = await (0, exports.getAllRFCRemarks)(startDate);
if (remarks.length === 0) {
logger.warn("No ongoing RFCs made from pull requests. Shuting down");
const { ongoing, completed } = await (0, exports.getAllRFCRemarks)(startDate);
if (ongoing.length === 0 && completed.length === 0) {
logger.warn("No RFCs made from pull requests found. Shuting down");
await summary_1.summary.addHeading("Referenda search", 3).addHeading("Found no matching referenda to open PRs", 5).write();
return;
}
logger.debug(`Found remarks ${JSON.stringify(remarks)}`);
logger.debug(`Found remarks ${JSON.stringify(ongoing)}`);
const prRemarks = await (0, exports.getAllPRs)(octokit, { owner, repo });
logger.debug(`Found all PR remarks ${JSON.stringify(prRemarks)}`);
const rows = [
Expand All @@ -67596,11 +67611,26 @@ const cron = async (startDate, owner, repo, octokit) => {
for (const [pr, remark] of prRemarks) {
// We compare the hash to see if there is a match
const tx = api.tx.system.remark(remark);
const match = remarks.find(({ hash }) => hash === tx.method.hash.toHex() || hash === tx.method.toHex());
// We first start with ongoing referendas
console.log("Remark for %s is", pr, remark, tx.method.hash.toHex(), tx.method.toHex());
const match = ongoing.find(({ hash }) => hash === tx.method.hash.toHex() || hash === tx.method.toHex());
if (match) {
logger.info(`Found existing referenda for PR #${pr}`);
const msg = `Voting for this referenda is **ongoing**.\n\nVote for it [here](${match.url})`;
rows.push([`${owner}/${repo}#${pr}`, `<a href="${match.url}">${match.url}</a>`]);
console.log("Publishing", msg);
await octokit.rest.issues.createComment({ owner, repo, issue_number: pr, body: msg });
}
// if we don't find a match, we search for a closed referenda
const closedMatch = completed.find(({ hash }) => hash === tx.method.hash.toHex() || hash === tx.method.toHex());
if (closedMatch) {
logger.info(`Found completed referenda for PR #${pr}`);
const msg = `/rfc process ${closedMatch.executedHash}`;
rows.push([
`${owner}/${repo}#${pr}`,
`<a href="https://collectives.polkassembly.io/referenda/${closedMatch.index}>RFC ${closedMatch.index}</a>`,
]);
console.log("Publishing", msg);
await octokit.rest.issues.createComment({ owner, repo, issue_number: pr, body: msg });
}
}
Expand Down Expand Up @@ -68085,6 +68115,31 @@ const createReferendumTx = async (opts) => {
exports.createReferendumTx = createReferendumTx;


/***/ }),

/***/ 88590:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";

var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.SubsquareApi = void 0;
const node_fetch_1 = __importDefault(__nccwpck_require__(80467));
class SubsquareApi {
constructor() {
this.url = "https://collectives.subsquare.io";
}
async fetchReferenda(index) {
const request = await (0, node_fetch_1.default)(`${this.url}/api/fellowship/referenda/${index}.json`);
return await request.json();
}
}
exports.SubsquareApi = SubsquareApi;


/***/ }),

/***/ 92629:
Expand Down

0 comments on commit 2655eaa

Please sign in to comment.