From d81fdc509c2c55966edd32a684ec937cbfd99c82 Mon Sep 17 00:00:00 2001 From: Robert Alonso <17463757+rgalonso@users.noreply.github.com> Date: Fri, 8 Nov 2024 15:15:42 +0000 Subject: [PATCH] fix: insert issue URLs at correct line number Fix bug where if there were multiple issue URLs to insert into a file, after the first insertion all further insertions would copy a "random" line (based on *original* line numbering) and insert that copy rather than the issue URL. Now processes files in order by file name and then in reverse order by line number, thereby ensuring that any line insertions/ deletions at bottom of file don't affect line numbering above them. Closes github.com/alstr/todo-to-issue-action#225 --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index c0307a1..567d8a1 100644 --- a/main.py +++ b/main.py @@ -79,7 +79,7 @@ if __name__ == "__main__": insert_issue_urls = os.getenv('INPUT_INSERT_ISSUE_URLS', 'false') == 'true' # Cycle through the Issue objects and create or close a corresponding GitHub issue for each. - for j, raw_issue in enumerate(issues_to_process): + for j, raw_issue in enumerate(sorted(reversed(sorted(issues_to_process, key = operator.attrgetter('start_line'))), key = operator.attrgetter('file_name'))): print(f"Processing issue {j + 1} of {len(issues_to_process)}: '{raw_issue.title}' @ {raw_issue.file_name}:{raw_issue.start_line}") if raw_issue.status == LineStatus.ADDED: status_code, new_issue_number = client.create_issue(raw_issue)