Skip to content

Commit

Permalink
Add revision options to API for git compiling (aslushnikov#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
NonlyNerd committed Jan 26, 2018
1 parent 8097db8 commit 2cea969
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ For every compilation request you can pass the following additional arguments:
- `lualatex`
- `download=sample.pdf` This will initiate downloading of the resulting PDF
into the file with the name "sample.pdf"
- `revision=some_revision_identifier`This will clone the repo with a specific branch, tag or commit
identifier

## Command-line interface

Expand Down
3 changes: 2 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ app.get('/compile', async (req, res) => {
preparation = await latexOnline.prepareURLCompilation(req.query.url, command);
} else if (req.query.git) {
var workdir = req.query.workdir || '';
preparation = await latexOnline.prepareGitCompilation(req.query.git, req.query.target, 'master', command, workdir);
var revision = req.query.revision || 'master';
preparation = await latexOnline.prepareGitCompilation(req.query.git, req.query.target, revision, command, workdir);
}
if (preparation)
handleResult(res, preparation, forceCompilation, req.query.download);
Expand Down
8 changes: 5 additions & 3 deletions lib/DownloadManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ class DownloadManager {

/**
* @param {string} url
* @param {string} revision
* @return {!Downloader}
*/
createGitDownloader(url) {
createGitDownloader(url, revision) {
var folderPath = this._nextName();
return new Downloader(async () => {
var exists = await utils.exists(folderPath);
Expand All @@ -85,8 +86,9 @@ class DownloadManager {
}
var fulfill;
var promise = new Promise(x => fulfill = x);
logger.info(`git clone ${url} ${folderPath}`);
exec('git', ['clone', '--depth', '1', url, folderPath], {timeout: utils.minutes(2)}, (err, stdout, stderr) => {
var args = ['clone', '--depth', '1', '-b', revision, url, folderPath];
logger.info(`Cloning ${url} with revision ${revision} in ${folderPath}`);
exec('git', args, {timeout: utils.minutes(2)}, (err, stdout, stderr) => {
if (err) {
logger.error(`ERROR: Downloader failed to clone git repository. ${err.message}`);
fulfill(new DownloadResult(null, UserErrors.GitCloneFailed(url)));
Expand Down
8 changes: 4 additions & 4 deletions lib/LatexOnline.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ class LatexOnline extends EventEmitter {

/**
* @param {string} url
* @param {string} branch
* @param {string} revision
* @param {string} target
* @param {string} command
* @param {string} workdir
* @return {!Promise<!LatexOnline.Result>}
*/
async prepareGitCompilation(url, target, branch, command, workdir) {
var {request, userError} = await CompilationRequest.createGitRequest(url, target, branch, command, workdir);
async prepareGitCompilation(url, target, revision, command, workdir) {
var {request, userError} = await CompilationRequest.createGitRequest(url, target, revision, command, workdir);
if (!request)
return new LatexOnline.Result(null, null, userError);
var downloader = this._downloadManager.createGitDownloader(url);
var downloader = this._downloadManager.createGitDownloader(url, revision);
return new LatexOnline.Result(request, downloader, null);
}

Expand Down

0 comments on commit 2cea969

Please sign in to comment.