Verified Commit dad85cb8 authored by David Beniamine's avatar David Beniamine
Browse files

Several fix on dates

parent b21dfc73
......@@ -120,11 +120,11 @@ class Gitlab extends CommonObject
function post($url, $params){
global $conf;
$fullurl=$conf->global->GITLABWORKFLOW_GITLAB_INSTANCE_URL.$this::$API_ROOT.$url;
$fullurl.='?title='.urlencode($params['title']);
unset($params['title']);
$fullurl.='?';
foreach($params as $key => $val){
$fullurl.='&'.$key.'='.urlencode($val);
$fullurl.=$key.'='.urlencode($val).'&';
}
$fullurl=trim($fullurl, '&');
dol_syslog("gitlabwf post url ".$fullurl);
......@@ -184,24 +184,36 @@ class Gitlab extends CommonObject
* @param assigneeid int gitlab used id
* @param due date due date
* @param confidential boolean should the issue be confidential
* @param duration int duration in days
* @param milestone int id of the gitlab milestone, ignored if <0
* @return int gitlab issue id
*/
function createIssue($title, $text, $projectid, $assigneeid, $due,
$confidential, $milestone=-1){
$confidential, $duration, $milestone=-1){
dol_syslog("gitlabwf :: createIssue ".$title);
//TODO transform text
$newtext=$text;
// Transform list into checkable list
// newline or start then list marker *,+ - or 1., 2. etc.
$pattern='/(^|\n)(\s*)([\*\+-]|\d+\.)/';
// Keep spacing + marker + checkable mark [ ]
$sub='$1$2$3 [ ]';
$newtext= preg_replace($pattern, $sub,$text);
// Prepare API call
$url='projects/'.$projectid.'/issues';
$params=array(
'title' => $title,
'description' => $newtext,
'assignee_ids' => $assigneeid,
'milestone_id' => $milestone,
'due_date' => dol_print_date($due, "%Y-%m-%d"),
'confidential' => $confidential,
//'due_date' => dol_print_date($due, "%Y-%m-%d"),
'confidential' => $confidential?$confidential:0,
);
return $this->post($url, $params)->id;
$answer=$this->post($url, $params);
$params=array(
'duration' => $duration.'d',
);
$output = $this->post($url.'/'.$answer->iid.'/time_estimate', $params);
dol_syslog("gitlabwf :: seting estimate time, answer ".json_encode($output));
return $answer->iid;
}
/*
......@@ -238,13 +250,14 @@ class Gitlab extends CommonObject
);
dol_syslog("gitlabwf :: generateIssues ".json_encode($issues));
foreach($issues as $key => $issue){
dol_syslog("gitlabwf :: signel issue ".$key." : ".json_encode($issue));
dol_syslog("gitlabwf :: single issue ".$key." : ".json_encode($issue));
if($issue['type'] == 'issue'){
// Retrieve milestone id
$milestone=$issue['milestone']?$milestones[$issue['milestone']]:-1;
$id= $this->createIssue($issue['title'],$issue['contents'],
$issue['project'], $issue['assignee'],
$issue['start'],$issue['confidential'],
$issue['duration'],
$milestone);
}else{
$id= $this->createMilestone($issue['title'],$issue['contents'],
......
......@@ -106,7 +106,7 @@ foreach($object->lines as $line){
$sublevel+=1;
$duration=round($line->qty*$unitconv);
$enddate=dol_time_plus_duree($curdate, $duration, 'd');
$enddate=add_open_days($curdate, $duration);
if($line->fk_parent_line){
$milestones[$line->fk_parent_line]['duration']+=$duration;
......@@ -141,7 +141,7 @@ foreach($milestones as $id => $mile){
$curdate=$mile['start'];
$duration=round($mile['duration']);
$enddate=dol_time_plus_duree($mile['start'], $duration, 'd');
$enddate=add_open_days($mile['start'], $duration);
$splits=explode("\n",$mile['desc'],2);
$name=$splits[0];
......
......@@ -100,12 +100,14 @@ foreach($object->lines as $line){
$type='issue';
$milestone=$line->fk_parent_line;
$issues[$line->id]['milestone'] = $milestone;
$duration=round($line->qty*$unitconv);
$end=dol_time_plus_duree($curdate, $duration, 'd');
$duration=$line->qty*$unitconv;
$issues[$line->id]['duration'] = $duration;
$end=add_open_days($curdate, $duration);
$issues[$line->id]['end']=$end;
if($milestone){
$issues[$milestone]['end']=
dol_time_plus_duree($issues[$milestone]['end'], $duration, 'd');
dol_syslog("gitlabwf :: Handling issue ".$line->desc);
dol_syslog("gitlabwf :: setting mielstone ".$milestone."end from ".dol_print_date($issues[$milestone]['end'], "%Y-%m-%d")."to ".dol_print_date($end, "%Y-%m-%d"));
$issues[$milestone]['end']=$end;
}
$curdate=$end;
}
......
......@@ -60,3 +60,13 @@ function gitlabworkflowAdminPrepareHead()
function isMilestone($line){
return $line->product_type == 9;
}
function add_open_days($timestamp_start, $numdays){
$rounded = round($numdays);
$timestamp_end = dol_time_plus_duree($timestamp_start, $rounded, "d");
do{
$missing = $rounded - num_open_day($timestamp_start, $timestamp_end);
$timestamp_end = dol_time_plus_duree($timestamp_end, $missing, "d") ;
}while($missing >0);
return $timestamp_end;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment