janhoy commented on code in PR #1483:
URL: https://github.com/apache/solr/pull/1483#discussion_r1145557521


##########
dev-tools/scripts/addDepsToChanges.py:
##########
@@ -0,0 +1,139 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""
+Script to add solrbot changes lines to CHANGES.txt
+"""
+import os
+import sys
+
+sys.path.append(os.path.dirname(__file__))
+from scriptutil import *
+
+import argparse
+import re
+
+line_re = re.compile(r"(.*?) \(#(\d+)\)$")
+
+
+def get_prev_release_tag(ver):
+    """
+    Based on a given version, compute the git tag for the "previous" version 
to calculate changes since.
+    For a major version, we want all solrbot commits since last release, i.e. 
X-1.Y.Z
+    For a minor version, we want all solrbot commits since X.Y-1.0
+    For a patch version, we want all solrbot commits since X.Y.Z-1
+    """
+    releases_arr = run('git tag |grep "releases/solr" | cut -c 
15-').strip().split("\n")
+    releases = list(map(lambda x: Version.parse(x), releases_arr))
+    if ver.is_major_release():
+        last = releases.pop()
+        return "releases/solr/%s" % last.dot
+    if ver.is_minor_release():
+        return "releases/solr/%s.%s.0" % (ver.major, ver.minor - 1)
+    if ver.is_bugfix_release():
+        return "releases/solr/%s.%s.%s" % (ver.major, ver.minor, ver.bugfix - 
1)
+    return None
+
+
+def read_config():
+    parser = argparse.ArgumentParser(description='Adds dependency changes 
section to CHANGES.txt.')
+    parser.add_argument('--version', type=Version.parse, help='Solr version to 
add changes to', required=True)
+    parser.add_argument('--user', default='solrbot', help='Git user to get 
changes for. Defaults to solrbot')
+    newconf = parser.parse_args()
+    return newconf
+
+
+def gitlog_to_changes(line, user="solrbot"):
+    """
+    Converts a git log formatted line ending in (#<pr-num) into a CHANGES 
style line
+    """
+    match = line_re.search(line)
+
+    if match:
+        text = match.group(1)
+        pr_num = match.group(2)
+        return "* PR#%s: %s (%s)\n" % (pr_num, text, user)
+    else:
+        return None
+
+
+def update_changes(filename, version, changes_lines):
+    """
+    Edits CHANGES.txt in-place
+    """
+    buffer = []
+    found_ver = False
+    found_header = False
+    appended = False
+    with open(filename) as f:
+        version_re = re.compile(r' %s ===' % (version))
+        header_re = re.compile(r'^Dependency Upgrades')
+        header_line_re = re.compile(r'^----')
+        for line in f:
+            if not found_ver:
+                buffer.append(line)
+                if version_re.search(line):
+                    found_ver = True
+                continue
+            if not found_header:
+                buffer.append(line)
+                if header_re.search(line):
+                    found_header = True
+                continue
+            if not appended:
+                if header_line_re.search(line):
+                    buffer.append(line)
+                    appended = True
+                    for change_line in changes_lines:
+                        buffer.append(change_line)
+                        buffer.append("\n")
+                    continue
+            buffer.append(line)

Review Comment:
   This logic fins a `Dependency Upgrades` heading in the correct version 
section of CHANGES, and adds all entries directly below that heading. 
   
   TODO:
   * It won't delete the `(No changes)` line that would be there by default
   * If the release version does not contain a `Dependency Upgrades` heading, 
the script fails. This is not likely to happen, as the `addVersion.py` script 
now adds this header by default.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to