Skip to content

Commit

Permalink
feat(datasource/azure-pipelines-tasks): Add in support for matching o…
Browse files Browse the repository at this point in the history
…n id and contribution combinations (#34398)

Co-authored-by: Richard Dalziel <[email protected]>
  • Loading branch information
RDalziel and rdalzielhymans authored Mar 4, 2025
1 parent b62b8d7 commit e9d86a2
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"count": 3,
"count": 4,
"value": [
{
"visibility": [
Expand Down Expand Up @@ -570,6 +570,93 @@
"Default": "5.248.2",
"Node20_229_2": "5.248.3"
}
},
{
"runsOn": [
"Agent",
"DeploymentGroup"
],
"id": "5d437bf5-f193-4449-b531-c4c69eebaa48",
"name": "gitreleasemanager/open",
"version": {
"major": 3,
"minor": 1,
"patch": 11,
"isTest": false
},
"contentsUploaded": true,
"iconUrl": "https://dev.azure.com/test_organisation/_apis/distributedtask/tasks/5d437bf5-f193-4449-b531-c4c69eebaa48/3.1.11/icon",
"minimumAgentVersion": "3.224.0",
"friendlyName": "Open GitReleaseManager Task",
"description": "Tool for creating and exporting releases for software applications hosted on GitHub",
"category": "Build",
"helpMarkDown": "See the [documentation](https://gittools.github.io/GitReleaseManager/docs/) for help",
"contributionIdentifier": "gittools.gittools.open-gitreleasemanager-task",
"contributionVersion": "3.1.11.25012214",
"definitionType": "task",
"author": "GitTools Contributors",
"demands": [],
"groups": [],
"inputs": [
{
"aliases": [],
"name": "owner",
"label": "The owner of the repository",
"defaultValue": "",
"required": true,
"type": "string",
"helpMarkDown": "The owner of the repository"
},
{
"aliases": [],
"name": "repository",
"label": "The name of the repository",
"defaultValue": "",
"required": true,
"type": "string",
"helpMarkDown": "The name of the repository"
},
{
"aliases": [],
"name": "token",
"label": "The access token to access GitHub with",
"defaultValue": "",
"required": true,
"type": "string",
"helpMarkDown": "The access token to access GitHub with"
},
{
"aliases": [],
"name": "milestone",
"label": "The milestone to use",
"defaultValue": "",
"required": true,
"type": "string",
"helpMarkDown": "The milestone to use"
},
{
"aliases": [],
"name": "targetDirectory",
"label": "The directory on which GitReleaseManager should be executed. Defaults to current directory",
"defaultValue": "",
"type": "string",
"helpMarkDown": "The directory on which GitReleaseManager should be executed. Defaults to current directory"
}
],
"satisfies": [],
"sourceDefinitions": [],
"dataSourceBindings": [],
"instanceNameFormat": "gitreleasemanager/open",
"preJobExecution": {},
"execution": {
"Node20_1": {
"target": "main.mjs",
"argumentFormat": "",
"workingDirectory": "."
}
},
"postJobExecution": {},
"_buildConfigMapping": {}
}
]
}
}
69 changes: 69 additions & 0 deletions lib/modules/datasource/azure-pipelines-tasks/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,74 @@ describe('modules/datasource/azure-pipelines-tasks/index', () => {
).toEqual({ releases: [{ version: '5.248.3' }] });
});

it('identifies task based on task id', async () => {
GlobalConfig.set({
platform: 'azure',
endpoint: 'https://my.custom.domain',
});
hostRules.add({
hostType: AzurePipelinesTasksDatasource.id,
matchHost: 'my.custom.domain',
token: '123test',
});
httpMock
.scope('https://my.custom.domain')
.get('/_apis/distributedtask/tasks/')
.reply(200, Fixtures.get('tasks.json'));
expect(
await getPkgReleases({
datasource: AzurePipelinesTasksDatasource.id,
packageName: '5d437bf5-f193-4449-b531-c4c69eebaa48',
}),
).toEqual({ releases: [{ version: '3.1.11' }] });
});

it('identifies task based on contributionIdentifier and id', async () => {
GlobalConfig.set({
platform: 'azure',
endpoint: 'https://my.custom.domain',
});
hostRules.add({
hostType: AzurePipelinesTasksDatasource.id,
matchHost: 'my.custom.domain',
token: '123test',
});
httpMock
.scope('https://my.custom.domain')
.get('/_apis/distributedtask/tasks/')
.reply(200, Fixtures.get('tasks.json'));
expect(
await getPkgReleases({
datasource: AzurePipelinesTasksDatasource.id,
packageName:
'gittools.gittools.open-gitreleasemanager-task.5d437bf5-f193-4449-b531-c4c69eebaa48',
}),
).toEqual({ releases: [{ version: '3.1.11' }] });
});

it('identifies task based on contributionIdentifier and name', async () => {
GlobalConfig.set({
platform: 'azure',
endpoint: 'https://my.custom.domain',
});
hostRules.add({
hostType: AzurePipelinesTasksDatasource.id,
matchHost: 'my.custom.domain',
token: '123test',
});
httpMock
.scope('https://my.custom.domain')
.get('/_apis/distributedtask/tasks/')
.reply(200, Fixtures.get('tasks.json'));
expect(
await getPkgReleases({
datasource: AzurePipelinesTasksDatasource.id,
packageName:
'gittools.gittools.open-gitreleasemanager-task.gitreleasemanager/open',
}),
).toEqual({ releases: [{ version: '3.1.11' }] });
});

it('returns organization task with multiple versions', async () => {
GlobalConfig.set({
platform: 'azure',
Expand Down Expand Up @@ -151,6 +219,7 @@ describe('modules/datasource/azure-pipelines-tasks/index', () => {
: null;

return AzurePipelinesTask.parse({
id: '',
name: '',
deprecated: false,
version,
Expand Down
12 changes: 11 additions & 1 deletion lib/modules/datasource/azure-pipelines-tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ export class AzurePipelinesTasksDatasource extends Datasource {
const result: ReleaseResult = { releases: [] };

results.value
.filter((task) => task.name === packageName)
.filter((task) => {
const matchers = [
task.id === packageName,
task.name === packageName,
task.contributionIdentifier !== null &&
`${task.contributionIdentifier}.${task.id}` === packageName,
task.contributionIdentifier !== null &&
`${task.contributionIdentifier}.${task.name}` === packageName,
];
return matchers.some((match) => match);
})
.sort(AzurePipelinesTasksDatasource.compareSemanticVersions('version'))
.forEach((task) => {
result.releases.push({
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/datasource/azure-pipelines-tasks/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ export const AzurePipelinesTaskVersion = z.object({
});

export const AzurePipelinesTask = z.object({
id: z.string(),
name: z.string(),
deprecated: z.boolean().optional(),
version: AzurePipelinesTaskVersion.nullable(),
contributionIdentifier: z.string().optional(),
});

export const AzurePipelinesJSON = z.object({
Expand Down

0 comments on commit e9d86a2

Please sign in to comment.