Git Integration

Git integration with SIL scripts is possible using standard git commands via the file system since SIL files are stored in standard folder on the file system.

Installation

Git is required to be installed on the Jira server in order to manage scripts in an external git repository as described in this article. The git folder should be set up using git commands on the server itself. It is also possible to configure git using the system() routine from a SIL script to run commands.

SIL scripts are typically store in JIRA_HOME/programs

Connections to remote repositories are set in git in the config file.

Using Git in Jira

Git commands can be run using the system() routine in SIL. A gadget script can be created to execute commits or to pull down versions to deploy changes.

Example gadget script to commit changes and push to a remote repository:


Main Script
persistent string gitPath;

string baseCommand = "git --git-dir=\"" + gitPath + "\\.git\" --work-tree=\"" + gitPath + "\" ";

string [] folders = gadget_getMultiValues(argv, "Folders");
string [] files = gadget_getMultiValues(argv, "Files");
string commitMessage = arrayGetElement(argv, "Commit Message");

for(string f in folders) {
    string command = baseCommand + "add --all \"" + gitPath + "\\" + f + "\"";
    runnerLog("Running git command: " + command);
    runnerLog(system(command)); 
}

for(string f in files) {
    string command = baseCommand + "add \"" + gitPath + "\\" + f + "\"";
    runnerLog("Running git command: " + command);
    runnerLog(system(command)); 
}

string command = baseCommand + "commit -a -m \"" + commitMessage + "\"";
runnerLog("Running git command: " + command);
runnerLog(system(command));
command = (baseCommand + "push origin \nusername: jmuse \n ");
runnerLog("Running git command: " + command);
runnerLog(system(command));
Gadget Params Script
persistent string gitPath = "C:\\Program Files\\Atlassian\\Application Data\\JIRA_versions\\silprograms";

function getFiles(string dir) {
    
    string [] dirs = findDirectories(dir, ".*");
    string [] silFiles;
    string [] files;
    
    for(string dir in dirs) {
        if(contains(dir, ".git") == false) {
            silFiles += findFiles(dir, ".*");
        }
    }
    
    silFiles = arraySort(silFiles, false);
    
    for(string b in silFiles) {
        string temp = replace(b, dir, "");
        temp = replace(temp, "/", "");
        temp = substring(temp, 1, length(temp));
        files += temp;
    }
    
    return arraySort(files, false);
}

function getFolders(string dir) {
    
    string [] folders = findDirectories(dir, ".*");
    string [] subFolders;
    string [] folderNames;
    
    for(string f in folders) {
        if(contains(f, ".git") == false) {
            folderNames += substring(replace(f, dir, ""), 1, length(dir));
            string [] subfold = findDirectories(f, ".*");
            for(string sf in subfold) {
                folderNames += substring(replace(sf, dir, ""), 1, length(dir));
            }
            
        }
    }
    
    folderNames += folderNames;
    return arraySort(arrayToSet(folderNames), false);
}

gadget_createMultiSelectList("Folders", getFolders(gitPath), "", false, "");
gadget_createMultiSelectList("Files", getFiles(gitPath), "", false, "");
gadget_createTextArea("Commit Message", "", 10, true, "");

Notes

  • Scripts stored in the database can not be controlled using git
  • Branches should be created on the repository and simple checkout commands can be run from SIL to use the branch in Jira