File tree Expand file tree Collapse file tree 3 files changed +49
-2
lines changed Expand file tree Collapse file tree 3 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ This is an evolution of [this proof of concept (POC)](https://github.com/UlisesG
6
6
7
7
- Node.js 22 and npm
8
8
- Docker and Docker Compose
9
+ - Github token with repo: read level access.
9
10
10
11
## Infrastructure
11
12
@@ -28,6 +29,23 @@ To stop the infrastructure, run the following command:
28
29
npm run infra:stop
29
30
```
30
31
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
+
31
49
## Database Management
32
50
33
51
### Running Migrations
Original file line number Diff line number Diff line change 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
+ } )
2
24
3
25
describe ( 'validateGithubUrl' , ( ) => {
4
26
it ( 'should return true for a valid GitHub URL' , ( ) => {
Original file line number Diff line number Diff line change @@ -2,6 +2,13 @@ const isURL = require('validator/lib/isURL.js')
2
2
3
3
const validateGithubUrl = ( url ) => isURL ( url , { protocols : [ 'https' ] , require_protocol : true } ) && url . includes ( 'github.com' )
4
4
5
+ const ensureGithubToken = ( ) => {
6
+ if ( ! process . env . GITHUB_TOKEN ) {
7
+ throw new Error ( 'GITHUB_TOKEN is required' )
8
+ }
9
+ }
10
+
5
11
module . exports = {
6
- validateGithubUrl
12
+ validateGithubUrl,
13
+ ensureGithubToken
7
14
}
You can’t perform that action at this time.
0 commit comments