Automating Cyrillic to Latin File Name Conversion for JIRA Attachments

Sophie
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 13, 2024

 

Hello everyone, I’m working on a JIRA project and need to rename attachment files in bulk. Specifically, I need to convert file names from Cyrillic to Latin characters. Here’s what I’m trying to achieve: Transliterate File Names: Convert file names from Cyrillic to Latin characters using a predefined mapping. Rename Files: Update the file names in JIRA to reflect the transliterated names.

1 answer

0 votes
Jonathan Muse {Appfire}
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 14, 2024

I don't think there is a good way to rename the attachment while it is still attached to the ticket. There are too many things that would need to be changed like the file on the server, the attachment data in the database and then other information that links it to the ticket.

The only way I cold see this being done is to:

  1. Download the file
  2. Rename it on the local drive
  3. Delete the old file from the ticket
  4. Upload and attach the newly renamed attachment.

Several of my go-to tools were not able to do this but I do know that a product called Power Scripts can do it. Here is an example script that shows how it can be done. This is just a starting point, I would add logging to it however it works:

struct renameData {
string oldFileName;
string newFileName;
}

renameData [] data = readFromCSVFile("renameData.csv", true);
string [] dataMapped;

for(renameData d in data) {
dataMapped[d.oldFileName] = d.newFileName;
}

string [] issueKeys = selectIssues("project = TEST");

for(string key in issueKeys) {
integer [] attach = getAttachmentIds(key);

for(integer a in attach) {
string oldFileName = attachmentFilename(key, a);
boolean downloaded = downloadAttachmentById(key, a, "C:/downloads/" + oldFileName);

if(downloaded) {
deleteAttachment(key, a);

string newFileName = dataMapped[oldFileName];
renameFile("C:/downloads/" + oldFileName, "C:/downloads/" + newFileName);
uploadAttachment(key, "C:/downloads/" + newFileName)
}
}
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events