Skip to content

Instantly share code, notes, and snippets.

@romualdrichard
Last active February 16, 2024 10:41
Show Gist options
  • Save romualdrichard/6ba8e4aac90f55dd6306dcaaf5d101c3 to your computer and use it in GitHub Desktop.
Save romualdrichard/6ba8e4aac90f55dd6306dcaaf5d101c3 to your computer and use it in GitHub Desktop.
#jArchi Script to read .gitconfig to have username and put it in property of the current view, and also add the update date in property of the view
//Script to put date of the day in the property "Date de mise à jour"
// and also the user name of the git in property Auteur
// Lit le fichier .gitconfig de l'utilisateur pour retrouver le nom
var System = Java.type('java.lang.System');
var currentDate = currentDate || new Date();
const Files = Java.type('java.nio.file.Files');
const Paths = Java.type('java.nio.file.Paths');
const StandardCharsets = Java.type('java.nio.charset.StandardCharsets');
const BufferedReader = Java.type('java.io.BufferedReader');
const InputStreamReader = Java.type('java.io.InputStreamReader');
const FileInputStream = Java.type('java.io.FileInputStream');
let userName = null;
// read .gitprofile
//const cheminGitconfig = Paths.get(process.env.HOME, '.gitconfig');
const cheminGitconfig = System.getProperty("user.home") + "\\.gitconfig";
try {
// Ouverture du fichier .gitconfig
const stream = new FileInputStream(cheminGitconfig);
const reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
let ligne;
// Lecture du fichier ligne par ligne
while ((ligne = reader.readLine()) !== null) {
// Recherche de la ligne contenant le nom de l'utilisateur
if (ligne.trim().startsWith("name")) {
// Extraction du nom de l'utilisateur
const match = /name\s*=\s*(.*)/.exec(ligne);
if (match && match[1]) {
userName = match[1].trim();
break; // Sortir de la boucle dès que le nom est trouvé
}
}
}
// Fermeture du flux
reader.close();
stream.close();
} catch (e) {
console.log("Erreur lors de la lecture du fichier .gitconfig :", e);
}
$(selection).each(function(concept) {
concept.prop("Date de mise à jour", ("0" + currentDate.getDate()).slice(-2) + "/" + ("0" + (currentDate.getMonth() + 1)).slice(-2) + "/" + currentDate.getFullYear());
concept.prop("Auteur", userName);
console.log("Date changée pour " + concept.name + " " + ("0" + currentDate.getDate()).slice(-2) + "/" + ("0" + (currentDate.getMonth() + 1)).slice(-2) + "/" + currentDate.getFullYear() + " pour " + userName);
});
model.save(); // save the model, you can set a short key to CTRL+S
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment