Skip to content

Commit

Permalink
fix(ui): show issues and branch names in ui (#13)
Browse files Browse the repository at this point in the history
Closes #12.
  • Loading branch information
tagoro9 authored Mar 3, 2017
1 parent ae7f872 commit 67c40a9
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 22 deletions.
11 changes: 8 additions & 3 deletions lib/fotingo-review.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ try {

var _reporter$stepFactory = _reporter2['default'].stepFactory(getTotalSteps(_commander2['default'])),
step = _reporter$stepFactory.step,
stepCurried = _reporter$stepFactory.stepCurried;
stepCurried = _reporter$stepFactory.stepCurried,
stepCurriedP = _reporter$stepFactory.stepCurriedP;

var stepOffset = shouldGetIssue() ? 0 : 2;
var project = (0, _util.getProject)(process.cwd());
Expand All @@ -46,7 +47,11 @@ try {
var git = _ref.git,
github = _ref.github,
issueTracker = _ref.issueTracker;
return (0, _util2.wrapInPromise)(step(2, 'Pushing current branch to Github', 'arrow_up')).then(_ramda2['default'].partial(git.pushBranchToGithub, [_config2['default']])).then(_ramda2['default'].ifElse(shouldGetIssue, _ramda2['default'].compose(issueTracker.getIssue, stepCurried(4, 'Getting issue from ' + issueTracker.name, 'bug'), git.extractIssueFromCurrentBranch, stepCurried(3, 'Extracting issue from current branch', 'mag_right')), _ramda2['default'].always(undefined))).then(function (issue) {
return git.getCurrentBranchName().then(_ramda2['default'].compose(_util2.wrapInPromise, stepCurried(2, function (name) {
return 'Pushing \'' + name + '\' to Github';
}, 'arrow_up'))).then(_ramda2['default'].partial(git.pushBranchToGithub, [_config2['default']])).then(_ramda2['default'].ifElse(shouldGetIssue, _ramda2['default'].composeP(issueTracker.getIssue, stepCurriedP(4, function (issue) {
return 'Getting \'' + issue + '\' from ' + issueTracker.name;
}, 'bug'), git.extractIssueFromCurrentBranch, stepCurriedP(3, 'Extracting issue from branch', 'mag_right')), _ramda2['default'].always(undefined))).then(function (issue) {
step(5 - stepOffset, 'Getting your commit history', 'books');
return git.getBranchInfo(issue).then(step(6 - stepOffset, 'Creating pull request', 'speaker')).then(github.checkAndGetLabels(_config2['default'], project, _commander2['default'].label)).then(github.createPullRequest(_config2['default'], project, issue, issueTracker.issueRoot));
}).then(_ramda2['default'].ifElse(_ramda2['default'].partial(_ramda2['default'].compose(_ramda2['default'].not, _ramda2['default'].propEq('simple', true)), [_commander2['default']]), function (_ref2) {
Expand All @@ -56,7 +61,7 @@ try {
return promise.then(_ramda2['default'].always((0, _util2.wrapInPromise)({ pullRequest: pullRequest })));
}, function (promises) {
return Promise.all(promises);
}, _ramda2['default'].map(_ramda2['default'].composeP(_ramda2['default'].partial(issueTracker.setIssueStatus, [{ status: issueTracker.status.IN_REVIEW, comment: 'PR: ' + pullRequest.html_url }]), issueTracker.getIssue, _ramda2['default'].compose(_util2.wrapInPromise, _ramda2['default'].prop('issue')))), stepCurried(7 - stepOffset, 'Setting issues to code review on ' + issueTracker.name, 'bookmark'))(issues);
}, _ramda2['default'].map(_ramda2['default'].composeP(_ramda2['default'].partial(issueTracker.setIssueStatus, [{ status: issueTracker.status.IN_REVIEW, comment: 'PR: ' + pullRequest.html_url }]), issueTracker.getIssue, _ramda2['default'].compose(_util2.wrapInPromise, _ramda2['default'].prop('issue')))), stepCurried(7 - stepOffset, 'Setting ' + _ramda2['default'].compose(_ramda2['default'].join(', '), _ramda2['default'].map(_ramda2['default'].prop('issue')))(issues) + ' to code review on ' + issueTracker.name, 'bookmark'))(issues);
}, _ramda2['default'].identity));
}).then(_ramda2['default'].compose(_reporter2['default'].footer, _ramda2['default'].ifElse(_ramda2['default'].isNil, _ramda2['default'].identity, _ramda2['default'].path(['pullRequest', 'html_url']))))['catch'](_error.handleError);
})();
Expand Down
8 changes: 6 additions & 2 deletions lib/fotingo-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var _reporter = require('./reporter');

var _reporter2 = _interopRequireDefault(_reporter);

var _util2 = require('./util');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _reporter$stepFactory = _reporter2['default'].stepFactory(4),
Expand All @@ -40,8 +42,10 @@ try {
(0, _init2['default'])(_config2['default'], _commander2['default']).then(function (_ref) {
var git = _ref.git,
issueTracker = _ref.issueTracker;
return issueTracker.getCurrentUser().then(stepCurried(2, 'Getting issue from ' + issueTracker.name, 'bug')).then(function (user) {
return issueTracker.getIssue(issueId).then(issueTracker.canWorkOnIssue(user)).then(stepCurried(3, 'Updating issue status', 'bookmark')).then(issueTracker.setIssueStatus({ status: issueTracker.status.IN_PROGRESS })).then(stepCurried(4, 'Creating branch to work on issue', 'tada')).then(git.createIssueBranch(_config2['default']));
return issueTracker.getCurrentUser().then(stepCurried(2, 'Getting \'' + issueId + '\' from ' + issueTracker.name, 'bug')).then(function (user) {
return issueTracker.getIssue(issueId).then(issueTracker.canWorkOnIssue(user)).then(stepCurried(3, 'Setting \'' + issueId + '\' in progress', 'bookmark')).then(issueTracker.setIssueStatus({ status: issueTracker.status.IN_PROGRESS })).then(_ramda2['default'].compose(_util2.wrapInPromise, git.createBranchName)).then(stepCurried(4, function (name) {
return 'Creating branch \'' + name + '\'';
}, 'tada')).then(git.createIssueBranch(_config2['default']));
});
}).then(_reporter2['default'].footer)['catch'](_error.handleError);
})();
Expand Down
5 changes: 3 additions & 2 deletions lib/git/local/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ exports['default'] = {

return init;
}(),
createIssueBranch: _ramda2['default'].curryN(2, function (config, issue) {
createBranchName: _util.createBranchName,
createIssueBranch: _ramda2['default'].curryN(2, function (config, name) {
(0, _util2.debug)('git', 'Creating branch for issue');
var name = (0, _util.createBranchName)(issue);

var _config$get = config.get(['git']),
remote = _config$get.remote,
Expand All @@ -92,6 +92,7 @@ exports['default'] = {
return repository.checkoutBranch(name);
});
}),
getCurrentBranchName: getCurrentBranchName,
pushBranchToGithub: _ramda2['default'].converge(_ramda2['default'].composeP(function (_ref2) {
var _ref3 = _slicedToArray(_ref2, 3),
remote = _ref3[0],
Expand Down
17 changes: 15 additions & 2 deletions lib/reporter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var _read = require('read');

var _read2 = _interopRequireDefault(_read);

var _util = require('../util');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var stdout = process.stdout;
Expand Down Expand Up @@ -68,14 +70,25 @@ var step = _ramda2['default'].curryN(4, function (total, current, msg, emojiStr)
});

var stepCurried = _ramda2['default'].curryN(5, function (total, current, msg, emojiStr, args) {
step(total, current, msg, emojiStr);
step(total, current, _ramda2['default'].ifElse(_ramda2['default'].is(Function), function (m) {
return m(args);
}, _ramda2['default'].identity())(msg), emojiStr);
return args;
});

var stepCurriedP = _ramda2['default'].curryN(5, function (total, current, msg, emojiStr, args) {
stepCurried(total, current, msg, emojiStr, args);
return Promise.resolve(args);
});

exports['default'] = {
stepFactory: function () {
function stepFactory(totalSteps) {
return { step: step(totalSteps), stepCurried: stepCurried(totalSteps) };
return {
step: step(totalSteps),
stepCurried: stepCurried(totalSteps),
stepCurriedP: stepCurriedP(totalSteps)
};
}

return stepFactory;
Expand Down
22 changes: 16 additions & 6 deletions src/fotingo-review.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,22 @@ try {
R.always(4),
R.ifElse(R.propEq('branchIssue', false), R.always(5), R.always(7))
);
const { step, stepCurried } = reporter.stepFactory(getTotalSteps(program));
const { step, stepCurried, stepCurriedP } = reporter.stepFactory(getTotalSteps(program));
const stepOffset = shouldGetIssue() ? 0 : 2;
const project = getProject(process.cwd());
step(1, 'Initializing services', 'rocket');
init(config, program)
.then(({ git, github, issueTracker }) =>
wrapInPromise(step(2, 'Pushing current branch to Github', 'arrow_up'))
git.getCurrentBranchName()
.then(R.compose(wrapInPromise, stepCurried(2, name => `Pushing '${name}' to Github`, 'arrow_up')))
.then(R.partial(git.pushBranchToGithub, [config]))
.then(R.ifElse(
shouldGetIssue,
R.compose(
R.composeP(
issueTracker.getIssue,
stepCurried(4, `Getting issue from ${issueTracker.name}`, 'bug'),
stepCurriedP(4, issue => `Getting '${issue}' from ${issueTracker.name}`, 'bug'),
git.extractIssueFromCurrentBranch,
stepCurried(3, 'Extracting issue from current branch', 'mag_right')
stepCurriedP(3, 'Extracting issue from branch', 'mag_right')
),
R.always(undefined),
))
Expand All @@ -64,7 +65,16 @@ try {
issueTracker.getIssue,
R.compose(wrapInPromise, R.prop('issue'))
)),
stepCurried(7 - stepOffset, `Setting issues to code review on ${issueTracker.name}`, 'bookmark'),
stepCurried(
7 - stepOffset,
`Setting ${
R.compose(
R.join(', '),
R.map(R.prop('issue'))
)(issues)
} to code review on ${issueTracker.name}`,
'bookmark'
),
)(issues),
R.identity
)))
Expand Down
8 changes: 5 additions & 3 deletions src/fotingo-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import config from './config';
import { handleError } from './error';
import init from './init';
import reporter from './reporter';
import { wrapInPromise } from './util';

const { step, stepCurried } = reporter.stepFactory(4);
const getIssueId = R.compose(validate, R.head, R.prop('args'));
Expand All @@ -17,13 +18,14 @@ try {
init(config, program)
.then(({ git, issueTracker }) =>
issueTracker.getCurrentUser()
.then(stepCurried(2, `Getting issue from ${issueTracker.name}`, 'bug'))
.then(stepCurried(2, `Getting '${issueId}' from ${issueTracker.name}`, 'bug'))
.then(user =>
issueTracker.getIssue(issueId)
.then(issueTracker.canWorkOnIssue(user))
.then(stepCurried(3, 'Updating issue status', 'bookmark'))
.then(stepCurried(3, `Setting '${issueId}' in progress`, 'bookmark'))
.then(issueTracker.setIssueStatus({ status: issueTracker.status.IN_PROGRESS }))
.then(stepCurried(4, 'Creating branch to work on issue', 'tada'))
.then(R.compose(wrapInPromise, git.createBranchName))
.then(stepCurried(4, name => `Creating branch '${name}'`, 'tada'))
.then(git.createIssueBranch(config))
))
.then(reporter.footer)
Expand Down
5 changes: 3 additions & 2 deletions src/git/local/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ export default {
})
.catch(throwControlledError(errors.git.couldNotInitializeRepo, { pathToRepo }));
},
createIssueBranch: R.curryN(2, (config, issue) => {
createBranchName,
createIssueBranch: R.curryN(2, (config, name) => {
debug('git', 'Creating branch for issue');
const name = createBranchName(issue);
const { remote, branch } = config.get(['git']);
debug('git', 'Fetching data from remote');
// We should fetch -> co master -> reset to origin/master -> create branch
Expand All @@ -76,6 +76,7 @@ export default {
))
.then(() => repository.checkoutBranch(name));
}),
getCurrentBranchName,
pushBranchToGithub: R.converge(
R.composeP(([remote, branch, { branchName, ref }]) => remote.push([ref], fetchOptions)
.then(() => Git.Branch.setUpstream(branch, `${remote.name()}/${branchName}`)),
Expand Down
19 changes: 17 additions & 2 deletions src/reporter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import readline from 'readline';
import emojis from 'node-emoji';
import R from 'ramda';
import read from 'read';
import { wrapInPromise } from '../util';

const stdout = process.stdout;
const startTime = Date.now();
Expand Down Expand Up @@ -34,13 +35,27 @@ const step = R.curryN(4, (total, current, msg, emojiStr) => {
});

const stepCurried = R.curryN(5, (total, current, msg, emojiStr, args) => {
step(total, current, msg, emojiStr);
step(
total,
current,
R.ifElse(R.is(Function), m => m(args), R.identity())(msg),
emojiStr
);
return args;
});

const stepCurriedP = R.curryN(5, (total, current, msg, emojiStr, args) => {
stepCurried(total, current, msg, emojiStr, args);
return Promise.resolve(args);
});

export default {
stepFactory(totalSteps) {
return { step: step(totalSteps), stepCurried: stepCurried(totalSteps) };
return {
step: step(totalSteps),
stepCurried: stepCurried(totalSteps),
stepCurriedP: stepCurriedP(totalSteps)
};
},
log,
info: (msg) => log(`${format.grey('info')} ${msg}`),
Expand Down

0 comments on commit 67c40a9

Please sign in to comment.