feat: working bitbar output
This commit is contained in:
23
.changelog_template.hbs
Normal file
23
.changelog_template.hbs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
### Changelog
|
||||||
|
|
||||||
|
{{#each releases}}
|
||||||
|
{{#if href}}
|
||||||
|
{{#if major}}
|
||||||
|
### [{{title}}]({{href}}) ({{niceDate}})
|
||||||
|
{{else}}
|
||||||
|
#### [{{title}}]({{href}}) ({{niceDate}})
|
||||||
|
{{/if}}
|
||||||
|
{{else}}
|
||||||
|
#### {{title}} ({{niceDate}})
|
||||||
|
{{/if}}
|
||||||
|
{{#each merges}}
|
||||||
|
- {{message}}{{#if href}} [`#{{id}}`]({{href}}){{/if}}
|
||||||
|
{{/each}}
|
||||||
|
{{#each fixes}}
|
||||||
|
- {{commit.subject}}{{#each fixes}}{{#if href}} [`#{{id}}`]({{href}}){{/if}}{{/each}}
|
||||||
|
{{/each}}
|
||||||
|
{{#each commits}}
|
||||||
|
- {{#matches message "BREAKING CHANGE"}}**Breaking:** {{/matches}}{{subject}}{{#if href}} [`{{shorthash}}`]({{href}}){{/if}}
|
||||||
|
{{/each}}
|
||||||
|
|
||||||
|
{{/each}}
|
||||||
41
.eslintrc
Normal file
41
.eslintrc
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
{
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 8,
|
||||||
|
"sourceType": "module"
|
||||||
|
},
|
||||||
|
"extends": [
|
||||||
|
"airbnb",
|
||||||
|
"prettier"
|
||||||
|
],
|
||||||
|
"plugins": [
|
||||||
|
"prettier",
|
||||||
|
"import"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"no-console": 0,
|
||||||
|
"prettier/prettier": "error",
|
||||||
|
"import/no-extraneous-dependencies": [
|
||||||
|
"error", {
|
||||||
|
"devDependencies": [
|
||||||
|
"test/**",
|
||||||
|
"packages/**/test/**",
|
||||||
|
"packages/**/*.test.js"
|
||||||
|
],
|
||||||
|
"optionalDependencies": false,
|
||||||
|
"peerDependencies": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"import/order": [
|
||||||
|
"error", {
|
||||||
|
"groups": [
|
||||||
|
"builtin",
|
||||||
|
"external",
|
||||||
|
"internal",
|
||||||
|
"parent",
|
||||||
|
"sibling",
|
||||||
|
"index"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
11
.gitignore
vendored
Normal file
11
.gitignore
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
node_modules
|
||||||
|
npm-debug.log
|
||||||
|
yarn-error.log
|
||||||
|
.DS_Store
|
||||||
|
.*.swp
|
||||||
|
.vscode
|
||||||
|
.env
|
||||||
|
coverage
|
||||||
|
.nyc_output
|
||||||
|
coverage.lcov
|
||||||
|
/lib
|
||||||
20
.travis.yml
Normal file
20
.travis.yml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
language: node_js
|
||||||
|
|
||||||
|
node_js:
|
||||||
|
- "stable"
|
||||||
|
- "8"
|
||||||
|
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- node_modules
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
email:
|
||||||
|
on_success: never
|
||||||
|
on_failure: change
|
||||||
|
|
||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- /^v[0-9].*$/
|
||||||
|
|
||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2018 Joe Fleming (https://github.com/w33ble)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
11
README.md
Normal file
11
README.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# github-info
|
||||||
|
|
||||||
|
Github info in your bitbar.
|
||||||
|
|
||||||
|
[](https://raw.githubusercontent.com/w33ble/github-info/master/LICENSE)
|
||||||
|
[](https://www.npmjs.com/package/github-info)
|
||||||
|
[](https://nodejs.org/api/documentation.html#documentation_stability_index)
|
||||||
|
|
||||||
|
#### License
|
||||||
|
|
||||||
|
MIT © [w33ble](https://github.com/w33ble)
|
||||||
5
index.js
Normal file
5
index.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
/* eslint no-global-assign: 0 */
|
||||||
|
require = require('esm')(module);
|
||||||
|
const mod = require('./src/index.mjs').default;
|
||||||
|
|
||||||
|
mod();
|
||||||
70
package.json
Normal file
70
package.json
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
{
|
||||||
|
"name": "github-info",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"description": "Github info in your bitbar",
|
||||||
|
"main": "index",
|
||||||
|
"module": "index.mjs",
|
||||||
|
"scripts": {
|
||||||
|
"lint": "eslint '*.{js,mjs}' 'src/**/*.{js,mjs}'",
|
||||||
|
"precommit": "lint-staged",
|
||||||
|
"version": "npm-auto-version",
|
||||||
|
"start": "node ."
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/w33ble/github-info.git"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"files": [
|
||||||
|
"src/",
|
||||||
|
"index.js",
|
||||||
|
"index.mjs",
|
||||||
|
"CHANGELOG.md",
|
||||||
|
"AUTHORS.md"
|
||||||
|
],
|
||||||
|
"author": "Joe Fleming (https://github.com/w33ble)",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/w33ble/github-info/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/w33ble/github-info",
|
||||||
|
"lint-staged": {
|
||||||
|
"ignore": [
|
||||||
|
"package.json"
|
||||||
|
],
|
||||||
|
"linters": {
|
||||||
|
"*.{js,mjs}": [
|
||||||
|
"eslint --fix"
|
||||||
|
],
|
||||||
|
"*.{js,mjs,json,css}": [
|
||||||
|
"prettier --write"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"prettier": {
|
||||||
|
"printWidth": 100,
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "es5"
|
||||||
|
},
|
||||||
|
"esm": {
|
||||||
|
"cjs": true
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"dotenv": "^6.2.0",
|
||||||
|
"esm": "^3.0.17",
|
||||||
|
"node-fetch": "^2.3.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@w33ble/npm-auto-tools": "*",
|
||||||
|
"eslint": "^4.9.0",
|
||||||
|
"eslint-config-airbnb": "^16.1.0",
|
||||||
|
"eslint-config-prettier": "^2.9.0",
|
||||||
|
"eslint-plugin-import": "^2.7.0",
|
||||||
|
"eslint-plugin-jsx-a11y": "^6.0.2",
|
||||||
|
"eslint-plugin-prettier": "^2.3.1",
|
||||||
|
"eslint-plugin-react": "^7.1.0",
|
||||||
|
"husky": "^0.14.3",
|
||||||
|
"lint-staged": "^7.0.4",
|
||||||
|
"prettier": "^1.9.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
121
src/index.mjs
Normal file
121
src/index.mjs
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
// <bitbar.title>Github Pull requests</bitbar.title>
|
||||||
|
// <bitbar.version>v2.0</bitbar.version>
|
||||||
|
// <bitbar.author>Noam Knispel</bitbar.author>
|
||||||
|
// <bitbar.author.github>noamknispel</bitbar.author.github>
|
||||||
|
// <bitbar.desc>Get list of pull requests from Github for multiple repositories</bitbar.desc>
|
||||||
|
// <bitbar.dependencies>node.js request co bluebird</bitbar.dependencies>
|
||||||
|
|
||||||
|
import dotenv from 'dotenv';
|
||||||
|
import nodeFetch, { FetchError } from 'node-fetch';
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
const username = process.env.GITHUB_USER;
|
||||||
|
const token = process.env.GITHUB_TOKEN;
|
||||||
|
const repos = process.env.GITHUB_REPOS.split(',');
|
||||||
|
|
||||||
|
const GITHUB_API = 'https://api.github.com';
|
||||||
|
|
||||||
|
// make fetch sane
|
||||||
|
const fetch = async (...args) => {
|
||||||
|
const res = await nodeFetch(...args);
|
||||||
|
if (res.ok) return res;
|
||||||
|
throw new FetchError(`Unsuccessful Request (${args[0]}) [${res.status}]`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getPull = async (repo, id) =>
|
||||||
|
fetch(`${GITHUB_API}/repos/${repo}/pulls/${id}`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
Authorization: `Basic ${Buffer.from(`${username}:${token}`).toString('base64')}`,
|
||||||
|
},
|
||||||
|
}).then(res => res.json());
|
||||||
|
|
||||||
|
const getPulls = async repo => {
|
||||||
|
const issues = await fetch(
|
||||||
|
`${GITHUB_API}/repos/${repo}/issues?state=open&sort=updated&creator=w33ble`,
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
Authorization: `Basic ${Buffer.from(`${username}:${token}`).toString('base64')}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
).then(res => res.json());
|
||||||
|
|
||||||
|
// remove non-pull issues
|
||||||
|
const pulls = issues.filter(issue => !!issue.pull_request);
|
||||||
|
|
||||||
|
// return actual pull info
|
||||||
|
return Promise.all(pulls.map(pull => getPull(repo, pull.number)));
|
||||||
|
};
|
||||||
|
|
||||||
|
const getStatus = async (repo, sha) =>
|
||||||
|
fetch(`${GITHUB_API}/repos/${repo}/commits/${sha}/status`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
Authorization: `Basic ${Buffer.from(`${username}:${token}`).toString('base64')}`,
|
||||||
|
},
|
||||||
|
}).then(res => res.json());
|
||||||
|
|
||||||
|
const getStatusColor = status => {
|
||||||
|
if (status === 'failure') return ' color=#aa0000';
|
||||||
|
if (status === 'success') return ' color=#00aa00';
|
||||||
|
if (status === 'pending') return ' color=#aaaa00';
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async () => {
|
||||||
|
let failed = false;
|
||||||
|
const tasks = await (() => {
|
||||||
|
try {
|
||||||
|
return Promise.all(
|
||||||
|
repos.map(async repo => {
|
||||||
|
// fetch pulls for repo
|
||||||
|
const pulls = await getPulls(repo);
|
||||||
|
|
||||||
|
// fetch status for each pull
|
||||||
|
return Promise.all(
|
||||||
|
pulls.map(async pull => {
|
||||||
|
const status = await getStatus(repo, pull.head.sha);
|
||||||
|
return { repo, pull, status };
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}, [])
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(`Request failed: ${err.message}`);
|
||||||
|
failed = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
if (failed) return false;
|
||||||
|
|
||||||
|
const { totalCount, failCount, strings } = tasks.reduce(
|
||||||
|
(acc, info) => {
|
||||||
|
// skip repo if there are no matches
|
||||||
|
if (info.length <= 0) return acc;
|
||||||
|
|
||||||
|
// build bitbar output
|
||||||
|
info.forEach(({ repo, pull, status }, i) => {
|
||||||
|
// append repo name
|
||||||
|
if (i === 0) acc.strings.push(`${repo} | color=#0000ff`);
|
||||||
|
|
||||||
|
// append information about each PR
|
||||||
|
acc.strings.push(
|
||||||
|
`#${pull.number} ${pull.title} | href=${pull.html_url} ${getStatusColor(status.state)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
// add count to tally
|
||||||
|
acc.totalCount += 1;
|
||||||
|
if (status.state === 'failure') acc.failCount += 1;
|
||||||
|
});
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
{ totalCount: 0, failCount: 0, strings: ['---'] }
|
||||||
|
);
|
||||||
|
|
||||||
|
strings.unshift(`${totalCount}/${failCount} PRs`);
|
||||||
|
strings.forEach(s => console.log(s));
|
||||||
|
return true;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user