generated from ubiquity/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
565 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.