Merger.php
[Pman.MTrack] / Merger.php
1 <?php
2 /**
3  * concept is to merge commits from a live or working tree
4  * into the 'release tree'
5  *
6  *
7  * step 1 = render the log of differences..
8  *
9  *
10  * First run issues:
11  *  -- our doc commit changes loads of files.. and makes the layout pointless.
12  *  -- ?? grouping by day??? // expand/collapse.. 
13  * 
14  *
15  */
16
17 require_once 'Pman.php';
18
19 class Pman_MTrack_Merger extends Pman {
20     
21     
22     // function getAuth() - from log..
23     function getAuth()
24     {
25         parent::getAuth();
26         $au = $this->getAuthUser();
27         if (!$au || $au->company()->comptype != 'OWNER') {
28             $this->jautherr();
29         }
30         $this->authUser = $au;
31         return true;
32     }
33     
34     
35     function get($pi)
36     {
37         
38         $this->pi = 'default/roojs1'; // fixme..
39         
40         $this->repo = DB_DataObject::factory('mtrack_repos');
41         $this->filename = $this->repo->loadFromPath($this->pi);
42         
43         if (!$this->repo->id) {
44             $this->err("invalid repo");
45         };
46           
47         //if (!$this->projectPerm($this->repo->project_id, 'MTrack.Repos', 'S')) {
48         //    $this->err("no perm for this repo ");
49         //}
50         if (isset($_REQUEST['_tree'])) {
51             $this->tree();
52         }
53         
54         if (isset($_REQUEST['_changedFiles'])) {
55             $this->changedFiles($_REQUEST['_changedFiles']);
56         }
57         $this->jerr("invalid url");
58         exit;
59         
60     }
61     function tree()
62     {
63         
64         $live = 'master';
65         $release = 'github';
66          
67         $this->repo->debug = 1;
68         $ar = $this->repo->history("/", null, "rev",  "$release..$live");
69         
70         // the point of this is to extract all the revisions, and group them.
71         
72         
73         
74         //echo '<PRE>';print_R($ar);
75         
76         // need to get a 2 dimensional array of
77         // files along top, and commints down.
78         $cfiles = array();
79         $rows = array();
80         foreach($ar as $commit) {
81             
82             $files = $commit->files;
83             $day = date("Y-m-d", strtotime($commit->ctime));
84             if (!isset($days[$day])) { 
85                 $days[$day] = array(
86                     'text' => $day,
87                     'rev' => $day,
88                     'children' => array()
89                 );
90             }
91             $time= date("H:i:s", strtotime($commit->ctime));
92             if (!isset($days[$day]['children'][$time])) { 
93                 $days[$day]['children'][$time] = array(
94                     'text' => $time,
95                     'rev' => $day . ' ' . $time,
96                     'commits' =>array(),
97                 );
98             }
99             $days[$day]['children'][$time]['children'][] = array(
100                 'text'=> $commit->changelog,
101                 'rev' => $commit->rev,
102                 'leaf' => true
103             );
104         }
105         $out = array();
106         
107         foreach($days as $d=>$do) {
108             $dcn = $do['children'];
109             $do['children'] = array();
110             foreach($dcn as $t=>$to) {
111                 $to['rev']  = $to['children'][0]['rev'];
112                 $do['children'][] = $to;
113             }
114             $do['rev'] = $do['children'][0]['rev'];
115             $out[] = $do;
116         }
117         
118         $this->jdata($out);
119         
120          
121         
122     }
123     
124     
125
126
127
128     function changedFiles()
129     {
130         // list the files that have changed..
131         // in theory you could click a number of them and only merge those changes..
132         // need to do a git diff.. and just get a list of files..
133     }
134 }