"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AzurePipelinesTasksDatasource = void 0;
const tslib_1 = require("tslib");
const data_files_generated_1 = tslib_1.__importDefault(require("../../../data-files.generated"));
const decorator_1 = require("../../../util/cache/package/decorator");
const loose_1 = require("../../versioning/loose");
const datasource_1 = require("../datasource");
const MARKETPLACE_TASKS_URL = 'https://raw.githubusercontent.com/renovatebot/azure-devops-marketplace/main/azure-pipelines-marketplace-tasks.json';
class AzurePipelinesTasksDatasource extends datasource_1.Datasource {
    static id = 'azure-pipelines-tasks';
    builtInTasks;
    constructor() {
        super(AzurePipelinesTasksDatasource.id);
        this.builtInTasks = JSON.parse(data_files_generated_1.default.get('data/azure-pipelines-tasks.json'));
    }
    customRegistrySupport = false;
    defaultVersioning = loose_1.id;
    async getReleases({ packageName, }) {
        const versions = this.builtInTasks[packageName.toLowerCase()] ??
            (await this.getMarketplaceTasks())[packageName.toLowerCase()];
        if (versions) {
            const releases = versions.map((version) => ({ version }));
            return Promise.resolve({ releases });
        }
        return Promise.resolve(null);
    }
    async getMarketplaceTasks() {
        const { body } = await this.http.getJson(MARKETPLACE_TASKS_URL);
        return body;
    }
}
tslib_1.__decorate([
    (0, decorator_1.cache)({
        namespace: `datasource-${AzurePipelinesTasksDatasource.id}`,
        key: 'azure-pipelines-marketplace-tasks',
        ttlMinutes: 24 * 60,
    })
], AzurePipelinesTasksDatasource.prototype, "getMarketplaceTasks", null);
exports.AzurePipelinesTasksDatasource = AzurePipelinesTasksDatasource;
//# sourceMappingURL=index.js.map