Skip to content

Commit 06b2bf7

Browse files
authored
set index-url from url (#1522)
1 parent e685ad9 commit 06b2bf7

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

__tests__/updater.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,36 @@ describe('Updater', () => {
244244
})
245245
})
246246

247+
describe('when given python credentials with a URL and not an index-url', () => {
248+
const jobDetails = {...mockJobDetails}
249+
250+
new Updater(
251+
'MOCK_UPDATER_IMAGE_NAME',
252+
'MOCK_PROXY_IMAGE_NAME',
253+
mockApiClient,
254+
jobDetails,
255+
[
256+
{
257+
type: 'python_index',
258+
url: 'https://example.com/some/path',
259+
username: 'user',
260+
token: 'token'
261+
}
262+
],
263+
workingDirectory
264+
)
265+
266+
it('generates credentials metadata with the index from the URL', () => {
267+
expect(jobDetails['credentials-metadata']).toEqual([
268+
{
269+
'index-url': 'https://example.com/some/path',
270+
type: 'python_index',
271+
url: 'https://example.com/some/path'
272+
}
273+
])
274+
})
275+
})
276+
247277
describe('when given composer credentials with a URL and not a registry', () => {
248278
const jobDetails = {...mockJobDetails}
249279

dist/main/index.js

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/updater.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export class Updater {
8080
if (credential['index-url'] !== undefined) {
8181
obj['index-url'] = credential['index-url']
8282
}
83+
this.setIndexUrlFromUrl(obj, credential)
8384
if (credential['env-key'] !== undefined) {
8485
obj['env-key'] = credential['env-key']
8586
}
@@ -125,6 +126,23 @@ export class Updater {
125126
}
126127
}
127128

129+
private setIndexUrlFromUrl(obj: Credential, credential: Credential): void {
130+
if (credential.type !== 'python_index') {
131+
return
132+
}
133+
if (credential['index-url']) {
134+
return
135+
}
136+
if (credential.url) {
137+
try {
138+
obj['index-url'] = credential.url
139+
} catch {
140+
// If the URL is invalid, we skip setting the index-url
141+
// as it will fall back to the default index URL for pip.
142+
}
143+
}
144+
}
145+
128146
private async runUpdate(proxy: Proxy): Promise<void> {
129147
const name = `dependabot-job-${this.apiClient.params.jobId}`
130148
const container = await this.createContainer(proxy, name, {

0 commit comments

Comments
 (0)