From 7accdd9845fe7ce9d0aa5a9d16faaa489c1294eb Mon Sep 17 00:00:00 2001
From: pukkandan <pukkandan.ytdlp@gmail.com>
Date: Sat, 4 Mar 2023 16:39:23 +0530
Subject: [PATCH] [devscripts] `make_changelog`: Stop at `Release ...` commit

Closes #6415
---
 .github/workflows/release-nightly.yml |  2 +-
 devscripts/changelog_override.json    |  4 +--
 devscripts/make_changelog.py          | 36 ++++++---------------------
 3 files changed, 10 insertions(+), 32 deletions(-)

diff --git a/.github/workflows/release-nightly.yml b/.github/workflows/release-nightly.yml
index b0634fa5a8..d4f01ab649 100644
--- a/.github/workflows/release-nightly.yml
+++ b/.github/workflows/release-nightly.yml
@@ -4,7 +4,7 @@ on:
     branches:
       - master
     paths:
-      - "**.py"
+      - "yt_dlp/**.py"
       - "!yt_dlp/version.py"
 concurrency:
   group: release-nightly
diff --git a/devscripts/changelog_override.json b/devscripts/changelog_override.json
index a5872d4b4c..e5c9d1aa21 100644
--- a/devscripts/changelog_override.json
+++ b/devscripts/changelog_override.json
@@ -1,12 +1,12 @@
 [
     {
         "action": "add",
-        "when": "2023.02.17",
+        "when": "776d1c3f0c9b00399896dd2e40e78e9a43218109",
         "short": "[priority] **A new release type has been added!**\n    * [`nightly`](https://github.com/yt-dlp/yt-dlp/releases/tag/nightly) builds will be made after each push, containing the latest fixes (but also possibly bugs).\n    * When using `--update`/`-U`, a release binary will only update to its current channel (either `stable` or `nightly`).\n    * The `--update-to` option has been added allowing the user more control over program upgrades (or downgrades).\n    * `--update-to` can change the release channel (`stable`, `nightly`) and also upgrade or downgrade to specific tags.\n    * **Usage**: `--update-to CHANNEL`, `--update-to TAG`, `--update-to CHANNEL@TAG`"
     },
     {
         "action": "add",
-        "when": "2023.02.17",
+        "when": "776d1c3f0c9b00399896dd2e40e78e9a43218109",
         "short": "[priority] **YouTube throttling fixes!**"
     }
 ]
diff --git a/devscripts/make_changelog.py b/devscripts/make_changelog.py
index 07aa3285b7..722315333a 100644
--- a/devscripts/make_changelog.py
+++ b/devscripts/make_changelog.py
@@ -248,30 +248,6 @@ def __init__(self, start, end, default_author=None) -> None:
         self._commits, self._fixes = self._get_commits_and_fixes(default_author)
         self._commits_added = []
 
-    @classmethod
-    def from_single(cls, commitish='HEAD', default_author=None):
-        start_commitish = cls.get_prev_tag(commitish)
-        end_commitish = cls.get_next_tag(commitish)
-        if start_commitish == end_commitish:
-            start_commitish = cls.get_prev_tag(f'{commitish}~')
-        logger.info(f'Determined range from {commitish!r}: {start_commitish}..{end_commitish}')
-        return cls(start_commitish, end_commitish, default_author)
-
-    @classmethod
-    def get_prev_tag(cls, commitish):
-        command = [cls.COMMAND, 'describe', '--tags', '--abbrev=0', '--exclude=*[^0-9.]*', commitish]
-        return subprocess.check_output(command, text=True).strip()
-
-    @classmethod
-    def get_next_tag(cls, commitish):
-        result = subprocess.run(
-            [cls.COMMAND, 'describe', '--contains', '--abbrev=0', commitish],
-            stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True)
-        if result.returncode:
-            return 'HEAD'
-
-        return result.stdout.partition('~')[0].strip()
-
     def __iter__(self):
         return iter(itertools.chain(self._commits.values(), self._commits_added))
 
@@ -293,13 +269,12 @@ def _is_ancestor(self, commitish):
     def _get_commits_and_fixes(self, default_author):
         result = subprocess.check_output([
             self.COMMAND, 'log', f'--format=%H%n%s%n%b%n{self.COMMIT_SEPARATOR}',
-            f'{self._start}..{self._end}'], text=True)
+            f'{self._start}..{self._end}' if self._start else self._end], text=True)
 
         commits = {}
         fixes = defaultdict(list)
         lines = iter(result.splitlines(False))
-        for line in lines:
-            commit_hash = line
+        for i, commit_hash in enumerate(lines):
             short = next(lines)
             skip = short.startswith('Release ') or short == '[version] update'
 
@@ -310,9 +285,12 @@ def _get_commits_and_fixes(self, default_author):
                     authors = sorted(map(str.strip, line[match.end():].split(',')), key=str.casefold)
 
             commit = Commit(commit_hash, short, authors)
-            if skip:
+            if skip and (self._start or not i):
                 logger.debug(f'Skipped commit: {commit}')
                 continue
+            elif skip:
+                logger.debug(f'Reached Release commit, breaking: {commit}')
+                break
 
             fix_match = self.FIXES_RE.search(commit.short)
             if fix_match:
@@ -471,7 +449,7 @@ def get_new_contributors(contributors_path, commits):
         datefmt='%Y-%m-%d %H-%M-%S', format='{asctime} | {levelname:<8} | {message}',
         level=logging.WARNING - 10 * args.verbosity, style='{', stream=sys.stderr)
 
-    commits = CommitRange.from_single(args.commitish, args.default_author)
+    commits = CommitRange(None, args.commitish, args.default_author)
 
     if not args.no_override:
         if args.override_path.exists():