{"version":3,"sources":["../src/index.ts","../src/create-plugin.ts","../src/DangerClient.ts"],"sourcesContent":["export { createPlugin } from \"./create-plugin.ts\";\nexport { default as DangerClient } from \"./DangerClient.ts\";\nexport * from \"./types.ts\";\n","import { type PluginRuntime } from \"./types.ts\";\n\n/**\n * Helper to create a typed Danger plugin for .\n * Ensures consistent structure and typing.\n *\n * @example\n * // a plugin that warn if the merge request is too big.\n * type Options = { size: number };\n * export const mergeRequestSizePlugins = createPlugin<Options>((client, options) => {\n *   const threshold = options?.size || 200;\n *   const changedFiles = [...client.git.modified_files, ...client.git.created_files];\n *   if (changedFiles.length > threshold) {\n *     client.warn(\n *       \"The merge request is too big. Break it into multiple merge requests\",\n *     );\n *   }\n * });\n */\nexport const createPlugin = <Options extends Record<PropertyKey, unknown>>(\n  pluginFn: PluginRuntime<Options>,\n): PluginRuntime<Options> => {\n  return pluginFn;\n};\n","import {\n  type DangerDSLType,\n  type DangerResults,\n  type GitDSL,\n  type GitHubDSL,\n  type GitLabDSL,\n} from \"danger\";\nimport { type PluginRuntime } from \"./types.ts\";\n\ndeclare let results: DangerResults;\ndeclare const warn: (msg: string, file?: string, line?: number) => void;\ndeclare const fail: (msg: string, file?: string, line?: number) => void;\ndeclare const message: (msg: string, file?: string, line?: number) => void;\ndeclare const markdown: (msg: string, file?: string, line?: number) => void;\n\n/**\n * A class that provides a modular way to enhance GitLab merge request validation\n * by integrating plugins and automating common tasks such as marking drafts,\n * notifying assignees/reviewers, and managing merge request titles.\n *\n * @see https://danger.systems/js/\n */\nclass DangerClient {\n  /**\n   * GitLab-specific information for the current merge request.\n   */\n  public readonly gitlab: GitLabDSL;\n\n  /**\n   * GitHub-specific information for the current pull request.\n   */\n  public readonly github: GitHubDSL;\n\n  /**\n   * Git-related information such as modified, created, and deleted files.\n   */\n  public readonly git: GitDSL;\n\n  /**\n   * The shared Danger results object used to store warnings, fails, messages, etc.\n   */\n  public readonly results: DangerResults;\n\n  /**\n   * Function to mark a failure in the Danger output.\n   */\n  public readonly fail: typeof fail;\n\n  /**\n   * Function to mark a warning in the Danger output.\n   */\n  public readonly warn: typeof warn;\n\n  /**\n   * Function to add markdown output to the Danger report.\n   */\n  public readonly markdown: typeof markdown;\n\n  /**\n   * Function to add a general message to the Danger report.\n   */\n  public readonly message: typeof message;\n\n  /**\n   * List of files that have been modified in the current merge request.\n   */\n  public readonly modifiedFiles: string[];\n\n  /**\n   * List of files that have been newly created in the current merge request.\n   */\n  public readonly createdFiles: string[];\n\n  /**\n   * List of files that have been deleted in the current merge request.\n   */\n  public readonly deletedFiles: string[];\n\n  /**\n   * Arbitrary data storage shared across plugins for this Danger run.\n   */\n  public readonly data: Record<PropertyKey, unknown>;\n\n  /**\n   * List of registered plugins and their associated options.\n   * Used to apply custom validation logic.\n   */\n  private readonly _plugins: Array<[PluginRuntime, object]> = [];\n\n  /**\n   * Creates an instance of DangerClient.\n   * Initializes context properties and file changes for processing.\n   *\n   * @param danger - The Danger context for the current merge request.\n   */\n  constructor(danger: DangerDSLType) {\n    this.gitlab = danger.gitlab;\n    this.git = danger.git;\n    this.github = danger.github;\n    this.fail = fail;\n    this.warn = warn;\n    this.results = results;\n    this.markdown = markdown;\n    this.message = message;\n\n    this.modifiedFiles = this.git.modified_files;\n    this.createdFiles = this.git.created_files;\n    this.deletedFiles = this.git.deleted_files;\n\n    this.data = {};\n  }\n\n  /**\n   * Returns the list of registered plugins for the current Danger run.\n   * Primarily exposed for testing or debugging purposes. Direct manipulation of this list is discouraged;\n   * plugins should be added using the {@link use} method to ensure consistent behavior.\n   *\n   * @returns The internal list of registered plugins and their options.\n   */\n  public get plugins() {\n    return this._plugins;\n  }\n\n  /**\n   * Registers a plugin to the DangerClient.\n   * Enables modular validation logic for merge requests.\n   *\n   * @param plugin - The plugin function to register.\n   * @param options - Optional configuration for the plugin.\n   * @returns The current DangerClient instance for chaining.\n   */\n  public use<Option extends object = object>(\n    plugin: PluginRuntime<Option>,\n    options?: Option,\n  ): this {\n    this._plugins.push([plugin as PluginRuntime, options ?? {}]);\n\n    return this;\n  }\n\n  /**\n   * Analyzes the merge request using registered plugins.\n   * Executes all plugins with their associated options.\n   *\n   * @returns The updated Danger results after plugin analysis.\n   */\n  public async analyze(): Promise<DangerResults> {\n    for (const [method, pluginOption] of this._plugins) {\n      await method(this, pluginOption);\n    }\n\n    return this.results;\n  }\n}\n\nexport default DangerClient;\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,iBAAAC,IAAA,eAAAC,EAAAJ,GCmBO,IAAMK,EACXC,GAEOA,ECAT,IAAMC,EAAN,KAAmB,CAyEjB,YAAYC,EAAuB,CARnC,KAAiB,SAA2C,CAAC,EAS3D,KAAK,OAASA,EAAO,OACrB,KAAK,IAAMA,EAAO,IAClB,KAAK,OAASA,EAAO,OACrB,KAAK,KAAO,KACZ,KAAK,KAAO,KACZ,KAAK,QAAU,QACf,KAAK,SAAW,SAChB,KAAK,QAAU,QAEf,KAAK,cAAgB,KAAK,IAAI,eAC9B,KAAK,aAAe,KAAK,IAAI,cAC7B,KAAK,aAAe,KAAK,IAAI,cAE7B,KAAK,KAAO,CAAC,CACf,CASA,IAAW,SAAU,CACnB,OAAO,KAAK,QACd,CAUO,IACLC,EACAC,EACM,CACN,YAAK,SAAS,KAAK,CAACD,EAAyBC,GAAA,KAAAA,EAAW,CAAC,CAAC,CAAC,EAEpD,IACT,CAQA,MAAa,SAAkC,CAC7C,OAAW,CAACC,EAAQC,CAAY,IAAK,KAAK,SACxC,MAAMD,EAAO,KAAMC,CAAY,EAGjC,OAAO,KAAK,OACd,CACF,EAEOC,EAAQN","names":["index_exports","__export","DangerClient_default","createPlugin","__toCommonJS","createPlugin","pluginFn","DangerClient","danger","plugin","options","method","pluginOption","DangerClient_default"]}