const create = Object.create;
const define = Object.defineProperties;
const freeze = Object.freeze;
const JitRub$internal = new WeakMap();

/**
 * Create Jira-GitHub sync.
 * @param {Jira} jira
 * @param {GitHub} github
 * @returns {JitRub}
 */
function jitrub(jira, github) {
    jitrub = create(JitRub);

    JitRub$internal.set(jitrub, {
        jira: jira,
        github: github,
        project: "",
        base: "master",
        head: "jitrub",
        statuses: new Set()
    });

    return jitrub;
}

const JitRub = {
    /**
     * Sync GitHub build branch with Jira issue feature branches.
     * @returns {Promise}
     */
    sync: function() {
        var project = this.project,
            statuses = this.statuses;

        return this.jira.issues(project, statuses).then(issues => {
            var branches;
            issues.sort((a,b) => a.key.localeCompare(b.key));
            branches = issues.map(branch => this.github.branch(branch));
            return Promise.all(branches).then(b => b.filter(b => b));
        }).then(features => {
            console.log(features);
        });
    },

    /**
     * Select Jira project from which tickets will be synced.
     * @param {string} projectCode
     */
    selectProject: function(projectCode) {
        projectCode = projectCode ? String(projectCode) : "";
        JitRub$internal.get(this).project = projectCode;
    },

    /**
     * Select base branch to start with when merging features into the head
     * branch.
     * @param {string} baseBranch
     */
    selectBase: function(baseBranch) {
        baseBranch = baseBranch ? String(baseBranch) : "";
        JitRub$internal.get(this).base = baseBranch;
    },

    /**
     * Select head branch to merge features into.
     * @param {string} headBranch
     */
    selectHead: function(headBranch) {
        headBranch = headBranch ? String(headBranch) : "";
        JitRub$internal.get(this).head = headBranch;
    },

    /**
     * Include features with specified issue status.
     * @param {string} status
     */
    includeStatus: function(status) {
        JitRub$internal.get(this).statuses.add(status);
    },

    /**
     * Exclude features with specified issue status.
     * @param {string} status
     */
    excludeStatus: function(status) {
        JitRub$internal.get(this).statuses.delete(status);
    }
};

define(JitRub, {
    /**
     * Jira connection.
     * @name JitRub#jira
     * @type {Jira}
     * @readonly
     */
    jira: {
        configurable: true,
        enumerable: true,
        get: function() {return JitRub$internal.get(this).jira;}
    },

    /**
     * GitHub connection.
     * @name JitRub#github
     * @type {GitHub}
     * @readonly
     */
    github: {
        configurable: true,
        enumerable: true,
        get: function() {return JitRub$internal.get(this).github;}
    },

    /**
     * Jira project code from which issues are synced.
     * @name JitRub#project
     * @type {string}
     * @readonly
     */
    project: {
        configurable: true,
        enumerable: true,
        get: function() {return JitRub$internal.get(this).project;}
    },

    /**
     * Base branch to start with for merging features.
     * @name JitRub#base
     * @type {string}
     * @readonly
     */
    base: {
        configurable: true,
        enumerable: true,
        get: function() {return JitRub$internal.get(this).base;}
    },

    /**
     * Head branch to which base and features are merged.
     * @name JitRub#head
     * @type {string}
     * @readonly
     */
    head: {
        configurable: true,
        enumerable: true,
        get: function() {return JitRub$internal.get(this).head;}
    },

    /**
     * Return immutable set of issue statuses to include when merging
     * features.
     * @name JitRub#statuses
     * @type {Set}
     * @readonly
     */
    statuses: {
        configurable: true,
        enumerable: true,
        get: function() {
            return freeze(new Set(JitRub$internal.get(this).statuses));
        }
    }
});

module.exports = jitrub;
module.exports.JitRub = JitRub;

@@ -919,22 +919,21 @@
 ues.map(
-branch
+issue
  =%3E this
@@ -947,22 +947,25 @@
 .branch(
-branch
+issue.key
 ));%0A    
@@ -1076,29 +1076,112 @@
     
-console.log(features)
+var log = %7B%7D, i;%0A            features.forEach(branch =%3E log%5Bbranch.name%5D = true);%0A            return log
 ;%0A  

tweak messaging and return value from JitRub.sync