Skip to content
This repository was archived by the owner on Apr 11, 2022. It is now read-only.

Commit 9d55276

Browse files
committed
init
0 parents  commit 9d55276

14 files changed

+392
-0
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.github/FUNDING.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
patreon: "rocktim"
2+
custom: ["buymeacoffee.com/7BdaxfI"]

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
yarn.lock
3+
yarn-error.log
4+
.env

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: node_js
2+
node_js:
3+
- '14'
4+
- '12'
5+
- '10'

bin/index.js

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
4+
const chalk = require('chalk');
5+
const boxen = require('boxen');
6+
const logSymbols = require('log-symbols');
7+
const {format} = require('timeago.js');
8+
const meow = require('meow');
9+
const ora = require('ora');
10+
const readUserName = require('git-user-name');
11+
12+
const readFeed = require('../lib');
13+
14+
const cli = meow(
15+
`
16+
Usage
17+
$ feed <options>
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+
default: readUserName()
36+
},
37+
page: {
38+
type: 'number',
39+
alias: 'p',
40+
default: 1
41+
},
42+
version: {
43+
type: 'boolean',
44+
alias: 'v'
45+
}
46+
}
47+
}
48+
);
49+
50+
const formatFeedlog = ({actor, action: {postfix, event, icon, issueTitle, issueNumber}, repo, createdAt}) => {
51+
actor = chalk.white(chalk.bold(actor));
52+
postfix = chalk.white.dim(postfix);
53+
event = chalk.blue(event);
54+
repo = chalk.blue(repo);
55+
createdAt = chalk.white.dim(format(createdAt, 'en_us'));
56+
issueNumber = issueTitle === undefined ? '' : issueNumber;
57+
issueTitle = issueTitle === undefined ? '' : `\n\n${logSymbols.info}) ${chalk.underline(`${issueTitle} #${issueNumber}`)}`;
58+
59+
const log = `\n${logSymbols.success} ${actor} ${event}${icon} ${postfix} ${repo} ${createdAt}${issueTitle}\n`;
60+
61+
return boxen(log, {
62+
margin: {left: 2},
63+
padding: {left: 1, right: 1},
64+
borderColor: 'magenta',
65+
borderStyle: 'round',
66+
dimBorder: true
67+
});
68+
};
69+
70+
(async () => {
71+
const spinner = ora({
72+
text: 'Loading the feed...',
73+
color: 'magenta'
74+
}).start();
75+
76+
try {
77+
const feedEvents = await readFeed({
78+
username: cli.flags.user,
79+
page: cli.flags.page
80+
});
81+
82+
spinner.stop();
83+
84+
feedEvents.map(activity => console.log(formatFeedlog(activity)));
85+
} catch (error) {
86+
if (error.status === 404) {
87+
console.error('User not found! Please provide a valid github username.');
88+
}
89+
90+
console.error(error);
91+
}
92+
})();

bin/post-install.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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`);

demo.gif

2.49 MB
Loading

lib/index.js

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
'use strict';
2+
const {Octokit} = require('@octokit/rest');
3+
const isEmpty = require('lodash.isempty');
4+
const chalk = require('chalk');
5+
const nodeEmoji = require('node-emoji');
6+
const cleanDeep = require('clean-deep');
7+
8+
const detectEventType = (type, payload) => {
9+
let event = {};
10+
11+
switch (type) {
12+
case 'WatchEvent':
13+
event = {
14+
event: 'starred',
15+
postfix: '',
16+
icon: chalk.white(nodeEmoji.get('star2'))
17+
};
18+
break;
19+
20+
case 'ForkEvent':
21+
event = {
22+
event: 'forked',
23+
postfix: '',
24+
icon: chalk.white(nodeEmoji.get('rocket'))
25+
};
26+
break;
27+
28+
case 'PublicEvent':
29+
event = {
30+
event: 'made',
31+
postfix: 'public',
32+
icon: chalk.white(nodeEmoji.get('globe_with_meridians'))
33+
};
34+
break;
35+
36+
case 'CreateEvent':
37+
event = {
38+
event: 'created',
39+
postfix: 'a repository',
40+
icon: chalk.white(nodeEmoji.get('pencil'))
41+
};
42+
break;
43+
44+
case 'IssuesEvent':
45+
event = {
46+
event: 'openned',
47+
postfix: 'an issue in',
48+
issueNumber: payload.issue.number,
49+
issueTitle: payload.issue.title,
50+
icon: chalk.white(nodeEmoji.get('alarm_clock'))
51+
};
52+
break;
53+
54+
case 'IssueCommentEvent':
55+
event = {
56+
event: 'commented',
57+
postfix: 'in an issue',
58+
issueNumber: payload.issue.number,
59+
issueTitle: payload.issue.title,
60+
commentBody: payload.comment.body,
61+
icon: chalk.white(nodeEmoji.get('speech_balloon'))
62+
};
63+
break;
64+
65+
case 'PushEvent':
66+
event = {
67+
event: 'pushed',
68+
postfix: 'commits to',
69+
icon: nodeEmoji.get('sparkles')
70+
};
71+
break;
72+
73+
case 'PullRequestEvent':
74+
event = {
75+
event: 'opened',
76+
postfix: 'a pull request in',
77+
icon: chalk.white(nodeEmoji.get('fire'))
78+
};
79+
break;
80+
81+
default:
82+
event = {};
83+
}
84+
85+
return event;
86+
};
87+
88+
module.exports = async options => {
89+
/**
90+
* @Todo
91+
* Adding auth token as argument is supported but not making it available in the cli version for now.
92+
*/
93+
const octokit = new Octokit();
94+
95+
const feedActivites = await octokit.request('GET /users/{username}/received_events', {
96+
username: options.username,
97+
page: options.page
98+
});
99+
100+
const updatedEvent = feedActivites.data.map(action => {
101+
let filteredEvents = {};
102+
103+
if (!isEmpty(action.payload)) {
104+
filteredEvents = {
105+
actor: action.actor.display_login,
106+
repo: action.repo.name,
107+
action: detectEventType(action.type, action.payload),
108+
createdAt: action.created_at
109+
};
110+
}
111+
112+
return filteredEvents;
113+
}).reverse();
114+
115+
return cleanDeep(updatedEvent, {emptyStrings: false});
116+
};

license

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) Rocktim Saikia <[email protected]> (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.

package.json

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "github-feed-cli",
3+
"version": "0.0.2",
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": "[email protected]",
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+
"devDependencies": {
28+
"ava": "2.4.0",
29+
"execa": "^4.0.3",
30+
"xo": "^0.33.1"
31+
},
32+
"engines": {
33+
"node": ">=12"
34+
},
35+
"dependencies": {
36+
"@octokit/rest": "^18.0.6",
37+
"boxen": "^4.2.0",
38+
"chalk": "^4.1.0",
39+
"clean-deep": "^3.4.0",
40+
"git-user-name": "^2.0.0",
41+
"lodash.isempty": "^4.4.0",
42+
"log-symbols": "^4.0.0",
43+
"meow": "^7.1.1",
44+
"node-emoji": "^1.10.0",
45+
"ora": "^5.1.0",
46+
"timeago.js": "^4.0.2"
47+
},
48+
"xo": {
49+
"ignores": "./test.js"
50+
}
51+
}

readme.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<p align="center">
2+
<h1 align="center">github-feed-cli</h1>
3+
<p align="center">Github feed right at your terminal.<p>
4+
<p align="center">
5+
<a href="https://travis-ci.com/rocktimsaikia/github-feed-cli"><img src="https://travis-ci.org/rocktimsaikia/github-feed-cli.svg?branch=master" alt="Build Status"></a>
6+
<a href="https://github.com/sindresorhus/xo"><img src="https://img.shields.io/badge/code_style-XO-5ed9c7.svg" alt="Code Style"></a>
7+
</p>
8+
</p>
9+
<p align="center"><img src="https://rawcdn.githack.com/rocktimsaikia/github-feed-cli/master/demo.gif" alt="gif" height="500"></p>
10+
11+
## :sparkles: Highlights
12+
13+
* Fast and Simple
14+
* Check the feed of any Github user
15+
* Also shows the notification events. ex: (Creating a issue, commenting, pushing codes etc)
16+
<br><br>
17+
18+
## Install
19+
```bash
20+
$ npm install --global github-feed-cli
21+
```
22+
<br>
23+
24+
## Usage
25+
26+
```bash
27+
Usage
28+
$ feed <options>
29+
30+
Options
31+
--username, -u Github username to fetch the feed [default: Your own git username]
32+
--page, -p Page number of the results to fetch [default: 1]
33+
--version, -v Get the current version
34+
35+
Examples
36+
$ feed
37+
$ feed --page 2
38+
$ feed --username rocktimsaikia
39+
$ feed --username rocktimsaikia -page 2
40+
```
41+
<br>
42+
43+
## Contribution
44+
45+
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:<br>
46+
<br>
47+
48+
## Related
49+
50+
- [`read-packages`](https://github.com/RocktimSaikia/read-packages) - Read dependencies of a package.json file
51+
- [`package-outdated`](https://github.com/RocktimSaikia/package-outdated) - Returns the outdated packages of a package.json file
52+
<br>
53+
54+
## Support
55+
56+
<a href="https://www.buymeacoffee.com/7BdaxfI"><img src="https://user-images.githubusercontent.com/33410545/95193575-a3b51b00-07f1-11eb-9bbb-90ea2e1018d7.png" height="60px"/></a>

0 commit comments

Comments
 (0)