Skip to content

Commit d33b53d

Browse files
committed
Gitopia changes and other fixes
1 parent 2054d2f commit d33b53d

3 files changed

Lines changed: 24 additions & 20 deletions

File tree

bin/helper.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default class Helper {
6161
// address and path shortcuts
6262
this.address = this.url.split("://")[1];
6363
this.path = path.resolve(process.env.GIT_DIR || "");
64-
this.arweaveWalletPath = process.env.ARWEAVE_WALLET_PATH;
64+
this.gitopiaWalletPath = process.env.GITOPIA_WALLET_PATH;
6565
// config
6666
this.config = this._config();
6767
// lib
@@ -163,18 +163,18 @@ export default class Helper {
163163
async _handlePush(line) {
164164
this.debug("cmd", line);
165165

166-
if (!this.arweaveWalletPath) {
166+
if (!this.gitopiaWalletPath) {
167167
if (process.env.GITOPIA_WALLET) {
168168
this.wallet = JSON.parse(process.env.GITOPIA_WALLET);
169169
} else {
170170
console.error(
171-
"Missing ARWEAVE_WALLET_PATH or GITOPIA_WALLET env variable"
171+
"Missing GITOPIA_WALLET_PATH or GITOPIA_WALLET env variable"
172172
);
173173

174174
this._die();
175175
}
176176
} else {
177-
const rawdata = fs.readFileSync(this.arweaveWalletPath);
177+
const rawdata = fs.readFileSync(this.gitopiaWalletPath);
178178
this.wallet = JSON.parse(rawdata);
179179
}
180180

@@ -199,21 +199,21 @@ export default class Helper {
199199

200200
// OK
201201
async _fetchRefs() {
202-
this.debug("fetching remote refs from arweave");
202+
this.debug("fetching remote refs from Gitopia");
203203

204204
let start;
205205
let block;
206206
let events;
207207
const ops = [];
208-
const spinner = ora("Fetching remote refs from arweave").start();
208+
const spinner = ora("Fetching remote refs from Gitopia").start();
209209

210210
try {
211211
const refs = await getAllRefs(this._arweave, this.url);
212212

213-
spinner.succeed("Remote refs fetched from arweave");
213+
spinner.succeed("Remote refs fetched from Gitopia");
214214
return refs;
215215
} catch (err) {
216-
spinner.fail("Failed to fetch remote refs from arweave");
216+
spinner.fail("Failed to fetch remote refs from Gitopia");
217217
throw err;
218218
}
219219
}
@@ -347,7 +347,7 @@ export default class Helper {
347347

348348
// upload git objects
349349
try {
350-
spinner = ora("Uploading git objects to arweave").start();
350+
spinner = ora("Uploading git objects to Gitopia").start();
351351
const dataItems = await Promise.all(puts);
352352
bar1.stop();
353353
await postBundledTransaction(
@@ -357,21 +357,21 @@ export default class Helper {
357357
this.url,
358358
dataItems
359359
);
360-
spinner.succeed("Git objects uploaded to arweave");
360+
spinner.succeed("Git objects uploaded to Gitopia");
361361
} catch (err) {
362362
spinner.fail(
363-
"Failed to upload git objects to arweave: " + err.message
363+
"Failed to upload git objects to Gitopia: " + err.message
364364
);
365365
this._die();
366366
}
367367

368368
// register on chain
369369
try {
370-
spinner = ora(`Updating ref ${dst} ${objects[0]} on arweave`).start();
370+
spinner = ora(`Updating ref ${dst} ${objects[0]} on Gitopia`).start();
371371
spinner.succeed(`Updated ref ${dst} ${objects[0]} successfully`);
372372
} catch (err) {
373373
spinner.fail(
374-
`Failed to update ref ${dst} ${objects[0]} on arweave: ` +
374+
`Failed to update ref ${dst} ${objects[0]} on Gitopia: ` +
375375
err.message
376376
);
377377
this._die();

bin/lib/arweave.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ export const postBundledTransaction = async (
9393

9494
// Push triggered from gitopia mirror action
9595
if (process.env.GITHUB_SHA) {
96-
tags.push({ name: "Origin", value: "gitopia-mirror-action" })
96+
tx.addTag("Origin", "gitopia-mirror-action")
9797
} else {
98-
tags.push({ name: "Origin", value: "git-remote-gitopia" })
98+
tx.addTag("Origin", "git-remote-gitopia")
9999
}
100100

101101
await arweave.transactions.sign(tx, wallet);
@@ -110,9 +110,7 @@ export const postBundledTransaction = async (
110110

111111
// Send fee to PST holders
112112
const contractState = await smartweave.default.readContract(arweave, contractId);
113-
console.error("contractState", contractState)
114113
const holder = smartweave.default.selectWeightedPstHolder(contractState.balances);
115-
console.error("holder", holder)
116114
// send a fee. You should inform the user about this fee and amount.
117115
const pstTx = await arweave.createTransaction(
118116
{ target: holder, quantity: arweave.ar.arToWinston("0.01") },

bin/lib/graphql.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ export const getOidByRef = async (arweave, remoteURI, ref) => {
4141

4242
const edges = data.data.transactions.edges
4343
if (edges.length === 0) {
44-
return '0000000000000000000000000000000000000000'
44+
return {
45+
oid: null,
46+
numCommits: 0
47+
}
4548
}
4649

4750
edges.sort((a, b) => {
@@ -54,10 +57,12 @@ export const getOidByRef = async (arweave, remoteURI, ref) => {
5457
})
5558

5659
const id = edges[0].node.id
57-
return await arweave.transactions.getData(id, {
60+
const response = await arweave.transactions.getData(id, {
5861
decode: true,
5962
string: true,
6063
})
64+
65+
return JSON.parse(response)
6166
}
6267

6368
export const getAllRefs = async (arweave, remoteURI) => {
@@ -104,7 +109,8 @@ export const getAllRefs = async (arweave, remoteURI) => {
104109
}
105110

106111
for (const ref of refs) {
107-
refOidObj[ref] = await getOidByRef(arweave, remoteURI, ref);
112+
const { oid } = await getOidByRef(arweave, remoteURI, ref);
113+
refOidObj[ref] = oid
108114
}
109115

110116
return refOidObj;

0 commit comments

Comments
 (0)