Repository: internetarchive/openlibrary

Issue:
Add Title field to Merge Requests
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->

Creating a merge request today currently infers title based on the works in the url, but after a work is merged, the merge request often fetches a /type/redirect as the first work in the url (since they are sorted by asc int ID).

This issue proposes moving title of work into Merge Request as official field.

### Describe the problem that you'd like solved
<!-- A clear and concise description of what you want to happen. -->

### Proposal & Constraints
<!-- What is the proposed solution / implementation? Is there a precedent of this approach succeeding elsewhere? -->

<!-- Which suggestions or requirements should be considered for how feature needs to appear or be implemented? -->

May not be an issue but there could be a case where a merge is happening because the 0th work doesn't have the most descriptive metadata and yet this is what we'd be using as MR title. Is this a problem? For now, assuming not, perhaps we could make title editable if librarians say it's needed.

### Additional context
<!-- Add any other context or screenshots about the feature request here. -->

### Stakeholders
<!-- @ tag stakeholders of this bug -->





Discussion:

Resolving patch:
diff --git a/openlibrary/core/edits.py b/openlibrary/core/edits.py
--- a/openlibrary/core/edits.py
+++ b/openlibrary/core/edits.py
@@ -1,6 +1,7 @@
 import datetime
 import json
 from typing import Optional
+import web
 
 from infogami.utils.view import public
 
@@ -134,7 +135,6 @@ def submit_work_merge_request(
 
         Precondition: OLIDs in work_ids list must be sanitized and normalized.
         """
-
         url = f"/works/merge?records={','.join(work_ids)}"
         if not cls.exists(url):
             return cls.submit_request(
@@ -143,8 +143,19 @@ def submit_work_merge_request(
                 comment=comment,
                 reviewer=reviewer,
                 status=status,
+                title=cls.get_work_merge_title(work_ids),
             )
 
+    @staticmethod
+    def get_work_merge_title(olids):
+        title = None
+        for olid in olids:
+            book = web.ctx.site.get(f'/works/{olid}')
+            if book and book.title:
+                title = book.title
+                break
+        return title
+
     @classmethod
     def submit_author_merge_request(cls, author_ids, submitter, comment=None):
         if not comment:
@@ -170,6 +181,7 @@ def submit_request(
         reviewer: str = None,
         status: int = STATUS['PENDING'],
         comment: str = None,
+        title: str = None,
     ):
         """
         Inserts a new record into the table.
@@ -188,6 +200,7 @@ def submit_request(
             url=url,
             status=status,
             comments=json_comment,
+            title=title,
         )
 
     @classmethod
diff --git a/openlibrary/plugins/upstream/edits.py b/openlibrary/plugins/upstream/edits.py
--- a/openlibrary/plugins/upstream/edits.py
+++ b/openlibrary/plugins/upstream/edits.py
@@ -105,42 +105,16 @@ def GET(self):
             reviewer=i.reviewer,
             order='created',
         ).list()
-        enriched_requests = self.enrich(merge_requests)
+
         total_found = CommunityEditsQueue.get_counts_by_mode(
             mode=i.mode, submitter=i.submitter, reviewer=i.reviewer
         )
         return render_template(
             'merge_queue/merge_queue',
             total_found,
-            merge_requests=enriched_requests,
+            merge_requests=merge_requests,
         )
 
-    def enrich(self, merge_requests):
-        results = []
-        for r in merge_requests:
-            comments = r['comments']
-            obj = {
-                'id': r['id'],
-                'submitter': r['submitter'],
-                'reviewer': r['reviewer'],
-                'url': r['url'],
-                'status': r['status'],
-                'comments': (comments and comments.get('comments')) or [],
-                'created': r['created'],
-                'updated': r['updated'],
-            }
-            olids = self.extract_olids(r['url'])
-            obj['title'] = ''
-            for olid in olids:
-                book = web.ctx.site.get(f'/works/{olid}')
-                if book:
-                    if not obj['title']:
-                        obj['title'] = book.title
-                        break
-
-            results.append(obj)
-        return results
-
     def extract_olids(self, url):
         query_string = url.split('?')[1]
         split_params = query_string.split('&')


Test patch: