File tree 2 files changed +47
-11
lines changed
2 files changed +47
-11
lines changed Original file line number Diff line number Diff line change @@ -5,10 +5,8 @@ const url = require('./util/github-url')
5
5
module . exports = class Configuration {
6
6
static load ( context , path , source ) {
7
7
const options = context . repo ( url ( path , source ) )
8
- return context . github . repos . getContent ( options ) . then ( res => {
9
- const config = new Configuration ( context , options )
10
- return config . parse ( Buffer . from ( res . data . content , 'base64' ) . toString ( ) )
11
- } )
8
+ const config = new Configuration ( context , options )
9
+ return config . contents ( ) . then ( buffer => config . parse ( buffer ) )
12
10
}
13
11
14
12
constructor ( context , source ) {
@@ -37,15 +35,15 @@ module.exports = class Configuration {
37
35
return load . then ( config => config . execute ( this . context ) )
38
36
}
39
37
} )
40
-
41
- return undefined
42
38
}
43
39
44
40
contents ( path ) {
45
- const options = this . context . repo ( url ( path , this . source ) )
46
- return this . context . github . repos . getContent ( options ) . then ( res => {
47
- return Buffer . from ( res . data . content , 'base64' ) . toString ( )
48
- } )
41
+ const options = path
42
+ ? this . context . repo ( url ( path , this . source ) )
43
+ : this . source
44
+ return this . context . github . repos . getContent ( options ) . then ( res =>
45
+ Buffer . from ( res . data . content , 'base64' ) . toString ( )
46
+ )
49
47
}
50
48
51
49
parse ( content ) {
Original file line number Diff line number Diff line change @@ -114,13 +114,28 @@ describe('app', () => {
114
114
if ( params . path === 'script-b.js' ) {
115
115
return ''
116
116
}
117
- return 'include("other/repo:script-a.js");'
117
+ return `
118
+ include("other/repo:script-a.js");
119
+ include("another/repo:script-a.js");
120
+ include("script-b.js");
121
+ `
118
122
} )
123
+ expect ( github . repos . getContent ) . toHaveBeenCalledTimes ( 1 + 3 + 2 )
119
124
expect ( github . repos . getContent ) . toHaveBeenCalledWith ( {
120
125
owner : 'other' ,
121
126
repo : 'repo' ,
122
127
path : 'script-b.js'
123
128
} )
129
+ expect ( github . repos . getContent ) . toHaveBeenCalledWith ( {
130
+ owner : 'another' ,
131
+ repo : 'repo' ,
132
+ path : 'script-b.js'
133
+ } )
134
+ expect ( github . repos . getContent ) . toHaveBeenCalledWith ( {
135
+ owner : 'bkeepers-inc' ,
136
+ repo : 'test' ,
137
+ path : 'script-b.js'
138
+ } )
124
139
} )
125
140
} )
126
141
@@ -156,5 +171,28 @@ describe('app', () => {
156
171
path : 'content.md'
157
172
} )
158
173
} )
174
+
175
+ it ( 'gets contents relative to included repository' , async ( ) => {
176
+ await configure ( params => {
177
+ if ( params . path === 'content.md' || params . path === 'label.md' ) {
178
+ return ''
179
+ }
180
+ return `
181
+ on("issues")
182
+ .comment(contents("other/repo:content.md"))
183
+ .comment(contents("label.md"));
184
+ `
185
+ } )
186
+ expect ( github . repos . getContent ) . toHaveBeenCalledWith ( {
187
+ owner : 'other' ,
188
+ repo : 'repo' ,
189
+ path : 'content.md'
190
+ } )
191
+ expect ( github . repos . getContent ) . toHaveBeenCalledWith ( {
192
+ owner : 'bkeepers-inc' ,
193
+ repo : 'test' ,
194
+ path : 'label.md'
195
+ } )
196
+ } )
159
197
} )
160
198
} )
You can’t perform that action at this time.
0 commit comments