📜 ⬆️ ⬇️

Redmine - control over production update

In the process of developing web applications, we often have 2 questions:
1. What tasks have already been solved, but have not yet been uploaded to the combat server. In other words - what exactly will be uploaded to the combat server when git is updated
2. How to quickly see the logs - what and when it was uploaded to the server.

Git is used as a version control system (through it the production server is updated). As a task manager of Redmine.
A few words about redmine. For him, we took the cheapest VPS from the hetzner, and our repository was tied to the redmine. It turned out very convenient when comments to the commit in the form of " re #111 " are automatically attached to task №111. Accordingly, " fix #111 " will close this task. Well, buns in the form of specifying references to revisions, viewing diffs between commits and so on. The main “master” repository is in our githaba, but I'm going to give it up.

So, the above questions can be answered quite easily using the commands in the console:
one.
 git config --global alias.incoming '!git remote update -p; git log ..@{u}' 

And then, with the git incoming command, we see exactly what is poured to us. More here (link given in q & a )
2
 git reflog 

and
 git log HEAD@{1}..HEAD@{0} 

')
However, this method is not always convenient. In particular, it is not immediately clear what exactly the task # 111, which will flash in the logs.
How I implemented it to make it more convenient.
In the Redmine for tasks a new logical field Production was added, yes - uploaded to the server, no - not uploaded.
Also, the user Robot was added to Redmine.
When uploading to the server, a post-merge hook is used. This hook looks at exactly which commits were uploaded, runs over each of them, if there is a task number, marks this task in the Production=true mine, and at the end draws up a final list of changes, creates a task for the Robot (with the status "solved") and there records the changes.
Hook is written in php, because An excellent ActiveResource.php library was found for working with Ruby on Rails REST APIs.
I will give the whole code, since there are some:
 #!/usr/bin/php <?php require_once ('ActiveResource.php'); //      .         User  . class Issue extends ActiveResource { var $site = 'http://redmine.site.com/'; var $request_format = 'xml'; var $extra_params = '?key=API_KEY'; } $issue = new Issue(); // ,    . exec('git log --pretty="%h=!=%an=!=%s" HEAD@{1}..HEAD@{0}',$logs); //  ,     $s = ""; //    foreach($logs as $log){ //  ,  ,    list($hash, $name, $comment) = explode("=!=", $log); //      echo $hash . " " . $name . " " . $comment . "\n"; // # -     . $s .= "# "; //         if(preg_match("/#\d+/", $comment, $ids)){ $id = substr($ids[0],1); $issue->find($id); //    Production  true.     ID.     2. $issue->set("custom_fields", array("@type"=>"array", array("custom_field"=>array("@id"=>"2", "value"=>1)))); $issue->save(); //     " "   .         alt   .      - . $s .= "+ " . $ids[0] . "+ "; } // ..       -    .      . $s .= "commit:" . $hash; //     $s .= " *".$name."*"; //     ,    ,    2       $comment = trim(preg_replace("/^.*#\d+/", "", $comment)); if(!empty($comment)){ $s .= ", _" . $comment . "_"; } $s .= "\n"; } //   . $newIssue = new Issue(array ('subject' => ' Production', 'project_id' => '2')); //  $newIssue->set("description", $s); //  $newIssue->set("status_id",3); //    $newIssue->set("assigned_to_id",12); $newIssue->save(); 

The task with the final description looks like this:


What we have in the end.
Through the filters of redmine, you can see which tasks are solved but not filled. You can also see in a convenient way when and what was updated on the server - convenient for reports.

By the way, add yourself to .bashrc
 alias gl='git log --pretty="%Cgreen%h %Cblue%an%Creset %s %Cred%ar"' 

and use gl instead of git log .

Source: https://habr.com/ru/post/147877/


All Articles