Skip to content

Commit

Permalink
feat: posts to github
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 committed May 24, 2024
1 parent 0ab95c5 commit ee697af
Show file tree
Hide file tree
Showing 4 changed files with 565 additions and 5 deletions.
4 changes: 2 additions & 2 deletions build/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import * as dotenv from "dotenv";
dotenv.config();
console.log("Welcome to Powerhouse mirror");
import mirror from "./mirror";
mirror();
88 changes: 88 additions & 0 deletions build/mirror.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { Octokit } from "@octokit/rest";
import fetch from "node-fetch";
import * as dotenv from "dotenv";
dotenv.config();

const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
if (!GITHUB_TOKEN) {
throw new Error("GITHUB_TOKEN is required");
}

const GITHUB_REPO_OWNER = "0x4007";
const GITHUB_REPO_NAME = "powerhouse-mirror";

const octokit = new Octokit({ auth: GITHUB_TOKEN });

const query = `
query {
document(id: "5KzfqVzVgZegGXxfY+pccgZGfug=") {
id
... on RealWorldAssets {
operations {
type
index
timestamp
hash
}
state {
accounts {
id
}
}
}
}
}
`;

const GRAPHQL_ENDPOINT = "https://apps.powerhouse.io/alpha/powerhouse/switchboard/d/powerhouse";

async function fetchIssueData() {
try {
const response = await fetch(GRAPHQL_ENDPOINT, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ query }),
});

const result = await response.json();
if (result.errors) {
throw new Error(JSON.stringify(result.errors));
}

const data = result.data;
const title = `Document ID: ${data.document.id}`;
const description = "```json\n" + JSON.stringify(data.document, null, 2) + "\n```";
return { title, description };
} catch (error) {
console.error("Error fetching issue data:", error);
throw error;
}
}

async function createGitHubIssue(title: string, body: string) {
try {
const response = await octokit.issues.create({
owner: GITHUB_REPO_OWNER,
repo: GITHUB_REPO_NAME,
title: title,
body: body,
});
console.log("GitHub issue created:", response.data.html_url);
} catch (error) {
console.error("Error creating GitHub issue:", error);
throw error;
}
}

async function main() {
try {
const issueData = await fetchIssueData();
await createGitHubIssue(issueData.title, issueData.description);
} catch (error) {
console.error("Error in main function:", error);
}
}

void main();
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@
"open-source"
],
"dependencies": {
"dotenv": "^16.4.4"
"@apollo/client": "^3.10.4",
"@octokit/rest": "^20.1.1",
"cross-fetch": "^4.0.0",
"dotenv": "^16.4.4",
"graphql": "^16.8.1",
"graphql-request": "^7.0.1",
"node-fetch": "^3.3.2"
},
"devDependencies": {
"@commitlint/cli": "^18.6.1",
Expand Down
Loading

0 comments on commit ee697af

Please sign in to comment.