@@ -4,6 +4,10 @@ import * as engine from './engine';
4
4
5
5
describe ( 'engine' , ( ) => {
6
6
describe ( 'prepareOptions' , ( ) => {
7
+ beforeEach ( ( ) => {
8
+ process . env = { } ;
9
+ } ) ;
10
+
7
11
it ( 'should replace the string GH_TOKEN in the repo url (for backwards compatibility)' , ( ) => {
8
12
const options = {
9
13
repo :
'https://[email protected] /organisation/your-repo.git'
@@ -16,15 +20,56 @@ describe('engine', () => {
16
20
) ;
17
21
} ) ;
18
22
19
- it ( 'should add a GH_TOKEN to the repo url' , ( ) => {
23
+ // see https://github.com/EdricChan03/rss-reader/commit/837dc10c18bfa453c586bb564a662e7dad1e68ab#r36665276 as an example
24
+ it ( 'should be possible to use GH_TOKEN in repo url as a workaround for other tokens (for backwards compatibility)' , ( ) => {
25
+ const options = {
26
+ repo :
27
+ 'https://x-access-token:[email protected] /organisation/your-repo.git'
28
+ } ;
29
+ process . env . GH_TOKEN = 'XXX' ;
30
+ const finalOptions = engine . prepareOptions ( options , new NullLogger ( ) ) ;
31
+
32
+ expect ( finalOptions . repo ) . toBe (
33
+ 'https://x-access-token:[email protected] /organisation/your-repo.git'
34
+ ) ;
35
+ } ) ;
36
+
37
+ // ----
38
+
39
+ it ( 'should also add a personal access token (GH_TOKEN) to the repo url' , ( ) => {
20
40
const options = {
21
41
repo : 'https://github.com/organisation/your-repo.git'
22
42
} ;
23
43
process . env . GH_TOKEN = 'XXX' ;
24
44
const finalOptions = engine . prepareOptions ( options , new NullLogger ( ) ) ;
25
45
26
46
expect ( finalOptions . repo ) . toBe (
27
- 'https://[email protected] /organisation/your-repo.git'
47
+ 'https://x-access-token:[email protected] /organisation/your-repo.git'
48
+ ) ;
49
+ } ) ;
50
+
51
+ it ( 'should also add a personal access token (PERSONAL_TOKEN) to the repo url' , ( ) => {
52
+ const options = {
53
+ repo : 'https://github.com/organisation/your-repo.git'
54
+ } ;
55
+ process . env . PERSONAL_TOKEN = 'XXX' ;
56
+ const finalOptions = engine . prepareOptions ( options , new NullLogger ( ) ) ;
57
+
58
+ expect ( finalOptions . repo ) . toBe (
59
+ 'https://x-access-token:[email protected] /organisation/your-repo.git'
60
+ ) ;
61
+ } ) ;
62
+
63
+ it ( 'should also add a installation access token (GITHUB_TOKEN) to the repo url' , ( ) => {
64
+ debugger ;
65
+ const options = {
66
+ repo : 'https://github.com/organisation/your-repo.git'
67
+ } ;
68
+ process . env . GITHUB_TOKEN = 'XXX' ;
69
+ const finalOptions = engine . prepareOptions ( options , new NullLogger ( ) ) ;
70
+
71
+ expect ( finalOptions . repo ) . toBe (
72
+ 'https://x-access-token:[email protected] /organisation/your-repo.git'
28
73
) ;
29
74
} ) ;
30
75
} ) ;
0 commit comments