@@ -4,6 +4,10 @@ import * as engine from './engine';
44
55describe ( 'engine' , ( ) => {
66 describe ( 'prepareOptions' , ( ) => {
7+ beforeEach ( ( ) => {
8+ process . env = { } ;
9+ } ) ;
10+
711 it ( 'should replace the string GH_TOKEN in the repo url (for backwards compatibility)' , ( ) => {
812 const options = {
913 repo :
'https://[email protected] /organisation/your-repo.git' @@ -16,15 +20,56 @@ describe('engine', () => {
1620 ) ;
1721 } ) ;
1822
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' , ( ) => {
2040 const options = {
2141 repo : 'https://github.com/organisation/your-repo.git'
2242 } ;
2343 process . env . GH_TOKEN = 'XXX' ;
2444 const finalOptions = engine . prepareOptions ( options , new NullLogger ( ) ) ;
2545
2646 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' 2873 ) ;
2974 } ) ;
3075 } ) ;
0 commit comments