Skip to content

Commit 084b836

Browse files
authored
Merge pull request #22 from secure-dashboards/feat/add-support-for-secrets
2 parents 96dd002 + fc28ad2 commit 084b836

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This is an evolution of [this proof of concept (POC)](https://github.com/UlisesG
66

77
- Node.js 22 and npm
88
- Docker and Docker Compose
9+
- Github token with repo:read level access.
910

1011
## Infrastructure
1112

@@ -28,6 +29,23 @@ To stop the infrastructure, run the following command:
2829
npm run infra:stop
2930
```
3031

32+
## Configuration
33+
34+
### Environment Variables
35+
36+
This project requires a GitHub token to access the GitHub API. You need to set the `GITHUB_TOKEN` environment variable.
37+
38+
#### Optional: use .env file
39+
40+
Create a `.env` file and add your GitHub token:
41+
42+
```sh
43+
GITHUB_TOKEN=your_github_token_here
44+
```
45+
46+
then use `--env-file` flag to load it, like `node --env-file=.env index.js workflow run --name populate-repos-list`
47+
48+
3149
## Database Management
3250

3351
### Running Migrations

__tests__/utils.test.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
1-
const { validateGithubUrl } = require('../src/utils/index')
1+
const { validateGithubUrl, ensureGithubToken } = require('../src/utils/index')
2+
3+
describe('ensureGithubToken', () => {
4+
let originalGithubToken
5+
6+
beforeAll(() => {
7+
originalGithubToken = process.env.GITHUB_TOKEN
8+
})
9+
10+
afterAll(() => {
11+
process.env.GITHUB_TOKEN = originalGithubToken
12+
})
13+
14+
it('should throw an error if GITHUB_TOKEN is required', () => {
15+
delete process.env.GITHUB_TOKEN
16+
expect(() => ensureGithubToken()).toThrow('GITHUB_TOKEN is required')
17+
})
18+
19+
it('should not throw an error if GITHUB_TOKEN is set', () => {
20+
process.env.GITHUB_TOKEN = 'test-token'
21+
expect(() => ensureGithubToken()).not.toThrow()
22+
})
23+
})
224

325
describe('validateGithubUrl', () => {
426
it('should return true for a valid GitHub URL', () => {

src/utils/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ const isURL = require('validator/lib/isURL.js')
22

33
const validateGithubUrl = (url) => isURL(url, { protocols: ['https'], require_protocol: true }) && url.includes('github.com')
44

5+
const ensureGithubToken = () => {
6+
if (!process.env.GITHUB_TOKEN) {
7+
throw new Error('GITHUB_TOKEN is required')
8+
}
9+
}
10+
511
module.exports = {
6-
validateGithubUrl
12+
validateGithubUrl,
13+
ensureGithubToken
714
}

0 commit comments

Comments
 (0)