Skip to content

Commit

Permalink
fix(datasource/galaxy): support multiple results (#29664)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Poxhofer <[email protected]>
  • Loading branch information
rarkins and secustor authored Sep 23, 2024
1 parent 300886a commit 8722bfd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/modules/datasource/galaxy/__fixtures__/datadog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"count":2,"next":null,"previous":null,"results":[{"id":7358,"upstream_id":null,"created":"2023-05-08T20:39:41.712620Z","modified":"2024-01-25T10:46:42.565078Z","imported":"2024-01-25T10:46:42.041295","github_user":"DataDog","username":"DataDog","github_repo":"ansible-datadog","github_branch":"main","commit":"286c8be5461a9f86063a40842a7f7ac85f1929d8","commit_message":"Prepare 4.22 release (#542)\n\n","name":"datadog","description":"Install Datadog agent and configure checks","summary_fields":{"dependencies":[],"namespace":{"id":1584,"name":"DataDog","avatar_url":"https://galaxy.ansible.com/api/pulp/api/v3/content/ansible/namespaces/018c3469-6cc2-76e4-8a81-557c3a806d80/avatar/"},"provider_namespace":{"id":12957,"name":"datadog","pulp_href":"/api/pulp/api/v3/pulp_ansible/namespaces/12957/"},"repository":{"name":"ansible-datadog","original_name":"ansible-datadog"},"tags":["monitoring"],"versions":[{"id":"5c821e30-5e2f-4cb5-a0d5-27f806cdaf44","name":"4.22.0","release_date":"2024-01-25T11:04:58+01:00"},{"id":"0f8f5505-e728-47d0-b62e-b7a32d42398a","name":"4.21.0","release_date":"2023-12-04T11:26:40+01:00"},{"id":"7d12eff3-e8b4-4d86-b1a2-6058e5d08676","name":"4.20.1","release_date":"2023-07-20T10:18:51-04:00"},{"id":"75ff5620-e11c-4f1e-829d-aa01070941db","name":"4.20.0","release_date":"2023-07-18T05:31:39-04:00"},{"id":"a2d45207-0daf-4b66-8f7c-b4be0d55b3b6","name":"4.19.0","release_date":"2023-05-10T08:04:01-04:00"},{"id":"14865b3d-7fef-4947-957b-690b1cc0c3c8","name":"4.18.0","release_date":"2023-01-12T09:53:08-05:00"},{"id":"4af6234d-12aa-4147-8dca-bfe38bbef6d4","name":"4.17.0","release_date":"2023-01-04T05:28:29-05:00"},{"id":"ded20247-ee4c-453c-a5e1-fd8ad963c575","name":"4.16.0","release_date":"2022-07-11T05:15:43-04:00"},{"id":"5f85cd03-042d-4d60-bfe9-62be7f553cb0","name":"4.15.0","release_date":"2022-04-20T02:47:29-04:00"},{"id":"6dc4da17-4a38-4fe2-a54c-f94c618edd2c","name":"4.14.0","release_date":"2022-02-08T09:34:55-05:00"},{"id":"f2b0dd5f-011b-4048-9069-937c71bfb85b","name":"4.13.0","release_date":"2022-01-21T06:57:13-05:00"}]},"download_count":10167551},{"id":33484,"upstream_id":null,"created":"2023-09-28T20:59:12.704850Z","modified":"2024-06-06T11:44:30.243787Z","imported":"2024-06-06T11:44:29.836996","github_user":"datadog","username":"datadog","github_repo":"ansible-datadog","github_branch":"main","commit":"2ebab5cbe09f30ee0257d2ea1b1625b716185702","commit_message":"Prepare 4.23.0 release, fix links on older changelog entries (#570)\n\n","name":"datadog","description":"Install Datadog agent and configure checks","summary_fields":{"dependencies":[],"namespace":{"id":8735,"name":"datadog","avatar_url":"https://galaxy.ansible.com/api/pulp/api/v3/content/ansible/namespaces/018c3469-6cc2-76e4-8a81-557c3a806d80/avatar/"},"provider_namespace":{"id":12957,"name":"datadog","pulp_href":"/api/pulp/api/v3/pulp_ansible/namespaces/12957/"},"repository":{"name":"ansible-datadog","original_name":"ansible-datadog"},"tags":["monitoring"],"versions":[{"id":"7481ba51-3c04-4208-b915-234902962c4d","name":"4.23.0","release_date":"2024-06-04T12:21:21-04:00"},{"id":"5661d630-1750-461e-acfd-93903d353e3a","name":"4.22.0","release_date":"2024-01-25T11:04:58+01:00"},{"id":"767a4ee9-b10f-4f22-b90d-7fb603f82450","name":"4.21.0","release_date":"2023-12-04T11:26:40+01:00"},{"id":"dd61aad5-e5fa-4dbe-b366-d5c2c9d9ee49","name":"4.20.1","release_date":"2023-07-20T10:18:51-04:00"},{"id":"76fdf4c1-0a82-425f-9417-e96fc309adbc","name":"4.20.0","release_date":"2023-07-18T05:31:39-04:00"},{"id":"e1eb55e6-a125-4bee-a56f-baf7faf94346","name":"4.19.0","release_date":"2023-05-10T08:04:01-04:00"},{"id":"742b5b35-b9b5-428d-ae60-35d5996e3af0","name":"4.18.0","release_date":"2023-01-12T09:53:08-05:00"},{"id":"6480bd7a-01c1-45d2-a4ec-7602310a2ac6","name":"4.17.0","release_date":"2023-01-04T05:28:29-05:00"},{"id":"a6689996-6e44-47b9-a61b-ffe62ae0f7c1","name":"4.16.0","release_date":"2022-07-11T05:15:43-04:00"},{"id":"e38041e7-2575-4a08-a3e4-fb4e95f013e4","name":"4.15.0","release_date":"2022-04-20T02:47:29-04:00"},{"id":"941282bd-4745-41eb-98a1-5356200ea4ad","name":"4.14.0","release_date":"2022-02-08T09:34:55-05:00"}]},"download_count":11933065}]}
25 changes: 25 additions & 0 deletions lib/modules/datasource/galaxy/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,31 @@ describe('modules/datasource/galaxy/index', () => {
expect(res).toBeDefined();
});

it('handles multiple results when one user matches exactly', async () => {
httpMock
.scope(baseUrl)
.get('/api/v1/roles/?owner__username=datadog&name=datadog')
.reply(200, Fixtures.get('datadog.json'));
const res = await getPkgReleases({
datasource: GalaxyDatasource.id,
packageName: 'datadog.datadog',
});
expect(res).not.toBeNull();
expect(res?.releases).toHaveLength(11);
});

it('rejects multiple results when no user matches exactly', async () => {
httpMock
.scope(baseUrl)
.get('/api/v1/roles/?owner__username=nope&name=nope')
.reply(200, Fixtures.get('datadog.json'));
const res = await getPkgReleases({
datasource: GalaxyDatasource.id,
packageName: 'nope.nope',
});
expect(res).toBeNull();
});

it('return null if searching random username and project name', async () => {
httpMock
.scope(baseUrl)
Expand Down
14 changes: 9 additions & 5 deletions lib/modules/datasource/galaxy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,17 @@ export class GalaxyDatasource extends Datasource {
this.handleGenericErrors(err);
}

// istanbul ignore if
if (body.results.length > 1) {
logger.warn(
{ dependency: packageName },
`Received multiple results from ${galaxyAPIUrl}`,
body.results = body.results.filter(
(result) => result.github_user === userName,
);
return null;
if (!body.results.length) {
logger.warn(
{ dependency: packageName, userName },
`Multiple results from galaxy for ${packageName}, none match`,
);
return null;
}
}
if (body.results.length === 0) {
logger.info(
Expand Down

0 comments on commit 8722bfd

Please sign in to comment.