Use a piece of string or a flexible measuring tape and measure the actual length of the bars. Use that value to order the correct length cable.
I recently installed a GRX Di2 groupset up on my Diverge. I used this method with a bar end junction port. Worked perfectly for me. Drilling the bars took some time but I would suggest this for a cleaner install.