Skip to content

Commit

Permalink
Merge 1270f48 into fe8ce17
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Feb 8, 2021
2 parents fe8ce17 + 1270f48 commit 6618e10
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/CosyComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1235,13 +1235,13 @@ protected function handleIndividualUpdates($data, $lockdata, $cdata, $one_pr_per
} catch (ValidationFailedException $e) {
// @todo: Do some better checking. Could be several things, this.
$this->log('Had a problem with creating the pull request: ' . $e->getMessage(), 'error');
if (isset($branch_name) && isset($pr_params) && !empty($prs_named[$branch_name]['title']) && $prs_named[$branch_name]['title'] != $pr_params['title']) {
if ($this->shouldUpdatePr($branch_name, $pr_params, $prs_named)) {
$this->log('Will try to update the PR.');
$this->getPrClient()->updatePullRequest($this->slug, $prs_named[$branch_name]['number'], $pr_params);
}
} catch (\Gitlab\Exception\RuntimeException $e) {
$this->log('Had a problem with creating the pull request: ' . $e->getMessage(), 'error');
if (isset($branch_name) && isset($pr_params) && !empty($prs_named[$branch_name]['title']) && $prs_named[$branch_name]['title'] != $pr_params['title']) {
if ($this->shouldUpdatePr($branch_name, $pr_params, $prs_named)) {
$this->log('Will try to update the PR based on settings.');
$this->getPrClient()->updatePullRequest($this->slug, $prs_named[$branch_name]['number'], $pr_params);
}
Expand Down Expand Up @@ -1276,6 +1276,28 @@ protected function handleIndividualUpdates($data, $lockdata, $cdata, $one_pr_per
}
}

/**
* Helper function.
*/
protected function shouldUpdatePr($branch_name, $pr_params, $prs_named)
{
if (!isset($branch_name)) {
return false;
}
if (!isset($pr_params)) {
return false;
}
if (!empty($prs_named[$branch_name]['title']) && $prs_named[$branch_name]['title'] != $pr_params['title']) {
return true;
}
if (!empty($prs_named[$branch_name]['body']) && !empty($pr_params['body'])) {
if (trim($prs_named[$branch_name]['body']) != trim($pr_params['body'])) {
return true;
}
}
return false;
}

/**
* Get the messages that are logged.
*
Expand Down
1 change: 1 addition & 0 deletions src/Providers/Gitlab.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function getPrsNamed(Slug $slug)
]);
$prs_named[$pr['source_branch']] = [
'title' => $pr['title'],
'body' => !empty($pr['description']) ? $pr['description'] : '',
'number' => $pr["iid"],
'base' => [
'sha' => !empty($commits[1]["id"]) ? $commits[1]["id"] : $pr['sha'],
Expand Down

0 comments on commit 6618e10

Please sign in to comment.