├── .npmrc
├── .gitattributes
├── .gitignore
├── demo.gif
├── .editorconfig
├── .travis.yml
├── bin
├── post-install.js
└── index.js
├── license
├── test.js
├── package.json
├── readme.md
└── lib
└── index.js
/.npmrc:
--------------------------------------------------------------------------------
1 | package-lock=false
2 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto eol=lf
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | yarn.lock
3 | yarn-error.log
4 | .env
--------------------------------------------------------------------------------
/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rocktimsaikia/github-feed-cli/HEAD/demo.gif
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_style = tab
5 | end_of_line = lf
6 | charset = utf-8
7 | trim_trailing_whitespace = true
8 | insert_final_newline = true
9 |
10 | [*.yml]
11 | indent_style = space
12 | indent_size = 2
13 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | os:
3 | - windows
4 | - linux
5 | - osx
6 | node_js:
7 | - '14'
8 | - '12'
9 | - '10'
10 | before_install:
11 | - if [ "$TRAVIS_OS_NAME" = "linux" ]; then chmod +x ./bin/index.js ; fi
12 | - if [ "$TRAVIS_OS_NAME" = "osx" ]; then chmod +x ./bin/index.js ; fi
13 |
--------------------------------------------------------------------------------
/bin/post-install.js:
--------------------------------------------------------------------------------
1 | const chalk = require('chalk');
2 | const nodeEmoji = require('node-emoji');
3 |
4 | // Installation message
5 | console.log(`\n
6 | ${chalk.magenta.bold('Thanks for installing github-feed-cli!')}
7 | ${chalk.magenta('Run `feed --help` to get started')}
8 | ${chalk.blue(`If you enjoy using this tool, don't forget to star${nodeEmoji.get('star2')} the project at rocktimsaikia/github-feed-cli`)}
9 | \n`);
10 |
--------------------------------------------------------------------------------
/license:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Rocktim Saikia (https://rocktim.xyz) 2020
4 |
5 | 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:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | 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.
10 |
--------------------------------------------------------------------------------
/test.js:
--------------------------------------------------------------------------------
1 | import test from 'ava';
2 | import execa from 'execa';
3 |
4 | const randomName = () => `asdasfgrgafadsgaf${Math.random().toString().slice(2)}`;
5 |
6 | test('--version', async t => {
7 | const {stdout} = await execa('./bin/index.js', ['--version']);
8 | t.true(typeof stdout.length === 'number');
9 | });
10 |
11 | test('--help', async t => {
12 | const response = await execa('./bin/index.js', ['--help']);
13 | t.regex(response.stdout, /examples/i);
14 | });
15 |
16 | // test('without arguments', async t => {
17 | // const response = await execa('./bin/index.js');
18 | // t.true(response.exitCode === 0 && !response.failed);
19 | // });
20 |
21 | test('--user', async t => {
22 | const response = await execa('./bin/index.js',['--user', 'rocktimsaikia']);
23 | t.regex(response.stdout, /ago/);
24 | })
25 |
26 | test('--user && --page', async t => {
27 | const response = await execa('./bin/index.js',['--user', 'rocktimsaikia', '--page', 2]);
28 | t.regex(response.stdout, /ago/);
29 | })
30 |
31 | test('invalid --user argument', async t => {
32 | const response = await execa('./bin/index.js',['--user', randomName()]);
33 | t.regex(response.stderr, /user not found/i);
34 | })
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "github-feed-cli",
3 | "version": "1.4.0",
4 | "description": "Github feed right at your terminal",
5 | "keywords": [
6 | "github",
7 | "feed",
8 | "cli",
9 | "github-feed",
10 | "node-cli",
11 | "github-feed-cli"
12 | ],
13 | "repository": "RocktimSaikia/github-feed-cli",
14 | "license": "MIT",
15 | "author": {
16 | "name": "Rocktim Saikia",
17 | "email": "rocktimthedev@gmail.com",
18 | "url": "https://rocktim.xyz"
19 | },
20 | "bin": {
21 | "feed": "./bin/index.js"
22 | },
23 | "scripts": {
24 | "postinstall": "node bin/post-install.js",
25 | "test": "xo && ava"
26 | },
27 | "dependencies": {
28 | "@octokit/rest": "^18.0.6",
29 | "boxen": "^4.2.0",
30 | "chalk": "^4.1.0",
31 | "clean-deep": "^3.4.0",
32 | "dotenv": "^8.2.0",
33 | "lodash.isempty": "^4.4.0",
34 | "meow": "^7.1.1",
35 | "node-emoji": "^1.10.0",
36 | "ora": "^5.1.0",
37 | "read-git-user": "^2.0.0",
38 | "timeago.js": "^4.0.2",
39 | "update-notifier": "^5.0.0"
40 | },
41 | "devDependencies": {
42 | "ava": "2.4.0",
43 | "execa": "^4.0.3",
44 | "xo": "^0.33.1"
45 | },
46 | "xo": {
47 | "ignores": "./test.js"
48 | },
49 | "engines": {
50 | "node": ">=12"
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 |
2 |
github-feed-cli
3 | Github feed right at your terminal.
4 |
5 |
6 |
7 |
8 |
9 | 
10 |
11 | ## :sparkles: Highlights
12 |
13 | - Fast and Simple
14 | - Can be used to check the feed of any Github user
15 | - Also shows the notification events. ex: (Creating a issue, commenting, pushing codes etc)
16 | - Filters out `depandabot` events
17 | - Working in [all the OSS.](https://github.com/RocktimSaikia/github-feed-cli/runs/1241472881)
18 |
19 |
20 | ## Install
21 |
22 | ```bash
23 | $ npm install --global github-feed-cli
24 | ```
25 |
26 | If you are using `npm` version `5.2+` or higher then you can use this tool with `npx` too.
27 |
28 | ```bash
29 | $ npx feed
30 | ```
31 |
32 |
33 |
34 | ## Usage
35 |
36 | ```bash
37 | Usage
38 | $ feed
39 |
40 | Options
41 | --username, -u Github username to fetch the feed [default: Your own git username]
42 | --page, -p Page number of the results to fetch [default: 1]
43 | --version, -v Get the current version
44 |
45 | Examples
46 | $ feed
47 | $ feed --page 2
48 | $ feed --username rocktimsaikia
49 | $ feed --username rocktimsaikia -page 2
50 | ```
51 |
52 |
53 |
54 | ## Contribution
55 |
56 | If you want to add new feature or improve the existing ones of `github-feed-cli`, please [open an issue](https://github.com/rocktimsaikia/github-feed-cli/issues/new) :rocket:
57 |
58 |
59 | ## Related
60 |
61 | - [`read-git-user`](https://github.com/rocktimsaikia/read-git-user) - Reads the Github username and email from `.gitconfig` :wrench: and returns it as a json object
62 |
63 |
64 | ## License
65 |
66 | MIT © [Rocktim Saikia](https://rocktim.xyz)
67 |
--------------------------------------------------------------------------------
/bin/index.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | 'use strict';
3 |
4 | const chalk = require('chalk');
5 | const boxen = require('boxen');
6 | const updateNotifier = require('update-notifier');
7 | const nodeEmoji = require('node-emoji');
8 | const {format} = require('timeago.js');
9 | const meow = require('meow');
10 | const ora = require('ora');
11 |
12 | const readFeed = require('../lib');
13 |
14 | const cli = meow(
15 | `
16 | Usage
17 | $ feed
18 |
19 | Options
20 | --user, -u Github username to fetch the feed
21 | --page, -p Page number of the results to fetch (default 1)
22 | --version, -v Get the current version
23 |
24 | Examples
25 | $ feed
26 | $ feed -u rocktimsaikia
27 | $ feed -p 2
28 | $ feed -v
29 | `,
30 | {
31 | flags: {
32 | user: {
33 | type: 'string',
34 | alias: 'u'
35 | },
36 | page: {
37 | type: 'number',
38 | alias: 'p',
39 | default: 1
40 | },
41 | version: {
42 | type: 'boolean',
43 | alias: 'v'
44 | }
45 | }
46 | }
47 | );
48 |
49 | const formatFeedlog = ({actor, action: {postfix, event, icon, issueTitle, issueNumber}, repo, createdAt}) => {
50 | actor = chalk.white(chalk.bold(actor));
51 | postfix = chalk.white.dim(postfix);
52 | event = chalk.blue(event);
53 | repo = chalk.blue(repo);
54 | createdAt = chalk.white.dim(format(createdAt, 'en_us'));
55 | issueNumber = issueTitle === undefined ? '' : issueNumber;
56 | issueTitle = issueTitle === undefined ? '' : `\n\n${chalk.blue('i')}) ${chalk.underline(`${issueTitle} #${issueNumber}`)}`;
57 | const successTick = chalk.green(nodeEmoji.get('heavy_check_mark'));
58 | const log = `${successTick} ${actor} ${event}${icon} ${postfix} ${repo} ${createdAt}${issueTitle} `;
59 |
60 | return boxen(log, {
61 | margin: {left: 2},
62 | padding: 1,
63 | borderColor: 'magenta',
64 | borderStyle: 'round',
65 | dimBorder: true
66 | });
67 | };
68 |
69 | (async () => {
70 | const spinner = ora({
71 | text: 'Loading the feed...',
72 | color: 'magenta'
73 | }).start();
74 |
75 | try {
76 | const feedEvents = await readFeed({
77 | username: cli.flags.user,
78 | page: cli.flags.page
79 | });
80 |
81 | spinner.stop();
82 |
83 | feedEvents.map(activity => console.log(formatFeedlog(activity)));
84 | } catch (error) {
85 | spinner.stop();
86 | if (error.status === 404) {
87 | console.error(`${nodeEmoji.get('warning')} User not found! Please provide a valid github username.`);
88 | process.exit();
89 | }
90 |
91 | console.error(error);
92 | process.exit();
93 | } finally {
94 | updateNotifier({pkg: require('../package.json')}).notify();
95 | }
96 | })();
97 |
--------------------------------------------------------------------------------
/lib/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | require('dotenv').config();
3 | const {Octokit} = require('@octokit/rest');
4 | const isEmpty = require('lodash.isempty');
5 | const chalk = require('chalk');
6 | const nodeEmoji = require('node-emoji');
7 | const cleanDeep = require('clean-deep');
8 | const readUserName = require('read-git-user');
9 |
10 | const detectEventType = (type, payload) => {
11 | let event = {};
12 |
13 | switch (type) {
14 | case 'WatchEvent':
15 | event = {
16 | event: 'starred',
17 | postfix: '',
18 | icon: chalk.white(nodeEmoji.get('star2'))
19 | };
20 | break;
21 |
22 | case 'ForkEvent':
23 | event = {
24 | event: 'forked',
25 | postfix: '',
26 | icon: chalk.white(nodeEmoji.get('rocket'))
27 | };
28 | break;
29 |
30 | case 'PublicEvent':
31 | event = {
32 | event: 'made',
33 | postfix: 'public',
34 | icon: chalk.white(nodeEmoji.get('globe_with_meridians'))
35 | };
36 | break;
37 |
38 | case 'CreateEvent':
39 | event = {
40 | event: 'created',
41 | postfix: 'a repository',
42 | icon: chalk.white(nodeEmoji.get('pencil'))
43 | };
44 | break;
45 |
46 | case 'IssuesEvent':
47 | event = {
48 | event: 'openned',
49 | postfix: 'an issue in',
50 | issueNumber: payload.issue.number,
51 | issueTitle: payload.issue.title,
52 | icon: chalk.white(nodeEmoji.get('alarm_clock'))
53 | };
54 | break;
55 |
56 | case 'IssueCommentEvent':
57 | event = {
58 | event: 'commented',
59 | postfix: 'in an issue',
60 | issueNumber: payload.issue.number,
61 | issueTitle: payload.issue.title,
62 | commentBody: payload.comment.body,
63 | icon: chalk.white(nodeEmoji.get('speech_balloon'))
64 | };
65 | break;
66 |
67 | case 'PushEvent':
68 | event = {
69 | event: 'pushed',
70 | postfix: 'commits to',
71 | icon: nodeEmoji.get('sparkles')
72 | };
73 | break;
74 |
75 | case 'PullRequestEvent':
76 | event = {
77 | event: 'opened',
78 | postfix: 'a pull request in',
79 | icon: chalk.white(nodeEmoji.get('fire'))
80 | };
81 | break;
82 |
83 | case 'PullRequestReviewCommentEvent':
84 | event = {
85 | event: 'commented',
86 | postfix: `in PR #${payload.pull_request.number} of`,
87 | icon: chalk.white(nodeEmoji.get('speech_balloon'))
88 | };
89 | break;
90 |
91 | default:
92 | event = {};
93 | }
94 |
95 | return event;
96 | };
97 |
98 | module.exports = async options => {
99 | const username = options.username === undefined ? (await readUserName()).username : options.username;
100 | /**
101 | * @Todo
102 | * Adding auth token as argument is supported but not making it available in the cli version for now.
103 | */
104 | const octokit = new Octokit({
105 | auth: process.env.GITHUB_TOKEN
106 | });
107 |
108 | const feedActivites = await octokit.request('GET /users/{username}/received_events', {
109 | username,
110 | page: options.page
111 | });
112 |
113 | const updatedEvent = feedActivites.data.map(action => {
114 | let filteredEvents = {};
115 |
116 | const isDependabot = action.actor.display_login === 'dependabot';
117 | const isMemberEvent = action.type === 'MemberEvent';
118 |
119 | if (!isEmpty(action.payload) && !isDependabot && !isMemberEvent) {
120 | filteredEvents = {
121 | actor: action.actor.display_login,
122 | repo: action.repo.name,
123 | action: detectEventType(action.type, action.payload),
124 | createdAt: action.created_at
125 | };
126 | }
127 |
128 | return filteredEvents;
129 | }).reverse();
130 |
131 | return cleanDeep(updatedEvent, {emptyStrings: false});
132 | };
133 |
--------------------------------------------------------------------------------