Getting collaboration change history

Started by rheward, July 03, 2023, 09:29:44 AM

Previous topic - Next topic

rheward

Is it possible to get the change history in jArchi? I'd like to be able to share it with colleagues who don't have Archi.

Phil Beauvoir

Hi, not sure I understand. You want to read a git history from jArchi? If so, that's not directly possible.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

rheward

Yes. Like you can see in Archi's Collaboration Change History tab. I'll think of another way of grabbing it. Thanks.

JoonasT

I'm also interested on this. So if you find some solution to get the history please do share.

My use case is to show the version history in in html export. So I would add the information with jArchi in Azure pipeline. Maybe in as a properties value. So when was the view last updated, by who and maybe even the commit message. This information is available in GIT and in partly in Archi GUI but I have not found a way to get this with jArchi.

Phil Beauvoir

#4
This isn't really a jArchi issue. What you need to do is to use the command line "git log" to print the log of the git repository to a text file and read that in.

Here's an example:

git log master --pretty=format:"%ct %s" --reverse --encoding=UTF-8 > file.txt
Once you have that, I think you could read it in to jArchi and manipulate it.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

jsimoncello

Hi,
I do have a similar use case albeit more "visual" : I'd like to have an history of all updated views in a model since a given date.
I tried with Git but haven't achieved anything, so my workaround is a jArchi script that
- computes checksum for each view in my model, store this checksum in an "history" file
- at the next script execution, it reads this file and computes checksum for each view. When a checksum has changed that means that there is something (even if it is minor change of a visual element, that's the drawback of this approach) has been changed on the view
- appends the result (before/after view) to an html file that is published along site our model HTML report. It is a single HTML file (so not scalable for now).
- of course, writes the new checksums to the "history" file.

I am planning to run this script weekly.

JoonasT

Quote from: Phil Beauvoir on July 03, 2023, 12:38:34 PMThis isn't really a jArchi issue. What you need to do is to use the command line "git log" to print the log of the git repository to a text file and read that in.

Here's an example:

git log master --pretty=format:"%ct %s" --reverse --encoding=UTF-8 > file.txt
Once you have that, I think you could read it in to jArchi and manipulate it.

Thanks for the tip. After playing around with this command I found that I can also get the history for each view.

For example:
git log --pretty=format:"%ch - %cn - %s" -- model/d
iagrams/id-5279de3a4b754ef489d5901286fddff6/ArchimateDiagramModel_id-20c15f06c8ee4531943bccdb9a83afba.xml > file7.txt

Reading this in and matching this in jArchi is still something to do. The filename id is same as element id's. So possible.

rheward

Quote from: Phil Beauvoir on July 03, 2023, 12:38:34 PMgit log master --pretty=format:"%ct %s" --reverse --encoding=UTF-8 > file.txt

Thanks for this; it's all I needed. I can now put the output into a SharePoint area so my colleagues can see what has been happening in the model (I removed the reverse and used the "%%ch - %%cn - %%s" arguments in a batch command. jArchi wasn't really the answer for this.  :)

Phil Beauvoir

If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

JoonasT

I got the git log command working and finding correct elements. But how can I read the results to jArchi?
I tried $.child_process.exec() and it works for running external bash script to execute git log, but I could not get the stdout working.

Jean-Baptiste Sarrodie

Hi,

Quote from: JoonasT on July 05, 2023, 08:25:40 AMBut how can I read the results to jArchi?
I tried $.child_process.exec() and it works for running external bash script to execute git log, but I could not get the stdout working.

$.child_process.exec() doesn't provide access to stdout nor stderr (I've just found this because I was following this discussion and did some experiment). I might improve it in the future, but maybe you can too as it's implemented in JS:

jArchi.child_process = {
    exec: function() {
        // Split arguments into an array of args
        var args = Array.prototype.slice.call(arguments);
       
        var platform = Java.type("org.eclipse.core.runtime.Platform").getOS();
        if(platform == "macosx") {
            args = ["open", "-a"].concat(args[0]); // for some reason, Mac will only accept one argument
        }
   
        var runtime = Java.type("java.lang.Runtime").getRuntime();
        runtime.exec(args);
    }
}

In the meantime you can also use git options to save output to a file and then read the file content (e.g. using the readFully function I did share on the forum).

Regards,

JB
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Phil Beauvoir

If the log is written to file, why do you need stdout?
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

JoonasT

Thanks for all the help. With $.child_process.exec() and readFully I now succeeded on adding latest commit message related to a view to top of its documentation. This is run in Azure pipeline to html exports.

Now the implementation is that first I write git logs to file and read. I would be much simpler to just read commands output straight away. So thats why stdout would be nice. Also I had to separate the reading and writing to separate loops because the reading sometimes failed if i tried to read it too quickly after the writing.

Here is the code that I used. I'm not a master coder so someone can probably make this much cleaner.

bash script gitlog.sh
#!/usr/bin/bash
cd /tmp/model/model/diagrams/
find . -name *$1* -type f | xargs git log -1 --pretty=format:"%cd - %cn - %s" --encoding=UTF-8 -- > /tmp/model/committiedot/$1.txt

jArchi script that is run during Azure pipeline and html export.
/*
 * Add git commit message to top of each view's documentation
 */
$("view").each(function(object) {
        console.log(object.id);
        gitCommitmessage(object.id);
    });
$("view").each(function(object) {
        console.log(object.id);
        commitviesti = gitCommitmessageRead(object.id);
        console.log(commitviesti);
        object.documentation = "View updated: " + commitviesti + object.documentation;
    });
function gitCommitmessage(elementtiid) {
$.child_process.exec("/app/gitlog.sh", elementtiid);
}
function gitCommitmessageRead(elementtiid) {
response = readFully("/tmp/model/committiedot/"+elementtiid+".txt");
return response;
}
function readFully(url) {
    var result = "";
    var imports = new JavaImporter(java.net, java.lang, java.io);

    with (imports) {

        var urlObj = null;

        try {
            urlObj = new URL(url);
        } catch (e) {
            // If the URL cannot be built, assume it is a file path.
            urlObj = new URL(new File(url).toURI().toURL());
        }

        var reader = new BufferedReader(new InputStreamReader(urlObj.openStream()));

        var line = reader.readLine();
        while (line != null) {
            result += line + "\n";
            line = reader.readLine();
        }

        reader.close();
    }