Skip to content

Commit

Permalink
feat(publish): implement filtering with --only and --exclude
Browse files Browse the repository at this point in the history
Fixes #821
  • Loading branch information
trieloff committed May 7, 2019
1 parent 8739ef4 commit e94ea52
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/git-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ class GitUtils {
*/
static async getRawContent(dir, ref, pathName) {
return GitUtils.resolveCommit(dir, ref)
.then(oid => git.readObject({ dir, oid, filepath: pathName, format: 'content' }))
.then(oid => git.readObject({
dir, oid, filepath: pathName, format: 'content',
}))
.then(obj => obj.object);
}
}
Expand Down
43 changes: 42 additions & 1 deletion src/remotepublish.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ const request = require('request-promise-native');
const fastly = require('@adobe/fastly-native-promises');
const chalk = require('chalk');
const ProgressBar = require('progress');
const glob = require('glob-to-regexp');
const { HelixConfig } = require('@adobe/helix-shared');
const AbstractCommand = require('./abstract.cmd.js');
const GitUtils = require('./git-utils.js');


class RemotePublishCommand extends AbstractCommand {
Expand Down Expand Up @@ -113,6 +116,27 @@ class RemotePublishCommand extends AbstractCommand {
return this;
}

withFilter(only, exclude) {
const negate = expr => (only ? !!expr : !expr);
const globex = glob(only || exclude);
this._filter = (master, current) => {
const leftmatch = master && master.name && !negate(globex.test(master.name));
const rightmatch = current && current.name && negate(globex.test(current.name));
this.logger.debug('matches:', master ? master.name : undefined, leftmatch, current ? current.name : undefined, rightmatch);
if (rightmatch) {
this.logger.debug('using current');
return current;
}
if (leftmatch) {
this.logger.debug('using master');
return master;
}
this.logger.debug('using none');
return undefined;
};
return this;
}

showNextStep(dryrun) {
this.progressBar().terminate();
if (dryrun) {
Expand Down Expand Up @@ -169,8 +193,25 @@ class RemotePublishCommand extends AbstractCommand {
});
}

servicePublish() {
async servicePublish() {
this.tick(1, 'preparing service config for Helix', true);

if (this._filter) {
this.logger.debug('filtering');
const content = await GitUtils.getRawContent('.', 'master', 'helix-config.yaml');

const other = await new HelixConfig()
.withSource(content.toString())
.init();

this.logger.debug('this', this.config.strains.keys());
this.logger.debug('other', other.strains.keys());
const merged = other.merge(this.config, this._filter);
this.logger.debug(merged.strains.keys());

this._config = merged;
}

return request.post(this._publishAPI, {
json: true,
body: {
Expand Down

0 comments on commit e94ea52

Please sign in to comment.