diff --git a/index.js b/index.js
index 8f8cc10..8ee32f7 100644
--- a/index.js
+++ b/index.js
@@ -2,4 +2,4 @@
require = require('esm')(module);
const mod = require('./src/index.mjs').default;
-mod();
+module.exports = mod;
diff --git a/index.mjs b/index.mjs
index ab478a1..5329a9f 100644
--- a/index.mjs
+++ b/index.mjs
@@ -1,3 +1,3 @@
import mod from './src/index.mjs';
-mod();
+export default mod;
diff --git a/package.json b/package.json
index ef2aeb5..8149ae0 100644
--- a/package.json
+++ b/package.json
@@ -50,7 +50,6 @@
"cjs": true
},
"dependencies": {
- "dotenv": "^6.2.0",
"esm": "^3.0.17",
"node-fetch": "^2.3.0"
},
diff --git a/src/index.mjs b/src/index.mjs
index 88bc585..31f1770 100644
--- a/src/index.mjs
+++ b/src/index.mjs
@@ -5,15 +5,8 @@
// Get list of pull requests from Github for multiple repositories
// node.js request co bluebird
-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
@@ -23,39 +16,43 @@ const fetch = async (...args) => {
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`,
- {
+const api = ({ username, token }) => {
+ 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());
+ }).then(res => res.json());
- // remove non-pull issues
- const pulls = issues.filter(issue => !!issue.pull_request);
+ return {
+ 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());
- // return actual pull info
- return Promise.all(pulls.map(pull => getPull(repo, pull.number)));
-};
+ // remove non-pull issues
+ const pulls = issues.filter(issue => !!issue.pull_request);
-const getStatus = async (repo, sha) =>
- fetch(`${GITHUB_API}/repos/${repo}/commits/${sha}/status`, {
- method: 'GET',
- headers: {
- Authorization: `Basic ${Buffer.from(`${username}:${token}`).toString('base64')}`,
+ // return actual pull info
+ return Promise.all(pulls.map(pull => getPull(repo, pull.number)));
},
- }).then(res => res.json());
+
+ 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';
@@ -64,7 +61,9 @@ const getStatusColor = status => {
return '';
};
-export default async () => {
+export default async ({ username, token, repos = [] }) => {
+ const { getPulls, getStatus } = api({ username, token });
+
let failed = false;
const tasks = await (() => {
try {
diff --git a/yarn.lock b/yarn.lock
index 79798d8..4028db0 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -551,11 +551,6 @@ doctrine@^2.1.0:
dependencies:
esutils "^2.0.2"
-dotenv@^6.2.0:
- version "6.2.0"
- resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-6.2.0.tgz#941c0410535d942c8becf28d3f357dbd9d476064"
- integrity sha512-HygQCKUBSFl8wKQZBSemMywRWcEDNidvNbjGVyZu3nbZ8qq9ubiPoGLMdRDpfSrpkkm9BXYFkpKxxFX38o/76w==
-
elegant-spinner@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/elegant-spinner/-/elegant-spinner-1.0.1.tgz#db043521c95d7e303fd8f345bedc3349cfb0729e"