diff --git a/README.md b/README.md index 9fd357a..f244ae4 100644 --- a/README.md +++ b/README.md @@ -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 ? diff --git a/index.js b/index.js index 0056a2b..612a583 100644 --- a/index.js +++ b/index.js @@ -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", @@ -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); @@ -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, @@ -48,6 +58,12 @@ 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, @@ -55,6 +71,12 @@ function getIssues(repository, owner) { }).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, @@ -62,6 +84,14 @@ function getLabels(repository, owner) { }).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, @@ -71,6 +101,10 @@ function addLabels(repository, issue, owner, labels) { }); } +/** + * login to GitHub + */ + function loginBasic() { return inquirer.prompt([ { @@ -92,6 +126,10 @@ function loginBasic() { }); } +/** + * retrieve login token + */ + function loginToken() { return new Promise(function (resolve, reject) { fs.readFile('.access-token', function (error, token) { @@ -104,6 +142,10 @@ function loginToken() { }); } +/** + * create token + */ + function createToken() { return inquirer.prompt([ {