Skip to content

Commit ec97be0

Browse files
authored
Merge pull request #244 from ashutosh1919/github-token-in-env
Add .env to the Project For Github Token
2 parents 6e6cdf0 + c707216 commit ec97be0

File tree

5 files changed

+25
-18
lines changed

5 files changed

+25
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
# misc
1515
.DS_Store
16+
.env
1617
.env.local
1718
.env.development.local
1819
.env.test.local

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ To view a live example, **[click here](https://ashutosh1919.github.io/)**
5050
- While installing `nodejs` and `npm`, try to install versions which are equal or greater than the versions mentioned in badges above
5151
- In case you want to help developing it or simply saving it, you can fork the repository just by clicking the button on the top-right corner of this page
5252
- After the successful installation of `nodejs` and `npm`, clone the repository into your local system using below command:
53-
```bash
54-
git clone https://github.com/ashutosh1919/masterPortfolio.git
55-
```
56-
This will clone the whole repository in your system.
53+
```bash
54+
git clone https://github.com/ashutosh1919/masterPortfolio.git
55+
```
56+
This will clone the whole repository in your system.
5757
- To download required dependencies to your system, navigate to the directory where the cloned repository resides and execute following command:
58-
```node
59-
npm install
60-
```
58+
```node
59+
npm install
60+
```
6161
- Now the project is ready to use
6262
- You can check it using `npm start`, it will open the website locally on your browser.
6363

@@ -100,17 +100,17 @@ You can change the personal information, experience, education, social media, ce
100100
### Github Information
101101

102102
You will find `git_data_fetcher.mjs` file in the main directory of the repository. This file is used to fetch the data (Pull requests, Issues, Organizations, Pinned projects etc.) from your github.
103-
If you open the file, you will see below component at the top of the file. You need to change only that component.
103+
104+
In the project you will see a `env.example` file, create a new file named `.env` and copy contents of `env.example` into it. In that file, you will see the following environment variables
104105

105106
```javascript
106-
const openSource = {
107-
githubConvertedToken: "Your Github Token Here.",
108-
githubUserName: "Your Github Username Here.",
109-
};
107+
GITHUB_TOKEN = your_token;
108+
GITHUB_USERNAME = your_username;
110109
```
111110

112-
You can get a github token as described [here](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). Give all permissions while generating token. Also add your `githubUserName` in the correct field inside `git_data_fetcher.mjs`.
113-
Now, you need to run following command.
111+
You can get a github token as described [here](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). Give all permissions while generating token. Add your github username and the token generated in `GITHUB_USERNAME` and `GITHUB_TOKEN` variables in the .env file.
112+
113+
Now, you need to run following command. (Make sure you executed `npm install` before this)
114114

115115
**Warning:** Treat your tokens like passwords and keep them secret. When working with the API, use tokens as environment variables instead of hardcoding them into your programs.
116116

env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GITHUB_TOKEN=your_token
2+
GITHUB_USERNAME=your_username

git_data_fetcher.mjs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import fetch from 'node-fetch';
2-
import fs from 'fs';
1+
import fetch from "node-fetch";
2+
import fs from "fs";
3+
import dotenv from "dotenv";
4+
5+
dotenv.config();
36

47
const openSource = {
5-
githubConvertedToken: "Your Github Token Here",
6-
githubUserName: "Your Github Username Here",
8+
githubConvertedToken: process.env.GITHUB_TOKEN,
9+
githubUserName: process.env.GITHUB_USERNAME,
710
};
811

912
const query_pr = {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"devDependencies": {
4040
"@iconify/icons-logos": "^1.0.9",
4141
"@iconify/react": "^1.1.1",
42+
"dotenv": "^6.2.0",
4243
"husky": "^4.2.5",
4344
"lint-staged": "^10.2.11",
4445
"prettier": "2.0.5"

0 commit comments

Comments
 (0)