From e85a7d8064987aed1cad4a6b8c52c362615677b1 Mon Sep 17 00:00:00 2001
From: RahulGautamSingh <rahultesnik@gmail.com>
Date: Mon, 3 Jun 2024 19:42:33 +0545
Subject: [PATCH] feat(config/package-rules): add `sourceUrl` and
 `sourceDirectory` options (#29387)

---
 docs/usage/configuration-options.md | 38 ++++++++++++++++++++++++++++-
 lib/config/options/index.ts         | 17 +++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/docs/usage/configuration-options.md b/docs/usage/configuration-options.md
index 7f14d471c4..848c3600a4 100644
--- a/docs/usage/configuration-options.md
+++ b/docs/usage/configuration-options.md
@@ -2394,7 +2394,7 @@ The matching process for a package rule:
 - If no match/exclude matchers are defined, everything matches.
 - If an aspect is both `match`ed and `exclude`d, the exclusion wins.
 - Multiple values within a single matcher will be evaluated independently (they're OR-ed together).
-- Combining multiple matchers will restrict the resulting matches (they're AND-ed together):  
+- Combining multiple matchers will restrict the resulting matches (they're AND-ed together):
   `matchCurrentVersion`, `matchCurrentValue`, `matchNewValue`, `matchConfidence`, `matchCurrentAge`,
   `matchManagers`, `matchDatasources`, `matchCategories`, `matchDepTypes`, `matchUpdateTypes`,
   `matchRepositories`/`excludeRepositories`, `matchBaseBranches`, `matchFileNames`
@@ -3232,6 +3232,42 @@ For example to replace the npm package `jade` with version `2.0.0` of the packag
 }
 ```
 
+### sourceUrl
+
+Use this field to set the source URL for a package, including overriding an existing one.
+Source URLs are necessary to link to the source of the package and in order to look up changelogs.
+
+```json title="Setting the source URL for the dummy package"
+{
+  "packageRules": [
+    {
+      "matchPackageNames": ["dummy"],
+      "sourceUrl": "https://github.com/org/dummy"
+    }
+  ]
+}
+```
+
+### sourceDirectory
+
+Use this field to set the directory in which the package is present at the source of the package.
+
+```json title="Setting the source directory for the kube-prometheus package from bitnami charts repo"
+{
+  "packageRules": [
+    {
+      "matchPackageNames": ["dummy"],
+      "sourceUrl": "https://github.com/bitnami/charts",
+      "sourceDirectory": "bitnami/kube-prometheus"
+    }
+  ]
+}
+```
+
+<!-- prettier-ignore -->
+!!! note
+    `sourceDirectory` should be only be configured along with `sourceUrl`.
+
 ### prPriority
 
 Sometimes Renovate needs to rate limit its creation of PRs, e.g. hourly or concurrent PR limits.
diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts
index 9485956f2e..98479dae8c 100644
--- a/lib/config/options/index.ts
+++ b/lib/config/options/index.ts
@@ -1562,6 +1562,23 @@ const options: RenovateOptions[] = [
     cli: false,
     env: false,
   },
+  {
+    name: 'sourceUrl',
+    description: 'The source URL of the package.',
+    type: 'string',
+    parents: ['packageRules'],
+    cli: false,
+    env: false,
+  },
+  {
+    name: 'sourceDirectory',
+    description:
+      'The source directory in which the package is present at its source.',
+    type: 'string',
+    parents: ['packageRules'],
+    cli: false,
+    env: false,
+  },
   {
     name: 'matchSourceUrlPrefixes',
     description:
-- 
GitLab