Skip to content

Commit

Permalink
GitOps commit
Browse files Browse the repository at this point in the history
* create from main class
* commit loop poc
  • Loading branch information
Eccenux committed Jul 13, 2023
1 parent 626d2ed commit 4fa4471
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/GitOps.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default class GitOps {
if (!result) {
throw 'Unable to create repo!';
}
return result;
}

/** Add all files (stage changes). */
Expand Down
38 changes: 38 additions & 0 deletions src/LoadData.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fetch from 'node-fetch';
import fs from 'fs';
import fsa from 'fs/promises';
import HistoryEntry from './HistoryEntry.js';
import GitOps from './GitOps.js';

/**
* Download page history from a Mediawiki site.
Expand Down Expand Up @@ -161,6 +162,43 @@ export class LoadData {
]);
}

/**
* Init repo.
*
* Skip this if repo already exists
* and you are just creating a history of a new file.
*/
async repoCreate(repoName) {
if (!this.history.length) {
throw 'Load (or read) history first';
}
this.prepareDir();
const git = new GitOps(this.baseDir, repoName);
await git.create();
}

/**
* Commit file history into the repo.
*
* Load rev, save and commit.
* This is separate from loading historyon purpose.
* Use `saveHistory` after initial load and then `readHistory`.
* You can manipulatedsaved JSON in between or merge two files as one.
*/
async repoCommit(repoName, filename) {
if (!this.history.length) {
throw 'Load (or read) history first';
}
const git = new GitOps(this.baseDir, repoName);

const dir = this.baseDir + repoName + '/';
for (const history of this.history) {
await this.saveRev(history.id, dir + filename);
await git.addAll();
await git.commit(history);
}
}

/**
* Preare base directory.
* @private
Expand Down
16 changes: 12 additions & 4 deletions src/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,22 @@ const loader = new LoadData(site);
// await loader.saveHistory();
// loader.info();

// read from JSON
/**
* Read page history from JSON.
*/
loader.history = [];
await loader.readHistory();
loader.info();

// test rev save
// await loader.poc();

console.log('\n\nCreating Git repo.')
const git = new GitOps('./repo', 'temp-git');
await git.create();
/**
* Create Git repo.
*/
const repoName = 'wiki-gConfig';
const filename = 'gConfig.js';
console.log('\n\nCreating Git repo (%s).', repoName);
loader.repoCreate(repoName);
console.log('\nSave history as %s.', filename);
loader.repoCommit(repoName, filename);

0 comments on commit 4fa4471

Please sign in to comment.