Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# github-manager-cli [![Build Status](https://travis-ci.org/99xt/github-manager-cli.svg?branch=master)](https://travis-ci.org/99xt/github-manager-cli) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/33e92f8ba07748a987da853e90aa3f55)](https://www.codacy.com/app/99xt/github-manager-cli?utm_source=github.com&utm_medium=referral&utm_content=99xt/github-manager-cli&utm_campaign=Badge_Grade)
# github-manager-cli [![Build Status](https://travis-ci.org/99xt/github-manager-cli.svg?branch=master)](https://travis-ci.org/99xt/github-manager-cli) [![npm dependencies](https://david-dm.org/99xt/github-manager-cli.svg)](https://david-dm.org/99xt/github-manager-cli.svg) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/33e92f8ba07748a987da853e90aa3f55)](https://www.codacy.com/app/99xt/github-manager-cli?utm_source=github.com&utm_medium=referral&utm_content=99xt/github-manager-cli&utm_campaign=Badge_Grade) [![Open Source Love](https://badges.frapsoft.com/os/mit/mit.svg?v=102)](https://github.com/ellerbrock/open-source-badge/)

## What's github-manager-cli ?

Expand Down
46 changes: 44 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const GitHubApi = require("github");
const gitHubApi = require("github");
const Promise = require('bluebird');
const inquirer = require('inquirer');
const fs = require('fs');
const predefinedLabels = require('./config/labels');

const github = new GitHubApi({
//initialize GitHub API from node-github
const github = new gitHubApi({
debug: false,
protocol: "https",
host: "api.github.com",
Expand All @@ -17,6 +18,7 @@ const github = new GitHubApi({
timeout: 5000
});

//Promisify github API with Bluebird
Promise.promisifyAll(github.authorization);
Promise.promisifyAll(github.issues);
Promise.promisifyAll(github.repos);
Expand All @@ -28,6 +30,14 @@ function getRepositories(user) {
});
}

/**
* create label
* @param {string} repository - repo name
* @param {string} owner - repo owner
* @param {string} name - label name
* @param {string} color - label color without `#`
*/

function createLabel(repository, owner, name, color) {
return github.issues.createLabel({
owner: owner,
Expand All @@ -48,20 +58,40 @@ function createLabel(repository, owner, name, color) {
});
}

/**
* get issues
* @param {string} repository - repo name
* @param {string} owner - repo owner
*/

function getIssues(repository, owner) {
return github.issues.getForRepo({
owner: owner,
repo: repository.name
}).each(issue => issue.repo = repository);
}

/**
* get labels
* @param {string} repository - repo name
* @param {string} owner - repo owner
*/

function getLabels(repository, owner) {
return github.issues.getLabels({
owner: owner,
repo: repository.name
}).map(label => ({name: label.name, color: label.color}));
}

/**
* add labels
* @param {string} repository - repo name
* @param {string} owner - repo owner
* @param {string} name - label name
* @param {string} color - label color without `#`
*/

function addLabels(repository, issue, owner, labels) {
return github.issues.addLabels({
owner: owner,
Expand All @@ -71,6 +101,10 @@ function addLabels(repository, issue, owner, labels) {
});
}

/**
* login to GitHub
*/

function loginBasic() {
return inquirer.prompt([
{
Expand All @@ -92,6 +126,10 @@ function loginBasic() {
});
}

/**
* retrieve login token
*/

function loginToken() {
return new Promise(function (resolve, reject) {
fs.readFile('.access-token', function (error, token) {
Expand All @@ -104,6 +142,10 @@ function loginToken() {
});
}

/**
* create token
*/

function createToken() {
return inquirer.prompt([
{
Expand Down