Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Limit repository listing output based on stdout.isTTY #408

Merged
merged 1 commit into from
Sep 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ exports.setUp = function () {
var iterativeValues,
remoteUrl = git.getRemoteUrl(options.remote);

options.isTTY = {};
options.isTTY.in = Boolean(process.stdin.isTTY);
options.isTTY.out = Boolean(process.stdout.isTTY);
options.loggedUser = base.getUser();
options.remoteUser = git.getUserFromRemoteUrl(remoteUrl);

Expand Down
43 changes: 24 additions & 19 deletions lib/cmds/repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Repo.DETAILS = {
'organization': String,
'private': Boolean,
'repo': String,
'type': ['all', 'member', 'owner', 'public', 'private'],
'type': ['all', 'forks', 'member', 'owner', 'public', 'private', 'sources'],
'user': String
},
shorthands: {
Expand All @@ -78,10 +78,12 @@ Repo.DETAILS = {
};

Repo.TYPE_ALL = 'all';
Repo.TYPE_FORKS = 'forks';
Repo.TYPE_MEMBER = 'member';
Repo.TYPE_OWNER = 'owner';
Repo.TYPE_PRIVATE = 'private';
Repo.TYPE_PUBLIC = 'public';
Repo.TYPE_SOURCES = 'sources';

// -- Commands -------------------------------------------------------------------------------------

Expand All @@ -90,8 +92,6 @@ Repo.prototype.run = function() {
options = instance.options,
user = options.loggedUser;

options.type = options.type || Repo.TYPE_ALL;

if (options.browser) {
instance.browser(options.user, options.repo);
}
Expand Down Expand Up @@ -154,14 +154,19 @@ Repo.prototype.run = function() {
}

if (options.list) {
user = options.user;

if (options.organization) {
user = options.organization;
options.type = options.type || Repo.TYPE_ALL;
} else {
user = options.user;
options.type = options.type || Repo.TYPE_OWNER;
}

if (options.isTTY.out) {
logger.log('Listing ' + logger.colors.green(options.type) + ' repos for ' +
logger.colors.green(user));
}

logger.log('Listing ' + logger.colors.green(options.type) + ' repos for ' +
logger.colors.green(user));

instance.list(user, function(err) {
if (err) {
Expand Down Expand Up @@ -235,20 +240,18 @@ Repo.prototype.list = function(user, opt_callback) {
}

if (options.type === 'public' || options.type === 'private') {
if (user !== options.user) {
logger.error('You can only list public and private repos of your own.');
if (user === options.user) {
method = 'getAll';
}
else {
base.github.repos.getAll(payload, function(err, repos) {
instance.listCallback_(err, repos, opt_callback);
});
logger.error('You can only list your own public and private repos of your own.');
return;
}
}
else {
base.github.repos[method](payload, function(err, repos) {
instance.listCallback_(err, repos, opt_callback);
});
}

base.github.repos[method](payload, function(err, repos) {
instance.listCallback_(err, repos, opt_callback);
});
};

Repo.prototype.listCallback_ = function(err, repos, opt_callback) {
Expand Down Expand Up @@ -281,8 +284,10 @@ Repo.prototype.listCallback_ = function(err, repos, opt_callback) {
logger.log('last update ' + logger.getDuration(repo.updated_at));
}

logger.log(logger.colors.green('forks: ' + repo.forks +
', stars: ' + repo.watchers + ', issues: ' + repo.open_issues) + '\n');
if (options.isTTY.out) {
logger.log(logger.colors.green('forks: ' + repo.forks +
', stars: ' + repo.watchers + ', issues: ' + repo.open_issues) + '\n');
}
}
}

Expand Down